Incorrect location of ParseException given
Brought to you by:
ptmcg
The ParseException thrown in the below code has a location of char 0, line 1, col 1. I am expecting a location around line 9.
#!/usr/bin/python
from pyparsing import *
# sample string with enums and other stuff
sample = \
'''enum hello {
Zero,
One,
Two,
Three,
Five=5,
Six,
Ten=10
.};
enum blah
{
alpha,
beta,
gamma = 10 ,
zeta = 50
};
'''
# syntax we don't want to see in the final parse tree
LBRACE,RBRACE,EQ,COMMA,SEMICOLON = map(Suppress,"{}=,;")
_enum = Suppress('enum')
identifier = Word(alphas,alphanums+'_')
integer = Word(nums)
enumValue = Group(identifier('name') + Optional(EQ + integer('value')))
enumList = Group(enumValue + ZeroOrMore(COMMA + enumValue))
enum = _enum + identifier('enum') + LBRACE + enumList('names') + RBRACE + SEMICOLON
enums = ZeroOrMore(Group(enum))
enum_vals = enums.parseString(sample, parseAll=True)
print enum_vals