| 1 | |
| 2 | pyparsing can be found in the trunk from revision 684 onwards. |
| 3 | |
| 4 | pyparsing providers a simple way of creating parsers for logical text patterns. |
| 5 | |
| 6 | A simple tutorial for pyparsing could be found at : http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION007600000000000000000 |
| 7 | |
| 8 | Documentation for pyparsing is located at : [http://crpppc19.epfl.ch/doc/python-pyparsing/HowToUsePyparsing.html] |
| 9 | |
| 10 | |
| 11 | Example usage is shown below. |
| 12 | |
| 13 | {{{ |
| 14 | from pyparsing import delimitedList,Word,alphanums,ParseException,Group |
| 15 | from pyparsing import Suppress,nums |
| 16 | |
| 17 | resource = delimitedList(Word(alphanums+"_"),'/') |
| 18 | |
| 19 | phone = Word(nums) # doesnot accept country code yet |
| 20 | |
| 21 | address = (Suppress("eden.")+resource) | phone | Word(alphanums+"_ . + @ ") |
| 22 | |
| 23 | addresses = delimitedList(Group(address)) |
| 24 | |
| 25 | string = "eden.pr_person/1/asd,eden.la/1/1,9935648569" |
| 26 | add = addresses.parseString(string) |
| 27 | print add |
| 28 | |
| 29 | ------------ |
| 30 | ==> Result |
| 31 | |
| 32 | [['pr_person', '1', 'asd'], ['la', '1', '1'], ['9935648569']] |
| 33 | |
| 34 | }}} |