Menu

#85 Incorrect location of ParseException given

v1.0 (example)
open
nobody
None
5
2015-12-23
2015-12-23
No

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.