You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.3 KiB

4 years ago
  1. ###################################################################
  2. parso - A Python Parser
  3. ###################################################################
  4. .. image:: https://secure.travis-ci.org/davidhalter/parso.png?branch=master
  5. :target: http://travis-ci.org/davidhalter/parso
  6. :alt: Travis-CI build status
  7. .. image:: https://coveralls.io/repos/davidhalter/parso/badge.png?branch=master
  8. :target: https://coveralls.io/r/davidhalter/parso
  9. :alt: Coverage Status
  10. .. image:: https://raw.githubusercontent.com/davidhalter/parso/master/docs/_static/logo_characters.png
  11. Parso is a Python parser that supports error recovery and round-trip parsing
  12. for different Python versions (in multiple Python versions). Parso is also able
  13. to list multiple syntax errors in your python file.
  14. Parso has been battle-tested by jedi_. It was pulled out of jedi to be useful
  15. for other projects as well.
  16. Parso consists of a small API to parse Python and analyse the syntax tree.
  17. A simple example:
  18. .. code-block:: python
  19. >>> import parso
  20. >>> module = parso.parse('hello + 1', version="3.6")
  21. >>> expr = module.children[0]
  22. >>> expr
  23. PythonNode(arith_expr, [<Name: hello@1,0>, <Operator: +>, <Number: 1>])
  24. >>> print(expr.get_code())
  25. hello + 1
  26. >>> name = expr.children[0]
  27. >>> name
  28. <Name: hello@1,0>
  29. >>> name.end_pos
  30. (1, 5)
  31. >>> expr.end_pos
  32. (1, 9)
  33. To list multiple issues:
  34. .. code-block:: python
  35. >>> grammar = parso.load_grammar()
  36. >>> module = grammar.parse('foo +\nbar\ncontinue')
  37. >>> error1, error2 = grammar.iter_errors(module)
  38. >>> error1.message
  39. 'SyntaxError: invalid syntax'
  40. >>> error2.message
  41. "SyntaxError: 'continue' not properly in loop"
  42. Resources
  43. =========
  44. - `Testing <http://parso.readthedocs.io/en/latest/docs/development.html#testing>`_
  45. - `PyPI <https://pypi.python.org/pypi/parso>`_
  46. - `Docs <https://parso.readthedocs.org/en/latest/>`_
  47. - Uses `semantic versioning <http://semver.org/>`_
  48. Installation
  49. ============
  50. pip install parso
  51. Future
  52. ======
  53. - There will be better support for refactoring and comments. Stay tuned.
  54. - There's a WIP PEP8 validator. It's however not in a good shape, yet.
  55. Known Issues
  56. ============
  57. - `async`/`await` are already used as keywords in Python3.6.
  58. - `from __future__ import print_function` is not ignored.
  59. Acknowledgements
  60. ================
  61. - Guido van Rossum (@gvanrossum) for creating the parser generator pgen2
  62. (originally used in lib2to3).
  63. - `Salome Schneider <https://www.crepes-schnaegg.ch/cr%C3%AApes-schn%C3%A4gg/kunst-f%C3%BCrs-cr%C3%AApes-mobil/>`_
  64. for the extremely awesome parso logo.
  65. .. _jedi: https://github.com/davidhalter/jedi
  66. .. :changelog:
  67. Changelog
  68. ---------
  69. 0.3.1 (2018-07-09)
  70. +++++++++++++++++++
  71. - Bugfixes in the diff parser and keyword-only arguments
  72. 0.3.0 (2018-06-30)
  73. +++++++++++++++++++
  74. - Rewrote the pgen2 parser generator.
  75. 0.2.1 (2018-05-21)
  76. +++++++++++++++++++
  77. - A bugfix for the diff parser.
  78. - Grammar files can now be loaded from a specific path.
  79. 0.2.0 (2018-04-15)
  80. +++++++++++++++++++
  81. - f-strings are now parsed as a part of the normal Python grammar. This makes
  82. it way easier to deal with them.
  83. 0.1.1 (2017-11-05)
  84. +++++++++++++++++++
  85. - Fixed a few bugs in the caching layer
  86. - Added support for Python 3.7
  87. 0.1.0 (2017-09-04)
  88. +++++++++++++++++++
  89. - Pulling the library out of Jedi. Some APIs will definitely change.