Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Show Off Your Open Source Projects (http://www.programmingforums.org/forum52.html)
-   -   pyparsing - Python parser library (http://www.programmingforums.org/showthread.php?t=15158)

ptmcg Feb 11th, 2008 8:50 AM

pyparsing - Python parser library
 
Pyparsing is a Python module for creating parsers. Here is a parser for "Hello, World!", or any string of the form "<greeting>, <person>!":

:

greeting = Word(alphas) + "," + Word(alphas) + "!"
print greeting.parseString("Hello, World!")
print greeting.parseString("Yo, Adrian!")


prints:
:

['Hello', ',', 'World', '!']
['Yo', ',', 'Adrian', '!']


Pyparsing can be used to parse text, scan text, and transform text. The Wiki (and the source and docs distributions) contain a number of examples, and epydoc class documentation. UML class diagrams are also included. I gave two presentations on pyparsing at PyCon'06, and there are links to online versions at the Wiki documentation page. Google for "pyparsing" to find more online material.

Here is a short list of some of the examples provided:
- "Hello, World!" (English, Korean, Greek, and Spanish)
- chemical formulas
- configuration file parser
- web page URL extractor
- 5-function arithmetic expression parser
- subset of CORBA IDL
- chess portable game notation
- simple SQL parser
- search query parser
- EBNF parser/compiler
- Python value string parser (lists, dicts, tuples, with nesting) (safe alternative to eval)
- HTML tag stripper
- S-expression parser
- macro substitution preprocessor

You can find what other uses pyparsing has been put to at the Wiki Who's Using Pyparsing page.

I just posted the latest version update to SourceForge, and you can find out more at the pyparsing Wiki: http://pyparsing.wikispaces.com.


All times are GMT -5. The time now is 3:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC