Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 11th, 2008, 8:50 AM   #1
ptmcg
Newbie
 
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0 ptmcg is on a distinguished road
Lightbulb 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.
ptmcg is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Convert Python script to C++ code clanotheduck Python 17 Sep 25th, 2005 8:55 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 7:39 AM
Hybrid python shell Arevos Existing Project Development 0 Sep 22nd, 2005 4:37 PM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:38 PM.

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