File: sort-hash-keys.patch

package info (click to toggle)
libparse-yapp-perl 1.21-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 492 kB
  • sloc: perl: 2,751; makefile: 2
file content (187 lines) | stat: -rw-r--r-- 5,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Description: sorting hash keys to remove non-determinism from the generated
 parsers.
Bug: https://rt.cpan.org/Public/Bug/Display.html?id=122977
Bug-Debian: https://bugs.debian.org/903979
Forwarded: https://rt.cpan.org/Ticket/Display.html?id=122977#txn-1796659
Author: Andrius Merkys <andrius.merkys@gmail.com>
Last-Update: 2018-07-19

--- a/lib/Parse/Yapp/Driver.pm
+++ b/lib/Parse/Yapp/Driver.pm
@@ -159,7 +159,7 @@
 sub YYExpect {
     my($self)=shift;
 
-    keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
+    sort keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
 }
 
 sub YYLexer {
--- a/lib/Parse/Yapp/Grammar.pm
+++ b/lib/Parse/Yapp/Grammar.pm
@@ -340,7 +340,7 @@
     $reachable = _Reachable($rules,$nterm,$term,$ufrules,$ufnterm);
 
     $$grammar{TERM}{chr(0)}=undef;
-    for my $sym (keys %$term) {
+    for my $sym (sort keys %$term) {
             (   exists($$reachable{$sym})
              or exists($values->{PREC}{$sym}) )
         and do {
@@ -352,7 +352,7 @@
     }
 
     $$grammar{NTERM}{'$start'}=[];
-    for my $sym (keys %$nterm) {
+    for my $sym (sort keys %$nterm) {
             exists($$reachable{$sym})
         and do {
                 exists($values->{NULL}{$sym})
--- a/lib/Parse/Yapp/Lalr.pm
+++ b/lib/Parse/Yapp/Lalr.pm
@@ -132,7 +132,7 @@
         }
 
         #Prepare Actions
-        for (keys(%{$$states[$stateno]{ACTIONS}})) {
+        for (sort keys(%{$$states[$stateno]{ACTIONS}})) {
             my($term,$action)=($_,$$states[$stateno]{ACTIONS}{$_});
 
                 $term eq chr(0)
@@ -220,7 +220,7 @@
             exists($$states[$stateno]{GOTOS})
         and    do {
                 $text.= "\n";
-                for (keys(%{$$states[$stateno]{GOTOS}})) {
+                for (sort keys(%{$$states[$stateno]{GOTOS}})) {
                     $text.= "\t$_\tgo to state $$states[$stateno]{GOTOS}{$_}\n";
                 }
             };
@@ -336,7 +336,7 @@
 
                                     "$term => $action";
                                 
-                                } grep { $_ } keys(%{$$state{ACTIONS}}));
+                                } grep { $_ } sort keys(%{$$state{ACTIONS}}));
 
                         $text.="\n\t\t}";
                     };
@@ -359,7 +359,7 @@
 
                                     "'$nterm' => $stateno";
                                 
-                                } keys(%{$$state{GOTOS}}));
+                                } sort keys(%{$$state{GOTOS}}));
                         $text.="\n\t\t}";
                     };
 
@@ -412,7 +412,7 @@
 
             exists($$rel{$x})
         and do {
-            for $y (keys(%{$$rel{$x}})) {
+            for $y (sort keys(%{$$rel{$x}})) {
                     exists($N{$y})
                 or  &$Traverse($y,$d+1);
 
@@ -435,7 +435,7 @@
         };
     };
 
-    for (keys(%$rel)) {
+    for (sort keys(%$rel)) {
             exists($N{$_})
         or  &$Traverse($_,1);
     }
@@ -459,7 +459,7 @@
 	my($grammar)=@_;
     my($rel,$closures);
 
-    for my $symbol (keys(%{$$grammar{NTERM}})) {
+    for my $symbol (sort keys(%{$$grammar{NTERM}})) {
         $closures->{$symbol}=pack('b'.@{$$grammar{RULES}});
 
         for my $ruleno (@{$$grammar{NTERM}{$symbol}}) {
@@ -511,7 +511,7 @@
         push(@{$transitions{$$rhs[$pos]}},[ $ruleno, $pos+1 ]);
     }
 
-    for (keys(%transitions)) {
+    for (sort keys(%transitions)) {
         my($symbol,$core)=($_,$transitions{$_});
         my($corekey)=join(',',map  { join('.',@$_) }
                               sort {    $$a[0] <=> $$b[0]
@@ -573,7 +573,7 @@
 	my($grammar,$termlst,$terminx)=@_;
     my($rel,$first)=( {}, {} );
 
-    for my $symbol (keys(%{$$grammar{NTERM}})) {
+    for my $symbol (sort keys(%{$$grammar{NTERM}})) {
         $first->{$symbol}=pack('b'.@$termlst);
 
         RULE:
@@ -621,7 +621,7 @@
     }
 
     # Pass @$preds through a hash to ensure unicity
-    [ keys( %{ +{ map { ($_,1) } @$preds } } ) ];
+    [ sort keys( %{ +{ map { ($_,1) } @$preds } } ) ];
 }
 
 sub _FirstSfx {
@@ -694,7 +694,7 @@
     		exists($$state{GOTOS})
 		or	next;
 
-        for my $symbol (keys(%{$$state{GOTOS}})) {
+        for my $symbol (sort keys(%{$$state{GOTOS}})) {
             my($tostate)=$$states[$$state{GOTOS}{$symbol}];
             my($goto)="$stateno.$symbol";
 
@@ -731,11 +731,11 @@
 
 sub _ComputeLA {
 	my($grammar,$states)=@_;
-	my($termlst)= [ '',keys(%{$$grammar{TERM}}) ];
+	my($termlst)= [ '',sort keys(%{$$grammar{TERM}}) ];
 
     my($follows,$inconsistent) = _ComputeFollows($grammar,$states,$termlst);
 
-    for my $stateno ( keys(%$inconsistent ) ) {
+    for my $stateno ( sort keys(%$inconsistent ) ) {
         my($state)=$$states[$stateno];
         my($conflict);
 
@@ -794,12 +794,12 @@
         undef;
     };
 
-    for my $stateno (keys(%$inconsistent)) {
+    for my $stateno (sort keys(%$inconsistent)) {
         my($state)=$$states[$stateno];
         my($actions)=$$state{ACTIONS};
         my($nbsr,$nbrr);
 
-        for my $term ( keys(%$actions) ) {
+        for my $term ( sort keys(%$actions) ) {
             my($act)=$$actions{$term};
 
                 @$act > 1
@@ -899,7 +899,7 @@
         and $$actions{error}[0] > 0
         and ++$nodefault;
 
-        for my $term (keys(%$actions)) {
+        for my $term (sort keys(%$actions)) {
 
 			$$actions{$term}=$$actions{$term}[0];
 
@@ -917,7 +917,7 @@
         $default=( map { $$_[0] }
                    sort { $$b[1] <=> $$a[1] or $$b[0] <=> $$a[0] }
                    map { [ $_, scalar(@{$reduces{$_}}) ] }
-                   keys(%reduces))[0];
+                   sort(keys(%reduces)))[0];
 
         delete(@$actions{ @{$reduces{$default}} });
         $$state{ACTIONS}{''}=$default;