Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
[regex]: Building a tokrx hash can result in the protoregex hash
Browse files Browse the repository at this point in the history
being modified while it's being iterated -- refactor so that
we get the complete list of method names from the protoregex hash
before we start building tokrx.
  • Loading branch information
pmichaud committed Oct 26, 2009
1 parent 09880e0 commit 9f56d59
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/Regex/Cursor-protoregex-peek.pir
Expand Up @@ -158,34 +158,43 @@ create a new one and return it.
tokrx = new ['Hash']

# The prototable has already collected all of the names of
# protoregex methods into C<prototable>. We set up a loop
# to find all of the method names that begin with "name:sym<".
# protoregex methods as keys in C<prototable>. First
# get a list of all of the methods that begin with "name:sym<".
.local string mprefix
.local int mlen
mprefix = concat name, ':sym<'
mlen = length mprefix

.local pmc method_it, method, sorttok
.local string method_name
.local pmc methodlist, proto_it
methodlist = new ['ResizableStringArray']
proto_it = iter prototable
proto_loop:
unless proto_it goto proto_done
.local string methodname
methodname = shift proto_it
$S0 = substr methodname, 0, mlen
if $S0 != mprefix goto proto_loop
push methodlist, methodname
goto proto_loop
proto_done:

# Now, walk through all of the methods, building the
# tokrx and toklen tables as we go.
.local pmc sorttok
sorttok = new ['ResizablePMCArray']
method_it = iter prototable
method_loop:
unless method_it goto method_done
method_name = shift method_it
$S0 = substr method_name, 0, mlen
if $S0 != mprefix goto method_loop
unless methodlist goto method_done
methodname = shift methodlist

# Okay, we've found a method name intended for this protoregex.
# Look up the method itself.
.local pmc rx
rx = find_method self, method_name
rx = find_method self, methodname

# Now find the prefix tokens for the method; calling the
# method name with a !PREFIX__ prefix should return us a list
# of valid token prefixes. If no such method exists, then
# our token prefix is a null string.
.local pmc tokens, tokens_it
$S0 = concat '!PREFIX__', method_name
$S0 = concat '!PREFIX__', methodname
$I0 = can self, $S0
unless $I0 goto method_peek_none
tokens = self.$S0()
Expand Down

0 comments on commit 9f56d59

Please sign in to comment.