Python:使用 Pyparser 测试数据的语法无效
使用 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
在查看此代码的示例时,似乎一切都很好,但是在运行时我收到此行的语法错误
<前><代码>测试 = """\ ^
我不明白。如果有任何帮助,我将不胜感激
Using pyparser, I am trying to create a very simple parser for the S-Expression language. I have written a very small grammar.
Here is my code:
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
While looking at examples of this code it seems that everything is fine, however when running i get a syntax error for this line
tests = """\ ^
I don't understand it. I would be grateful for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
前一行的括号未闭合。
需要更多)的
parentheses on a previous line are not closed.
Needs more )'s