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

Commit

Permalink
Browse files Browse the repository at this point in the history
Add :sigspace support. Fix up comment parsing.
  • Loading branch information
pmichaud committed Oct 13, 2009
1 parent 3cc84fe commit 2cd0942
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -52,7 +52,8 @@ method termish($/) {
my $lastlit := 0;
for $<noun> {
my $ast := $_.ast;
if $lastlit && $ast.pasttype eq 'literal' {
if !$ast { }
elsif $lastlit && $ast.pasttype eq 'literal' {
$lastlit[0] := $lastlit[0] ~ $ast[0];
}
else {
Expand All @@ -66,6 +67,7 @@ method termish($/) {
method quantified_atom($/) {
my $past := $<atom>.ast;
if $<quantifier> {
if !$past { $/.panic("Can't quantify zero-width atom"); }
my $qast := $<quantifier>[0].ast;
$qast.unshift($past);
$past := $qast;
Expand Down Expand Up @@ -124,6 +126,15 @@ method quantmod($/) {
}


method metachar:sym<ws>($/) {
my $past := @MODIFIERS[0]<s>
?? PAST::Regex.new( 'ws', :pasttype('subrule'),
:subtype('method') )
!! 0;
make $past;
}


method metachar:sym<[ ]>($/) {
make $<nibbler>.ast;
}
Expand Down Expand Up @@ -421,6 +432,5 @@ method mod_internal($/) {
my %mods := @MODIFIERS[0];
my $n := $<n>[0] gt '' ?? +$<n>[0] !! 1;
%mods{ ~$<mod_ident><sym> } := $n;
my $past := PAST::Regex.new( :pasttype('anchor'), :subtype('null') );
make $past;
make 0;
}
10 changes: 4 additions & 6 deletions src/Regex/P6Regex/Grammar.pm
@@ -1,12 +1,12 @@
grammar Regex::P6Regex::Grammar is PCT::Grammar;

token ws { [ \s+ | '#' \N*\n ]* }
token ws { [ \s+ | '#' \N* ]* }

token normspace { <?before \s | '#' > <.ws> }

token TOP {
<nibbler>
[ <.ws> $ || <.panic: "Syntax error"> ]
[ $ || <.panic: "Syntax error"> ]
{*}
}

Expand All @@ -21,15 +21,12 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
}

token termish {
<.ws>
<noun=quantified_atom>+
{*}
}

token quantified_atom {
<atom>
<.ws>
[ <quantifier> <.ws> ]?
<atom> [ <.ws> <quantifier> ]?
{*}
}

Expand Down Expand Up @@ -58,6 +55,7 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token quantmod { ':'? [ '?' | '!' | '+' ]? {*} }

# proto token metachar { <...> }
token metachar:sym<ws> { <.normspace> {*} }
token metachar:sym<[ ]> { '[' <nibbler> ']' {*} }
token metachar:sym<( )> { '(' <nibbler> ')' {*} }
token metachar:sym<.> { $<sym>=['.'] {*} }
Expand Down

0 comments on commit 2cd0942

Please sign in to comment.