How do I get PyParsing set up on the Google App En

2019-04-15 06:14发布

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?

2条回答
Summer. ? 凉城
2楼-- · 2019-04-15 06:41

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

查看更多
欢心
3楼-- · 2019-04-15 06:56

"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', '!']
查看更多
登录 后发表回答