Javascript 为什么pegjs无法处理空白规则&引用*
以下简单的pegjs语法可以很好地工作:Javascript 为什么pegjs无法处理空白规则&引用*,javascript,parsing,peg,pegjs,Javascript,Parsing,Peg,Pegjs,以下简单的pegjs语法可以很好地工作: start = sentence sentence = word ws sentence / word word = [a-z]* ws = " " 可在以下网址下载:。gramar也可以粘贴到 如果我将ws规则更改为允许空白或任意空格: ws = " "* // add an asterisk to allow " ", " ", " ", ... 解析失败,引发最大调用堆栈异常。(如果使用JSFIDLE,
start
= sentence
sentence
= word ws sentence
/ word
word
= [a-z]*
ws
= " "
可在以下网址下载:。gramar也可以粘贴到
如果我将ws规则更改为允许空白或任意空格:
ws
= " "* // add an asterisk to allow " ", " ", " ", ...
解析失败,引发最大调用堆栈异常。(如果使用JSFIDLE,您会在浏览器工具中看到异常。异常也出现在node.js环境中,因此它肯定与pegjs相关)
此ws规则中的*有什么问题?使用
+
而不是*
(对于单词也使用)
*
可以匹配空字符串<代码>+
至少需要一个实例