[egenix-users] Help needed for context object in mxTextTools 2.1.0

Pekka Niiranen krissepu at vip.fi
Sun Aug 11 23:08:09 CEST 2002


Hi,

I am currently perfecting my parser by
trying to add error messages to it.
I found error messages mentioned in documentation
were context object were explained, but had problems
understanding what is meant with "context".

If I understood correctly I should be able to:

1)  instead of saying "MatchFail", jump to a location
     were I call python function that prints Errortext first and
     only then call "MatchFail".

2)  set flag that tells I am recursing at the moment and at error
     check flag and print messages according to flags' value.

a) Should I use Call or CallTag -function ?
b) What is the difference of adding Python function to tag() -command 
instead of  using CallTag ?
c) should I use mxStack instead of a python variable for the flag ? This 
is a speed issue.
d) Merging error printing with mxTextTools C-engine's MatchFail -state. 
Possible ?

---code starts ---

NOTE: IF-ELSE -structure can (and must ?) be implemented with jumps.

from mx.TextTools import *

text = "Xaa(AA)a((BB))aa((CC)DD)aa(EE(FF))aa(GG(HH(II)JJ)KK)aaY"

tables = []

tab = ('start',
       (None, AllNotIn,'()', +1),
       (None, Is+LookAhead, '(', "IF FLAG IS NOT SET PRINT ERROR 
'SPURIOUS )-SIGN' and MatchFail"\
                                                 ELSE UNSET FLAG and 
MatchOk", 'nesting'),
       'nesting',
       "SET FLAG ON",
       ('group',SubTable+AppendMatch,((None, Is, '(', +1),
                                      (None, SubTableInList, (tables,0)),
                                      (None, Is, ')', "PRINT ERROR 
'SPURIOUS (-SIGN' and MatchFail", MatchOk))),
       (None,Jump,To,'start'))

tables.append(tab) # Add tab to tables

if __name__ == '__main__':

    result, taglist, nextindex = tag(text,tab)
    print taglist

--code stops---

-pekka-




More information about the egenix-users mailing list