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

Commit

Permalink
Add parsing of proto regex statements to P6Grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 18, 2009
1 parent 5699969 commit af458ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
42 changes: 31 additions & 11 deletions src/Regex/P6Grammar/Actions.pm
Expand Up @@ -38,16 +38,36 @@ method regex_stmt($/, $key?) {
@MODIFIERS.unshift(%h);
return 0;
}
my $rpast := $<nibbler>.ast;
my %capnames := Regex::P6Regex::Actions::capnames($rpast, 0);
%capnames{''} := 0;
$rpast := PAST::Regex.new(
$rpast,
PAST::Regex.new( :pasttype('pass') ),
:pasttype('concat'),
:capnames(%capnames)
);
my $past := PAST::Block.new( $rpast, :name(~$<longname>), :blocktype('method'), :node($/) );
@MODIFIERS.shift;
my $name := ~$<longname>;
my $past;
if $<proto> {
$past :=
PAST::Block.new( :name($name),
PAST::Op.new(
PAST::Var.new( :name('self'), :scope('register') ),
$name,
:name('protoregex'),
:pasttype('callmethod'),
),
:blocktype('method'),
:lexical(0),
:node($/)
);
}
else {
my $rpast := $<nibbler>.ast;
my %capnames := Regex::P6Regex::Actions::capnames($rpast, 0);
%capnames{''} := 0;
$rpast := PAST::Regex.new(
$rpast,
PAST::Regex.new( :pasttype('pass') ),
:pasttype('concat'),
:capnames(%capnames)
);
$past := PAST::Block.new( $rpast, :name($name),
:blocktype('method'), :node($/) );
@MODIFIERS.shift;
}
make $past;
}

11 changes: 7 additions & 4 deletions src/Regex/P6Grammar/Grammar.pm
Expand Up @@ -17,9 +17,12 @@ grammar Regex::P6Grammar::Grammar is Regex::P6Regex::Grammar;
rule grammar_stmt { grammar <name> [ is <base=name> ]? ';' }

rule regex_stmt {
$<sym>=[regex|token|rule]
<longname>
{*} #= open
'{'<nibbler>'}'
[
| $<proto>=[proto] [regex|token|rule] <longname> '{' '<...>' '}'
| $<sym>=[regex|token|rule]
<longname>
{*} #= open
'{'<nibbler>'}'
]
}

0 comments on commit af458ca

Please sign in to comment.