Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
More nqp value handling improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 19, 2009
1 parent 348a761 commit 66906e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
26 changes: 18 additions & 8 deletions src/NQP/Actions.pm
@@ -1,16 +1,26 @@
class NQP::Actions;

method TOP($/, $key?) {
make PAST::Val.new( :value($<quote_delimited>.ast) );
method TOP($/) {
make $<value>.ast;
}

method value($/) {
my $past := PAST::Val.new(
:value($<integer> ?? $<integer>.ast !! $<quote_delimited>.ast)
);
make $past;
}

method integer($/) {
make
$<hexint>
?? $<hexint>.ast
!! $<octint>
?? $<octint>.ast
!! string_to_int( $<digits>, $<base> eq 'b' ?? 2 !! 10 );
make $<decint>
?? string_to_int( $<decint>, 10)
!! ( $<hexint>
?? $<hexint>.ast
!! ( $<octint>
?? $<octint>.ast
!! string_to_int( $<binint>, 2)
)
);
}

method hexint($/) {
Expand Down
13 changes: 9 additions & 4 deletions src/NQP/Grammar.pm
Expand Up @@ -3,7 +3,12 @@ grammar NQP::Grammar;
token starter { \" }
token stopper { \" }

token TOP { <quote_delimited> }
token TOP { <value> }

token value {
| <integer>
| <quote_delimited>
}

token quote_delimited {
<starter> <quote_atom>* <stopper>
Expand All @@ -25,12 +30,12 @@ token octints { [<.ws><octint><.ws>] ** ',' }

token integer {
[
| 0 [ b $<digits>=[[<[01]>+] ** '_']
| 0 [ b $<binint>=[[<[01]>+] ** '_']
| o <octint>
| x <hexint>
| d $<digits>=[[\d+] ** '_']
| d $<decint>=[[\d+] ** '_']
]
| $<digits>=[\d+ [_\d+]*]
| $<decint>=[\d+ [_\d+]*]
]
}

Expand Down

0 comments on commit 66906e8

Please sign in to comment.