[egenix-users] Continuous searching of text thru all characters on line

Pekka Niiranen krissepu at vip.fi
Sun Jun 23 21:20:27 CEST 2002


I am using the mxTextTool in mxBase 2.1.0b2.

I am parsing a line that may contain multiple non-overlapping matches:

---- code starts ---
import os
import pprint
from mx.TextTools import *

letter_set = set(alpha)
linput = "aa?BB!aa?DD!aa"
head_pos = None


def pr(taglist,txt,l,r,subtag):
    """Print matched string"""
    print txt[l:r]

matchtable = ((pr, AllIn+CallTag, '?', +1),
              (pr, AllInSet+CallTag, letter_set, +1),
              (pr, AllIn+CallTag, '!', +1, MatchOk),
              (None, Fail, Here)) #This is needed in order to avoid
infinite loop


tagtable = ((None, AllInSet, letter_set, +1),
            ('m', Table+AppendMatch, matchtable),
            (None, Table, ThisTable)) # Continue searching after first
match on line.


result,taglist,next = tag(linput, tagtable)
print taglist
print "-------"

---- code ends ---

The problem is that "print taglist" returns only ['?BB!'] instead of
['?BB!', ?DD!']
i.e the recursive call of tagtable is not added into taglist. However,
as function pr
reveals, ?DD! is found by mxTextTool.

Is it possible to add all the matched strings into a single table that
does not subtables ?
(not ['?BB!, [?DD!]])

-pekka-




More information about the egenix-users mailing list