Permalink
Browse files

[pge]: Update P5Regex so that its parser recognizes specific stop tok…

…ens.

git-svn-id: https://svn.parrot.org/parrot/trunk@37752 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 295b1db commit 48890757b3a994e4cdf767d08b0d0a33a68fdf30 @pmichaud pmichaud committed Mar 27, 2009
Showing with 38 additions and 3 deletions.
  1. +38 −3 compilers/pge/PGE/P5Regex.pir
@@ -15,9 +15,20 @@
target = adverbs['target']
target = downcase target
+ ## If we're passed the results of a previous parse, use it.
.local pmc match
+ $I0 = isa source, ['PGE';'Match']
+ if $I0 == 0 goto parse
+ $P0 = source['expr']
+ if null $P0 goto parse
+ $I0 = isa $P0, ['PGE';'Exp']
+ if $I0 == 0 goto parse
+ match = source
+ goto analyze
+
+ parse:
$P0 = get_global "p5regex"
- match = $P0(source)
+ match = $P0(source, adverbs :flat :named)
if target != 'parse' goto check
.return (match)
@@ -42,9 +53,20 @@
.sub "p5regex"
.param pmc mob
- .local pmc optable
+ .param pmc adverbs :slurpy :named
+
+ .local string stop, tighter
+ .local pmc stopstack, optable
+
+ stopstack = get_hll_global ['PGE';'P5Regex'], '@!stopstack'
optable = get_hll_global ["PGE";"P5Regex"], "$optable"
- $P0 = optable."parse"(mob)
+
+ stop = adverbs['stop']
+ tighter = adverbs['tighter']
+ push stopstack, stop
+ $P0 = optable."parse"(mob, 'stop'=>stop, 'tighter'=>tighter)
+ $S0 = pop stopstack
+
.return ($P0)
.end
@@ -92,6 +114,10 @@
optable.'newtok'('close:}', 'looser'=>'infix:|', 'nows'=>1) # XXX: hack
+ # Create a stack for holding stop tokens
+ $P0 = new 'ResizablePMCArray'
+ set_hll_global ['PGE';'P5Regex'], '@!stopstack', $P0
+
$P0 = get_hll_global ["PGE";"P5Regex"], "compile_p5regex"
compreg "PGE::P5Regex", $P0
.end
@@ -149,8 +175,17 @@
term_literal:
litstart = pos
litlen = 0
+ .local string stop
+ .local int stoplen
+ $P0 = get_hll_global ['PGE';'P5Regex'], '@!stopstack'
+ stop = $P0[-1]
+ stoplen = length stop
term_literal_loop:
if pos >= lastpos goto term_literal_end
+ if stoplen == 0 goto not_stop
+ $S0 = substr target, pos, stoplen
+ if $S0 == stop goto term_literal_end
+ not_stop:
$S0 = substr target, pos, 1
$I0 = index "[](){}*?+\\|^$.", $S0
# if not in circumfix:( ) throw error on end paren

0 comments on commit 4889075

Please sign in to comment.