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

Commit

Permalink
[p6grammar]: Action methods to automatically create grammar object.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 15, 2009
1 parent fbb15ef commit fb80e2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Regex/P6Grammar.pir
Expand Up @@ -16,7 +16,7 @@ Regex::P6Grammar - scaffolding compiler for NQP / Perl 6 grammars
load_bytecode 'p6regex.pbc'
.local pmc p6meta, p6grammar
p6meta = get_hll_global 'P6metaclass'
p6grammar = p6meta.'new_class'('Regex::P6Grammar', 'parent'=>'PCT::HLLCompiler')
p6grammar = p6meta.'new_class'('Regex::P6Grammar::Compiler', 'parent'=>'PCT::HLLCompiler')
p6grammar.'language'('Regex::P6Grammar')
$P0 = get_hll_namespace ['Regex';'P6Grammar';'Grammar']
p6grammar.'parsegrammar'($P0)
Expand Down
18 changes: 17 additions & 1 deletion src/Regex/P6Grammar/Actions.pm
@@ -1,14 +1,30 @@
class Regex::P6Grammar::Actions is Regex::P6Regex::Actions;

method TOP($/) {
my $past := PAST::Stmts.new();
my $past := $<grammar_stmt>.ast;
for $<regex_stmt> {
$past.push( $_.ast );
}
make $past;
}


method grammar_stmt($/) {
my @ns := Regex::P6Grammar::Compiler.parse_name( ~$<name> );
my $past := PAST::Block.new( :namespace(@ns) );
my $init :=
PAST::Op.new(
PAST::Var.new( :name('P6metaclass'), :scope('package'),
:namespace('') ),
~$<name>,
PAST::Val.new( :value('Regex::Cursor'), :named('parent') ),
:pasttype('callmethod'), :name('new_class')
);
$past.loadinit($init);
make $past;
}


method regex_stmt($/, $key?) {
my @MODIFIERS := Q:PIR {
%r = get_hll_global ['Regex';'P6Regex';'Actions'], '@MODIFIERS'
Expand Down

0 comments on commit fb80e2d

Please sign in to comment.