Question

I'm using http://pyparsing.wikispaces.com/file/view/ebnf.py to convert my ebnf definition.

ebnf def looks like this:

TEST = A, SPACE, A;

A = "AA" | "BB";
SPACE = " ";

if I load the file and try to parse a string like:

e = ebnf.parse(ebnf_file)
e['TEST'].leaveWhitespace().parseString('AA BB') # same without leaveWhitespace()

I get:

ParseException: Expected " " (at char 3), (line:1, col:4)

Does anybody have an ideas/solutions?

Was it helpful?

Solution

The leaveWhitespace() has to be applied to the original whitespace-containing tag, so try the following:

e = ebnf.parse(ebnf_file)
e['SPACE'] = e['SPACE'].leaveWhitespace()
e['TEST'].parseString('AA BB')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top