[svn:parrot] r41631 - branches/pct-rx/compilers/pct/src/Regex

pmichaud at svn.parrot.org pmichaud at svn.parrot.org
Sat Oct 3 06:20:38 UTC 2009


Author: pmichaud
Date: Sat Oct  3 06:20:38 2009
New Revision: 41631
URL: https://trac.parrot.org/parrot/changeset/41631

Log:
[pct-rx]:  Add Cursor.!literal, P6Regex.quantmod.

Modified:
   branches/pct-rx/compilers/pct/src/Regex/Cursor.pir
   branches/pct-rx/compilers/pct/src/Regex/P6Regex.pir

Modified: branches/pct-rx/compilers/pct/src/Regex/Cursor.pir
==============================================================================
--- branches/pct-rx/compilers/pct/src/Regex/Cursor.pir	Sat Oct  3 05:50:10 2009	(r41630)
+++ branches/pct-rx/compilers/pct/src/Regex/Cursor.pir	Sat Oct  3 06:20:38 2009	(r41631)
@@ -545,6 +545,42 @@
 .end
 
 
+=item !literal(str [, pos :named('pos')] )
+
+Perform a literal match of C<str> using the current cursor
+(starting at C<pos>, if supplied).  If the match is successful, 
+the cursor is moved to the end of the literal string.
+
+=cut
+
+.sub '!literal' :method
+    .param string str
+    .param pmc pos             :named('pos') :optional
+    .param int has_pos         :opt_flag
+
+    unless has_pos goto pos_0
+    setattribute self, '$!pos', pos
+    goto pos_done
+  pos_0:
+    pos = getattribute self, '$!pos'
+  pos_done:
+
+    .local string target
+    $P0 = getattribute self, '$!target'
+    target = $P0
+
+    $I0 = pos
+    $I1 = length str
+    $S0 = substr target, $I0, $I1
+    unless $S0 == str goto fail
+    add $P0, pos, $I1
+    setattribute self, '$!pos', $P0
+    .return (1, pos)
+  fail:
+    .return (0, pos)    
+.end
+
+
 =item !subrule(subname [, bindnames :slurpy] [, pos :named('pos')] )
 
 Perform a subrule match on C<name>, binding any successful

Modified: branches/pct-rx/compilers/pct/src/Regex/P6Regex.pir
==============================================================================
--- branches/pct-rx/compilers/pct/src/Regex/P6Regex.pir	Sat Oct  3 05:50:10 2009	(r41630)
+++ branches/pct-rx/compilers/pct/src/Regex/P6Regex.pir	Sat Oct  3 06:20:38 2009	(r41631)
@@ -151,23 +151,39 @@
     .local string target
     .local int pos
     (cur, pos, target) = self.'!cursor_start'()
-    $S0 = substr target, pos, 1
-    if $S0 != '*' goto fail
-    inc pos
+    $I0 = cur.'!literal'('*')
+    unless $I0 goto fail
     cur.'!match_bind'('*', 'sym')
-    goto done
-    cur.'!cursor_pos'(pos)
-    quantmod = cur.'quantmod'()
+    quantmod = cur.'!subrule'('quantmod', 'quantmod')
     unless quantmod goto fail
-    pos = quantmod.'pos'()
-    cur.'!match_bind'(quantmod, 'quantmod')
   done:
-    cur.'!matchify'('pos'=>pos)
+    cur.'!matchify'()
   fail:
     .return (cur)
 .end
 
 
+=item quantmod
+
+    token quantmod { ':'? [ '?' | '!' | '+' ]? }
+
+=cut
+
+.sub 'quantmod' :method
+    .local pmc cur
+    cur = self.'!cursor_start'()
+    cur.'!literal'(':')
+    $I0 = cur.'!literal'('?')
+    if $I0 goto done
+    $I0 = cur.'!literal'('!')
+    if $I0 goto done
+    $I0 = cur.'!literal'('+')
+  done:
+    cur.'!matchify'()
+    .return (cur)
+.end
+
+
 =back
 
 =head1 AUTHORS


More information about the parrot-commits mailing list