[egenix-users] SimpleParse 2.0 alpha (+ mx.TextTools 2.1 beta2)

Pekka Niiranen krissepu at vip.fi
Sat Jul 13 23:21:05 CEST 2002


I used latest alpha of Simpleparse 2.0 and it worked OK in my problem, but

- I could not understand the section where AppendMatch, CallTag etc. were
explained.
  How do I enforce Simpleparse to use "AppendMatch  + Subtable" -parameters
together ?

- I hit the solution to the problem I mentioned on June with code 1 (Sheer
luck). However, could you
  explain why > - and < -sign are compulsonary in that solution ?

- The code 2 functions allmost as as code 1, with starting ? -sign missing from
returned items.
  Any ideas how to append that to results? (I should somehow merge ? -sign to
returned nested match)
  I doubt the tagtable returned by the Simpleparse is the shortest/quickest
solution.
  Maybe  I could LookAhead the "?" -sign and then add it to result only when I
am recursing ?

- Would it be possible to add support for compination "LookAhead+CallTag" to
mxTextTools ?
   This would help debugging.

--- code 1 starts --

import string, pprint, os
from mx.TextTools import TextTools
from simpleparse.parser import *

declaration = r'''
>line<  := (a/match)+
match   := '?', line, '!'
<a>     := -[?!]
'''
text1 = "?AA!aa??BB!!aa??CC!DD!aa?EE?FF!!aa?GG?HH?II!JJ!KK!"

parser = Parser(declaration)
success, children, nextcharacter = parser.parse(text1, production = "line")
print_tags(text1, children)

--- code 1 ends ---

--- code 2 starts --

import sys,string
from mx.TextTools import *

text = "?AA!aa??BB!!aa??CC!DD!aa?EE?FF!!aa?GG?HH?II!JJ!KK!"

rtf = ('start',
       (None, Is, '?', +1, 'nesting'),  # How to add ? -sign to result only when
we are nesting ?
       (None, Is, '!', +1, MatchOk),
       (None, AllNotIn, '?!', 0, 'start'),
       'nesting',
       ('group', SubTable+AppendMatch, ThisTable, 0, 'start'))

if __name__ == '__main__':

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

--- code 2 ends ---


-pekka-




More information about the egenix-users mailing list