Python 使用waxeye生成的解析器解析空白

Python 使用waxeye生成的解析器解析空白,python,parsing,python-2.7,parser-generator,waxeye,Python,Parsing,Python 2.7,Parser Generator,Waxeye,我正在使用waxeye解析器生成器为一些语法生成python解析器。不幸的是,当我尝试解析任何文本时,几乎每次都会遇到相同的错误: parse error: failed to match 'whitespace' at line=1, col=10, pos=10 或 我想这是我对语法的定义有问题,但我尝试了几乎所有我能弥补的方法,但仍然是错误的 下面是python代码: import waxeye import robLang text = ' block is red ' def a

我正在使用waxeye解析器生成器为一些语法生成python解析器。不幸的是,当我尝试解析任何文本时,几乎每次都会遇到相同的错误:

parse error: failed to match 'whitespace' 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]
语句
语句
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]
statement <- ws thing ws isWord wse adjective ws ?(adjectives)