make sure entire string was parsed

Steven Bethard steven.bethard at gmail.com
Mon Sep 12 12:06:00 EDT 2005


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



More information about the Python-list mailing list