问题描述
我在Google App Engine文档中看到 Antlr3被用作解析第三方库。
但是从我所知道的Pyparsing看起来更容易使用,我只是旨在解析一些简单的语法。
是否有替代方案?我可以在App Engine上使用pyparsing工作吗?
Just do it! - )获取pyparsing.py,例如从,并将其放入您的应用引擎应用的目录;现在你可以在你的应用程序代码中使用 import pyparsing
并使用它。 例如,调整greeting.py从:
from pyparsing import Word,alphas
greet = Word(alphas)+,+ Word(alphas)+! #< - 此处定义的语法
hello =Hello,World!
printContent-type:text / plain \\\
print hello, - >,greet.parseString(hello)
在处理程序中添加到您的app.yaml:
两行:
- url:/ parshello
script:greeting.py
启动您的应用程序,访问 http:// localhost:8083 / parshello
(或您在其上运行的任何端口;-),以及你会在浏览器中看到纯文本输出:
Hello,World! - > ['Hello',',','World','!']
I saw on the Google App Engine documentation that http://www.antlr.org/ Antlr3 is used as the parsing third party library.
But from what I know Pyparsing seems to be the easier to use and I am only aiming to parse some simple syntax.
Is there an alternative? Can I get pyparsing working on the App Engine?
"Just do it"!-) Get pyparsing.py, e.g. from here, and put it in your app engine app's directory; now you can just import pyparsing
in your app code and use it.
For example, tweak the greeting.py from here to be:
from pyparsing import Word, alphas
greet = Word( alphas ) + "," + Word( alphas ) + "!" # <-- grammar defined here
hello = "Hello, World!"
print "Content-type: text/plain\n"
print hello, "->", greet.parseString( hello )
add to your app.yaml right under handlers:
the two lines:
- url: /parshello
script: greeting.py
start your app, visit http://localhost:8083/parshello
(or whatever port you're running on;-), and you'll see in your browser the plain text output:
Hello, World! -> ['Hello', ',', 'World', '!']
这篇关于我如何在Google App Engine上设置PyParsing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!