Skip to content

Commit

Permalink
Add enumerated character lists to ARE.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Dec 9, 2009
1 parent f634404 commit c43ea6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ARE/Actions.pm
Expand Up @@ -72,6 +72,21 @@ method metachar:sym<.>($/) {

method metachar:sym<back>($/) { make $<backslash>.ast; }

method metachar:sym<[>($/) {
my $str := '';
for $<charspec> {
if $_[1] {
my $a := pir::ord($_[0]);
my $b := pir::ord(~$_[1][0]);
while $a < $b { $str := $str ~ pir::chr($a); $a++; }
}
else { $str := $str ~ $_[0]; }
}
my $past := PAST::Regex.new( $str, :pasttype<enumcharlist>, :node($/) );
$past.negate( $<invert> gt '' );
make $past;
}

method backslash:sym<w>($/) {
make PAST::Regex.new( :pasttype<charclass>, :subtype(~$<sym>), :node($/));
}
Expand Down
6 changes: 6 additions & 0 deletions src/ARE/Grammar.pm
Expand Up @@ -32,6 +32,12 @@ token quantifier:sym<?> { <sym> }
proto token metachar { <...> }
token metachar:sym<.> { <sym> }
token metachar:sym<back> { \\ <backslash> }
token metachar:sym<[> {
'['
$<invert>=['^'?]
$<charspec>=( [ \\ (.) | (<-[\]\\]>) ] [ '-' (.) ]? )*
']'
}

proto token backslash { <...> }
token backslash:sym<w> { $<sym>=[<[dswDSW]>] }
Expand Down

0 comments on commit c43ea6e

Please sign in to comment.