Commits

Anonymous committed dc84463

Add support for Python 2 octals (munging wouldn't be necessary in Python
3, because it also uses '0o' for octals).

Comments (0)

Files changed (2)

src/parser/actions.nqp

     make $( $/{$key} );
 }
 
-method integer($/) {
-    make PAST::Val.new( :value( ~$/ ), :returns('Integer'), :node($/) );
+method integer($/, $key) {
+    my $str;
+    if $key eq 'octal' {
+        PIR q<  $P0 = find_lex '$/'   >;
+        PIR q<  $S0 = $P0             >;
+        PIR q<  $S1 = substr $S0, 1 >;
+        PIR q<  $S2 = '0o' . $S1 >;
+        PIR q<  $P1 = new 'String'  >;
+        PIR q<  assign $P1, $S2       >;
+        PIR q<  store_lex '$str', $P1 >;
+
+        make PAST::Val.new( :value( ~$str ), :returns('Integer'), :node($/) );
+    }
+    else {
+        make PAST::Val.new( :value( ~$/ ), :returns('Integer'), :node($/) );
+    }
 }
 
 method floatnumber($/) {

src/parser/grammar.pg

 }
 
 token integer {
-    [
-    | '0' <[0..7]>+
-    | '0' <[xX]> [ \d | <[a..f]> | <[A..F]> ]+
-    | <[1..9]> \d* | '0'
-    ]
-    {*}
+    | [ '0' <[0..7]>+ ] {*}                              #= octal
+    | [ '0' <[xX]> [ \d | <[a..f]> | <[A..F]> ]+ ] {*}   #= hex
+    | [ <[1..9]> \d* | '0' ] {*}                         #= dec
 }
 
 token intpart { \d+ }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.