本文介绍了如何将简单的语法转换为可在PEG.js中使用的语法(预期为"a"但找到"a")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始玩PEG.js,语法有问题(调试时大大简化了):
I've just started playing with PEG.js and have a problem with a grammar (vastly simplified for debugging):
start
= presingle single
/ preplural plural
presingle
= "a"
/ "b"
preplural
= "b"
/ "c"
single
= "d"
/ "e"
plural
= "dd"
/ "ee"
我正在使用 https://pegjs.org/online
此语法无法解析bdd
.
Line 1, column 3: Expected "a" but "d" found.
这是PEG不能做的事情吗,还是可以将我的语法转换成可以对此进行解析的事情?
Is this something which PEGs cannot do, or can I transform my grammar into something which will parse this?
P.S.如果我尝试解析(错误建议?)bda
,我会得到无意义的错误:
P.S. If I try to parse the (erroneously advised?) bda
I get the nonsensical error:
Line 1, column 3: Expected "a" but "a" found.
推荐答案
此语法仅更改开始中子句的顺序,并适用于bdd
This grammar changes only the order of the clauses in start and works for bdd
start =
preplural plural /
presingle single
presingle
= "a"
/ "b"
preplural
= "b"
/ "c"
single
= "d"
/ "e"
plural
= "dd"
/ "ee"
并且对于bda显示错误第1行,第3列:预期为"dd"或"ee",但找到了"a".
and for bda shows error Line 1, column 3: Expected "dd" or "ee" but "a" found.
这篇关于如何将简单的语法转换为可在PEG.js中使用的语法(预期为"a"但找到"a")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!