使用waxeye生成解析器解析空格

时间:2013-05-26 14:55:14

标签: python parsing python-2.7 parser-generator waxeye

我正在使用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]

1 个答案:

答案 0 :(得分:-1)

statement <- ws thing ws isWord wse adjective ws ?(adjectives)

wse更改为ws