Steven Bethard wrote: > Paul McGuire wrote: > >>>> I have to differentiate between: >>>> (NP -x-y) >>>> and: >>>> (NP-x -y) >>>> I'm doing this now using Combine. Does that seem right? >> >> >> If your word char set is just alphanums+"-", then this will work >> without doing anything unnatural with leaveWhitespace: >> >> from pyparsing import * >> >> thing = Word(alphanums+"-") >> LPAREN = Literal("(").suppress() >> RPAREN = Literal(")").suppress() >> node = LPAREN + OneOrMore(thing) + RPAREN >> >> print node.parseString("(NP -x-y)") >> print node.parseString("(NP-x -y)") >> >> will print: >> >> ['NP', '-x-y'] >> ['NP-x', '-y'] > > > I actually need to break these into: > > ['NP', '-x-y'] {'tag':'NP', 'word:'-x-y'} > ['NP', 'x', 'y'] {tag:'NP', 'functions':['x'], 'word':'y'}
Oops, sorry, the last line should have been: ['NP', 'x', '-y'] {tag:'NP', 'functions':['x'], 'word':'-y'} Sorry to introduce confusion into an already confusing parsing problem. ;) STeVe -- http://mail.python.org/mailman/listinfo/python-list