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

Commit

Permalink
[nqp]: Add regex_declarator.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 28, 2009
1 parent 819be4d commit b1c6254
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -135,6 +135,7 @@ method noun:sym<variable>($/) { make $<variable>.ast; }
method noun:sym<package_declarator>($/) { make $<package_declarator>.ast; }
method noun:sym<scope_declarator>($/) { make $<scope_declarator>.ast; }
method noun:sym<routine_declarator>($/) { make $<routine_declarator>.ast; }
method noun:sym<regex_declarator>($/) { make $<regex_declarator>.ast; }

method colonpair($/) {
my $past := $<circumfix>
Expand Down Expand Up @@ -300,6 +301,43 @@ method named_param($/) {
make $past;
}

method regex_declarator($/, $key?) {
my @MODIFIERS := Q:PIR {
%r = get_hll_global ['Regex';'P6Regex';'Actions'], '@MODIFIERS'
};
my $name := ~$<deflongname>.ast;
my $past;
if $key eq 'open' {
my %h;
if $<sym> eq 'token' { %h<r> := 1; }
if $<sym> eq 'rule' { %h<r> := 1; %h<s> := 1; }
@MODIFIERS.unshift(%h);
Q:PIR {
$P0 = find_lex '$name'
set_hll_global ['Regex';'P6Regex';'Actions'], '$REGEXNAME', $P0
};
return 0;
}
else {
my $rpast := $<p6regex_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 := @BLOCK.shift;
$past.blocktype('method');
$past.name($name);
$past.push($rpast);
@MODIFIERS.shift;
}
make $past;
}


method dotty($/) {
my $past := $<args> ?? $<args>[0].ast !! PAST::Op.new( :node($/) );
$past.name( ~$<identifier> );
Expand Down
1 change: 1 addition & 0 deletions src/NQP/Compiler.pir
Expand Up @@ -11,6 +11,7 @@ NQP::Compiler - NQP compiler
.sub '' :anon :load :init
load_bytecode 'PCT.pbc'
load_bytecode 'HLLGrammar.pbc'
load_bytecode 'P6Regex.pbc'
.end

.include 'src/gen/nqp-grammar.pir'
Expand Down
11 changes: 11 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -120,6 +120,7 @@ token noun:sym<variable> { <variable> }
token noun:sym<package_declarator> { <package_declarator> }
token noun:sym<scope_declarator> { <scope_declarator> }
token noun:sym<routine_declarator> { <routine_declarator> }
token noun:sym<regex_declarator> { <regex_declarator> }

token colonpair {
':'
Expand Down Expand Up @@ -197,6 +198,16 @@ token named_param {

rule default_value { '=' <EXPR('i=')> }

rule regex_declarator {
[
| $<sym>=[regex|token|rule]
<deflongname>
<.newpad>
{*} #= open
'{'<p6regex_nibbler>'}'
]
}

token dotty {
'.' <identifier>
[
Expand Down
11 changes: 11 additions & 0 deletions src/cheats/nqp-builtins.pir
Expand Up @@ -60,3 +60,14 @@
match[1] = $P1
match[2] = $P0
.end


.sub 'p6regex_nibbler' :method
.local pmc regexproto, cur, pos
regexproto = get_hll_global ['Regex';'P6Regex'], 'Grammar'
(cur, pos) = self.'!cursor_start'(regexproto)
cur.'!cursor_pos'(pos)
$P0 = get_hll_global ['Regex';'P6Regex'], 'Actions'
setattribute cur, '$!action', $P0
.tailcall cur.'nibbler'()
.end

0 comments on commit b1c6254

Please sign in to comment.