Skip to content

Commit

Permalink
Add *, +, and ? quantifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Nov 29, 2009
1 parent 8add5bf commit ccab549
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/ARE/Actions.pm
Expand Up @@ -40,14 +40,30 @@ method termish($/) {
}

method quantified_atom($/) {
make $<atom>.ast;
my $past := $<atom>.ast;
if $<quantifier> {
my $qast := $<quantifier>[0].ast;
$qast.unshift($past);
$past := $qast;
}
make $past;
}

method atom($/) {
my $past := PAST::Regex.new( ~$/, :pasttype<literal>, :node($/) );
make $past;
}

method quantifier:sym<*>($/) {
make PAST::Regex.new( :pasttype<quant>, :node($/) );
}
method quantifier:sym<+>($/) {
make PAST::Regex.new( :pasttype<quant>, :min(1), :node($/) );
}
method quantifier:sym<?>($/) {
make PAST::Regex.new( :pasttype<quant>, :min(0), :max(1), :node($/) );
}


sub buildsub($rpast, $block = PAST::Block.new() ) {
$rpast := PAST::Regex.new(
Expand Down
7 changes: 6 additions & 1 deletion src/ARE/Grammar.pm
Expand Up @@ -14,7 +14,7 @@ token termish {
}

token quantified_atom {
<atom>
<atom> <quantifier>?
}

token atom {
Expand All @@ -24,4 +24,9 @@ token atom {
]
}

proto token quantifier { <...> }
token quantifier:sym<*> { <sym> }
token quantifier:sym<+> { <sym> }
token quantifier:sym<?> { <sym> }


0 comments on commit ccab549

Please sign in to comment.