README.rst 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. PyParsing -- A Python Parsing Module
  2. ====================================
  3. |Build Status|
  4. Introduction
  5. ============
  6. The pyparsing module is an alternative approach to creating and
  7. executing simple grammars, vs. the traditional lex/yacc approach, or the
  8. use of regular expressions. The pyparsing module provides a library of
  9. classes that client code uses to construct the grammar directly in
  10. Python code.
  11. *[Since first writing this description of pyparsing in late 2003, this
  12. technique for developing parsers has become more widespread, under the
  13. name Parsing Expression Grammars - PEGs. See more information on PEGs at*
  14. https://en.wikipedia.org/wiki/Parsing_expression_grammar *.]*
  15. Here is a program to parse ``"Hello, World!"`` (or any greeting of the form
  16. ``"salutation, addressee!"``):
  17. .. code:: python
  18. from pyparsing import Word, alphas
  19. greet = Word(alphas) + "," + Word(alphas) + "!"
  20. hello = "Hello, World!"
  21. print(hello, "->", greet.parseString(hello))
  22. The program outputs the following::
  23. Hello, World! -> ['Hello', ',', 'World', '!']
  24. The Python representation of the grammar is quite readable, owing to the
  25. self-explanatory class names, and the use of '+', '|' and '^' operator
  26. definitions.
  27. The parsed results returned from ``parseString()`` can be accessed as a
  28. nested list, a dictionary, or an object with named attributes.
  29. The pyparsing module handles some of the problems that are typically
  30. vexing when writing text parsers:
  31. - extra or missing whitespace (the above program will also handle ``"Hello,World!"``, ``"Hello , World !"``, etc.)
  32. - quoted strings
  33. - embedded comments
  34. The examples directory includes a simple SQL parser, simple CORBA IDL
  35. parser, a config file parser, a chemical formula parser, and a four-
  36. function algebraic notation parser, among many others.
  37. Documentation
  38. =============
  39. There are many examples in the online docstrings of the classes
  40. and methods in pyparsing. You can find them compiled into online docs
  41. at https://pyparsing-docs.readthedocs.io/en/latest/. Additional
  42. documentation resources and project info are listed in the online
  43. GitHub wiki, at https://github.com/pyparsing/pyparsing/wiki. An
  44. entire directory of examples is at
  45. https://github.com/pyparsing/pyparsing/tree/master/examples.
  46. License
  47. =======
  48. MIT License. See header of pyparsing.py
  49. History
  50. =======
  51. See CHANGES file.
  52. .. |Build Status| image:: https://travis-ci.org/pyparsing/pyparsing.svg?branch=master
  53. :target: https://travis-ci.org/pyparsing/pyparsing