Skip to content

Commit

Permalink
Enable :P5 on m/.../ and rx/.../ patterns.
Browse files Browse the repository at this point in the history
Throw exception if attempting to use colon as quoting delimiter.
  • Loading branch information
pmichaud committed Mar 27, 2009
1 parent c3e5408 commit 353aca7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/parser/actions.pm
Expand Up @@ -2362,6 +2362,14 @@ method quote_expression($/, $key) {
:node( $/ )
);
}
elsif $key eq 'quote_p5regex' {
$past := PAST::Block.new(
$<quote_p5regex>,
:compiler('PGE::P5Regex'),
:blocktype('declaration'),
:node( $/ )
);
}
elsif $key eq 'quote_pir' {
$past := PAST::Op.new( :inline( $<quote_pir> ), :node($/) );
}
Expand Down
5 changes: 4 additions & 1 deletion src/parser/grammar.pg
Expand Up @@ -843,7 +843,10 @@ token quote {
| <.before '<' > <quote_expression: :w :q>
# | <.before '«' > <quote_expression: :ww :qq> FIXME: unicode
| <.before '/'> <quote_expression: :regex>
| m <.ws> <quote_expression: :regex>
| [m|rx] <.ws>
[ [':P5'|':Perl5'] <.ws> <quote_expression: :regex :P5>
| <quote_expression: :regex>
]
| q [ <.ws> ':' ]?
[ q <.ws> <quote_expression: :qq>
| w <.ws> <quote_expression: :q :w>
Expand Down
19 changes: 14 additions & 5 deletions src/parser/quote_expression.pir
Expand Up @@ -12,6 +12,7 @@
brackets = unicode:"<>[](){}\xab\xbb\u0f3a\u0f3b\u0f3c\u0f3d\u169b\u169c\u2045\u2046\u207d\u207e\u208d\u208e\u2329\u232a\u2768\u2769\u276a\u276b\u276c\u276d\u276e\u276f\u2770\u2771\u2772\u2773\u2774\u2775\u27c5\u27c6\u27e6\u27e7\u27e8\u27e9\u27ea\u27eb\u2983\u2984\u2985\u2986\u2987\u2988\u2989\u298a\u298b\u298c\u298d\u298e\u298f\u2990\u2991\u2992\u2993\u2994\u2995\u2996\u2997\u2998\u29d8\u29d9\u29da\u29db\u29fc\u29fd\u3008\u3009\u300a\u300b\u300c\u300d\u300e\u300f\u3010\u3011\u3014\u3015\u3016\u3017\u3018\u3019\u301a\u301b\u301d\u301e\ufd3e\ufd3f\ufe17\ufe18\ufe35\ufe36\ufe37\ufe38\ufe39\ufe3a\ufe3b\ufe3c\ufe3d\ufe3e\ufe3f\ufe40\ufe41\ufe42\ufe43\ufe44\ufe47\ufe48\ufe59\ufe5a\ufe5b\ufe5c\ufe5d\ufe5e\uff08\uff09\uff3b\uff3d\uff5b\uff5d\uff5f\uff60\uff62\uff63"

start = substr target, pos, 1
if start == ':' goto err_colon_delim
stop = start
$I0 = index brackets, start
if $I0 < 0 goto end
Expand All @@ -34,6 +35,8 @@
stop = repeat stop, len
end:
.return (start, stop)
err_colon_delim:
self.'panic'("Colons cannot be used as delimiters in quoting constructs")
.end


Expand Down Expand Up @@ -95,22 +98,28 @@
lastpos -= stoplen
options['stop'] = stop

.local pmc p6regex, quote_regex
.local pmc quote_regex
$I0 = options['regex']
if $I0 goto regex_start
$I0 = options['PIR']
if $I0 goto pir_start
goto word_start

regex_start:
.local string key
key = 'quote_regex'
.local pmc regexparse
## handle :regex parsing
p6regex = get_root_global ['parrot';'PGE';'Perl6Regex'], 'regex'
regexparse = get_root_global ['parrot';'PGE';'Perl6Regex'], 'regex'
$I0 = options['P5']
unless $I0 goto have_regexparse
regexparse = get_root_global ['parrot';'PGE';'P5Regex'], 'p5regex'
key = 'quote_p5regex'
have_regexparse:
mob.'to'(pos)
quote_regex = p6regex(mob, options :flat :named)
quote_regex = regexparse(mob, options :flat :named)
unless quote_regex goto fail
pos = quote_regex.'to'()
.local string key
key = 'quote_regex'
mob[key] = quote_regex
goto succeed

Expand Down

0 comments on commit 353aca7

Please sign in to comment.