1
我正在使用waxeye解析器生成器爲某些語法生成python解析器。不幸的是,當我嘗試解析任何文本我幾乎每次都得到同樣的錯誤:用waxeye生成解析器解析空格
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]