質問

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?

役に立ちましたか?

解決

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')
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top