How do I get PyParsing set up on the Google App Engine?

天涯浪子 提交于 2020-01-01 19:58:06

问题


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?


回答1:


"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', '!']



回答2:


Pyparsing's runtime footprint is intentionally small for just this purpose. It is a single source file, pyparsing.py, so just drop it in amongst your own source files and parse away!

-- Paul



来源:https://stackoverflow.com/questions/1341137/how-do-i-get-pyparsing-set-up-on-the-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!