开发者

pyparsing with ebnf and whitespaces

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜