pyparser を使用して、S-Expression 言語用の非常に単純なパーサーを作成しようとしています。私は非常に小さな文法を書きました。これが私のコードです:
from pyparsing import *
alphaword = Word(alphas)
integer = Word(nums)
sexp = Forward()
LPAREN = Suppress("(")
RPAREN = Suppress(")")
sexp << ( alphaword | integer | ( LPAREN + ZeroOrMore(sexp) + RPAREN)
tests = """\
red
100
( red 100 blue )
( green ( ( 1 2 ) mauve ) plaid () ) """.splitlines()
for t in tests:
print t
print sexp.parseString(t)
print
このコードの例を見ると、すべて問題ないように見えますが、実行すると、この行の構文エラーが発生します
tests = """\ ^
わかりません。どんな助けにも感謝します