Skip to content

Instantly share code, notes, and snippets.

@ungrim97
Last active November 1, 2015 15:16
Show Gist options
  • Save ungrim97/98a8ca3d252215b544ca to your computer and use it in GitHub Desktop.
Save ungrim97/98a8ca3d252215b544ca to your computer and use it in GitHub Desktop.
diff --git a/src/QRegex/P6Regex/Actions.nqp b/src/QRegex/P6Regex/Actions.nqp
index 2eb8131..c92fa02 100644
--- a/src/QRegex/P6Regex/Actions.nqp
+++ b/src/QRegex/P6Regex/Actions.nqp
@@ -145,40 +145,41 @@ class QRegex::P6Regex::Actions is HLL::Actions {
make backmod($qast, $<backmod>);
}
method quantifier:sym<?>($/) {
my $qast := QAST::Regex.new( :rxtype<quant>, :subtype<item>, :min(0), :max(1), :node($/) );
make backmod($qast, $<backmod>);
}
method quantifier:sym<**>($/) {
my $qast;
if $<codeblock> {
$qast := QAST::Regex.new( :rxtype<dynquant>, :node($/),
QAST::Op.new( :op('callmethod'), :name('!DYNQUANT_LIMITS'),
QAST::Var.new( :name('$¢'), :scope('lexical') ),
$<codeblock>.ast
),
);
}
else {
my $min := $<min>.ast;
+ if $<min>.Str eq '^' { $min := 0 }
my $max := -1;
if ! $<max> { $max := $min }
elsif $<max> ne '*' {
$max := $<max>.ast;
$/.CURSOR.panic("Empty range") if $min > $max;
}
$qast := QAST::Regex.new( :rxtype<quant>, :min($min), :max($max), :node($/) );
}
make backmod($qast, $<backmod>);
}
method codeblock($/) {
my $block := $<block>.ast;
$block.blocktype('immediate');
my $ast :=
QAST::Stmts.new(
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name('$/'), :scope('lexical') ),
QAST::Op.new(
diff --git a/src/QRegex/P6Regex/Grammar.nqp b/src/QRegex/P6Regex/Grammar.nqp
index 924d586..1abc959 100644
--- a/src/QRegex/P6Regex/Grammar.nqp
+++ b/src/QRegex/P6Regex/Grammar.nqp
@@ -239,40 +239,41 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
token sigmaybe:sym<sigwhite> {
<?{$*SIGOK}> <normspace>
}
proto token quantifier { <...> }
token quantifier:sym<%> {
('%''%'?) {
$/.CURSOR.panic("Missing quantifier on the left argument of " ~ $/[0]);
}
}
token quantifier:sym<*> { <sym> <backmod> }
token quantifier:sym<+> { <sym> <backmod> }
token quantifier:sym<?> { <sym> <backmod> }
token quantifier:sym<{N,M}> { {} '{' (\d+) (','?) (\d*) '}'
<.obs: '{N,M} as general quantifier', '** N..M (or ** N..*)'>
}
token quantifier:sym<**> {
<sym> <.normspace>? <backmod> <.normspace>?
[
+ | $<min>=['^'] <max=.integer>
| <min=.integer> \s+ '..' <.throw_spaces_in_bare_range>
| <min=.integer>
[ '..'
[
| <max=.integer> {
$/.CURSOR.panic("Negative numbers are not allowed as quantifiers") if $<max>.Str < 0;
}
| $<max>=['*']
| <.throw_malformed_range>
]
]?
{ $/.CURSOR.panic("Negative numbers are not allowed as quantifiers") if $<min>.Str < 0 }
| <?[{]> <codeblock>
]
}
token codeblock {
<block=.LANG('MAIN','pblock')>
}
~/Programming/Perl6/nqp [feature/repeat_regex_all_seq*]$ nqp-m -e 'say("hello" ~~ /l**^2/)'
Quantifier quantifies nothing. at line 2, near "^3/)"
at gen/moar/stage2/NQPHLL.nqp:519 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm:panic:105)
from gen/moar/stage2/NQPP6QRegex.nqp:83 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:throw_solitary_quantifier:11)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:metachar:sym<quantifier>:95
)
from gen/moar/stage2/QRegex.nqp:1350 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/QRegex.moarvm:!protoregex:
109)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:metachar:10)
from gen/moar/stage2/NQPP6QRegex.nqp:232 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:ato
m:247)
from gen/moar/stage2/NQPP6QRegex.nqp:214 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:qua
ntified_atom:66)
from gen/moar/stage2/NQPP6QRegex.nqp:198 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:termish:101)
from gen/moar/stage2/NQPP6QRegex.nqp:187 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:ter
mconj:57)
from gen/moar/stage2/NQPP6QRegex.nqp:182 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:ter
malt:57)
from gen/moar/stage2/NQPP6QRegex.nqp:177 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:ter
mconjseq:57)
from gen/moar/stage2/NQPP6QRegex.nqp:172 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:ter
maltseq:57)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:termseq:57)
from gen/moar/stage2/NQPP6QRegex.nqp:138 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPP6QRegex.moarvm:nib
bler:337)
from gen/moar/stage2/NQPHLL.nqp:898 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm:LANG:146)
from gen/moar/stage2/NQP.nqp:1470 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:quote:sym</ />:109
)
from gen/moar/stage2/QRegex.nqp:1350 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/QRegex.moarvm:!protoregex:
109)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:quote:10)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:value:79)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:term:sym<value>:57)
from gen/moar/stage2/QRegex.nqp:1350 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/QRegex.moarvm:!protoregex:
109)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm:term:10)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm:termish:159)
from gen/moar/stage2/NQPHLL.nqp:681 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/NQPHLL.moarvm:EXPR:74)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:arglist:91)
from <unknown>:1 (/home/mike/.rakudobrew/moar-nom/install/share/nqp/lib/nqp.moarvm:args:64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment