Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bring back rx// and :s adverb
  • Loading branch information
moritz committed Jul 24, 2011
1 parent 1123ec5 commit a50225a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 44 deletions.
4 changes: 0 additions & 4 deletions NOMMAP.markdown
Expand Up @@ -7,7 +7,6 @@ are likely to get focus sooner.

Current fails that people are likely to encounter (no particular order):
* core constants (e.g., Inf, Order::Decrease)
* regexes missing
* is export on methods
- should work outside the setting; note here if not

Expand All @@ -21,9 +20,6 @@ Things that aren't blockers but might be worth knowing about:
## Lexical Multi-Part names
For my X::Base { ... }, my Foo::Bar { ... } etc. The our-scoped ones work.

## Magicals
Move creation of $! and $/ to be per-routine instead of per-block.

## when statements
when needs to properly find use correct outer scope

Expand Down
34 changes: 16 additions & 18 deletions src/Perl6/Actions.pm
Expand Up @@ -2889,24 +2889,22 @@ class Perl6::Actions is HLL::Actions {
make $*value;
}

method setup_quotepairs($/) {
method setup_quotepair($/) {
my %h;
for @*REGEX_ADVERBS {
my $key := $_.ast.named;
my $value := $_.ast;
if $value ~~ PAST::Val {
$value := $value.value;
} else {
if %SHARED_ALLOWED_ADVERBS{$key} {
$/.CURSOR.panic('Value of adverb :' ~ $key ~ ' must be known at compile time');
}
}
if $key eq 'samecase' || $key eq 'ii' {
%h{'i'} := 1;
my $key := $*ADVERB.ast.named;
my $value := $*ADVERB.ast;
if $value ~~ PAST::Val {
$value := $value.value;
}
elsif $value<has_compile_time_value> {
$value := $value<compile_time_value>;
}
else {
if %SHARED_ALLOWED_ADVERBS{$key} {
$/.CURSOR.panic('Value of adverb :' ~ $key ~ ' must be known at compile time');
}
%h{$key} := $value;
}

%*RX{$key} := $value;
}

method quote:sym<apos>($/) { make $<quote_EXPR>.ast; }
Expand Down Expand Up @@ -2942,9 +2940,9 @@ class Perl6::Actions is HLL::Actions {
}

method quote:sym<rx>($/) {
self.handle_and_check_adverbs($/, %SHARED_ALLOWED_ADVERBS, 'rx');
my $past := Regex::P6Regex::Actions::buildsub($<p6regex>.ast);
make block_closure($past, 'Regex', 0);
my $block := PAST::Block.new(PAST::Stmts.new, PAST::Stmts.new, :node($/));
my $coderef := regex_coderef($/, $<p6regex>.ast, 'anon', '', [], $block);
make block_closure($coderef);
}
method quote:sym<m>($/) {
$regex := Regex::P6Regex::Actions::buildsub($<p6regex>.ast);
Expand Down
37 changes: 15 additions & 22 deletions src/Perl6/Grammar.pm
Expand Up @@ -1587,6 +1587,14 @@ grammar Perl6::Grammar is HLL::Grammar {
]
}

token rx_adverbs {
[
<quotepair> <.ws>
:my $*ADVERB;
{ $*ADVERB := $<quotepair>[-1] }
<.setup_quotepair>
]*
}

proto token quote { <...> }
token quote:sym<apos> { <?[']> <quote_EXPR: ':q'> }
Expand All @@ -1602,10 +1610,8 @@ grammar Perl6::Grammar is HLL::Grammar {
token quote:sym</ /> { '/' :my %*RX; <p6regex=.LANG('Regex','nibbler')> '/' <.old_rx_mods>? }
token quote:sym<rx> {
<sym> >>
[ <quotepair> <.ws> ]*
:my @*REGEX_ADVERBS;
{ @*REGEX_ADVERBS := $<quotepair>; }
<.setup_quotepairs>
:my %*RX;
<rx_adverbs>
[
| '/'<p6regex=.LANG('Regex','nibbler')>'/' <.old_rx_mods>?
| '{'<p6regex=.LANG('Regex','nibbler')>'}' <.old_rx_mods>?
Expand All @@ -1621,35 +1627,22 @@ grammar Perl6::Grammar is HLL::Grammar {

token quote:sym<m> {
<sym> (s)?>>
[ <quotepair> <.ws> ]*
:my @*REGEX_ADVERBS;
{ @*REGEX_ADVERBS := $<quotepair>;
if $/[0] {
pir::push__vPP(@*REGEX_ADVERBS, $/.CURSOR.match_with_adverb('s'));
}
}
<.setup_quotepairs>
:my %*RX;
<rx_adverbs>
[
| '/'<p6regex=.LANG('Regex','nibbler')>'/' <.old_rx_mods>?
| '{'<p6regex=.LANG('Regex','nibbler')>'}'
]
<.cleanup_modifiers>
}

token setup_quotepairs { '' }
token setup_quotepair { '' }
token cleanup_modifiers { '' }

token quote:sym<s> {
<sym> (s)? >>
[ <quotepair> <.ws> ]*
:my @*REGEX_ADVERBS;
{
@*REGEX_ADVERBS := $<quotepair>;
if $/[0] {
pir::push__vPP(@*REGEX_ADVERBS, $/.CURSOR.match_with_adverb('s'));
}
}
<.setup_quotepairs>
:my %*RX;
<rx_adverbs>
[
| '/' <p6regex=.LANG('Regex','nibbler')> <?[/]> <quote_EXPR: ':qq'> <.old_rx_mods>?
| '[' <p6regex=.LANG('Regex','nibbler')> ']'
Expand Down

0 comments on commit a50225a

Please sign in to comment.