开发者

pyparsing with ebnf and whitespaces

开发者 https://www.devze.com 2023-04-06 03:50 出处:网络
I\'m using http://pyparsing.wikispaces.com/file/view/ebnf.py to convert my ebnf definition. ebnf def looks like this:

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

精彩评论

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

关注公众号