Pyparsing: Specify grammar at run time

Paul McGuire ptmcg at austin.rr._bogus_.com
Wed May 17 19:15:59 EDT 2006


"Khoa Nguyen" <khoa.coffee at gmail.com> wrote in message
news:mailman.5845.1147902428.27775.python-list at python.org...
I run into another issue with my grammar:

My input record contains a common part and an extended part. Based on
the value of the common part, the extended part will be different. So,
I am thinking of parsing the common part first and check the common's
value and then parse again for the rest of the record. How do I tell
pyparsing to start the 2nd parse at the exact location where the 1st
parse left off?

######################################
from pyparsing import *

common = Word('aA').setResultsName('value')
extend1 = Word('b')
extend2 = Word('c')

result = common.parseString(record)
if result.value == 'a':
   result1 = extend1.parseString(???)
else:
   result2 = extend2.parseString(???)
######################################

Thanks,
Khoa

Any reason you can't construct a grammar that looks like:

allData = "a"





More information about the Python-list mailing list