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+ }