我正在使用waxeye解析器生成器为某些语法生成python解析器。不幸的是,当我尝试解析任何文本时,我几乎每次都会遇到同样的错误:
parse error: failed to match 'whitespace' at line=1, col=10, pos=10
或
parse error: failed to match 'ws' at line=1, col=10, pos=10
我认为我的语法定义存在问题,但我几乎尝试了各种方法,但仍然是错误的。
这是python代码:
import waxeye
import robLang
text = ' block is red '
def analyze(input):
ast = robLang.Parser().parse(input)
if isinstance(ast, waxeye.ParseError):
return ast
else:
return sum(ast.children[0])
result = analyze(text)
print result
和语法定义:
statement <- ws thing ws isWord wse adjective ws ?(adjectives)
thing <- objectType ?(ws name)
objectType <- 'pyramid'|'ball'|'block'|'boot'|'leg'|'degree'
name <- [a-zA-Z] *[a-zA-Z0-9_-]
isWord <- 'is'
adjectives <- *(adjective ws)
colour <- 'red'|'green'|'blue'|'black'|'white'|'yellow'|'orange'|'purple'
|'cyan'|'magenta'
size <- 'small'|'big'
moralDirection <- 'good'|'bad'
adjective <- colour|size|moralDirection
number <- +[0-9] ?('.' +[0-9]) ws
ws <: *[ \t\n\r]
答案 0 :(得分:-1)
statement <- ws thing ws isWord wse adjective ws ?(adjectives)
将wse
更改为ws
。