views:

147

answers:

2

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  A: 

"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', '!']
Alex Martelli
+1  A: 

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

Paul McGuire
are you going to move your pyparsing support over here, Paul? Rather than the secret spot on your wiki?
Gregg Lind
where there's a cop beatin' up a kid, I'll be there...
Paul McGuire