1

ワックスアイ パーサー ジェネレーターを使用して、文法用の 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]
4

1 に答える 1

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

に変更wsewsます。

于 2016-05-04T14:16:05.753 に答える