mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 13:45:01 +08:00
Move to python 3.6 intersphinx.
This commit is contained in:
@@ -274,7 +274,7 @@ autodoc_default_flags = []
|
|||||||
# -- Options for intersphinx module --------------------------------------------
|
# -- Options for intersphinx module --------------------------------------------
|
||||||
|
|
||||||
intersphinx_mapping = {
|
intersphinx_mapping = {
|
||||||
'http://docs.python.org/': None,
|
'http://docs.python.org/': ('https://docs.python.org/3.6', None),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,7 @@
|
|||||||
Parser Tree
|
Parser Tree
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Usage
|
The parser tree is returned by calling :py:meth:`parso.Grammar.parse`.
|
||||||
-----
|
|
||||||
|
|
||||||
.. automodule:: parso.python
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
|
|
||||||
|
|
||||||
Parser Tree Base Class
|
Parser Tree Base Class
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ __version__ = '0.0.5'
|
|||||||
def parse(code=None, **kwargs):
|
def parse(code=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
A utility function to avoid loading grammars.
|
A utility function to avoid loading grammars.
|
||||||
Params are documented in :py:meth:`parso.Grammar.parse`
|
Params are documented in :py:meth:`parso.Grammar.parse`.
|
||||||
|
|
||||||
:param string version: The version used by :py:func:`parso.Grammar.load_grammar`.
|
:param str version: The version used by :py:func:`parso.load_grammar`.
|
||||||
"""
|
"""
|
||||||
version = kwargs.pop('version', None)
|
version = kwargs.pop('version', None)
|
||||||
grammar = load_grammar(version=version)
|
grammar = load_grammar(version=version)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Grammar(object):
|
|||||||
|
|
||||||
:param str code: A unicode or bytes string. When it's not possible to
|
:param str code: A unicode or bytes string. When it's not possible to
|
||||||
decode bytes to a string, returns a
|
decode bytes to a string, returns a
|
||||||
:py:class:`exceptions.UnicodeDecodeError`.
|
:py:class:`UnicodeDecodeError`.
|
||||||
:param bool error_recovery: If enabled, any code will be returned. If
|
:param bool error_recovery: If enabled, any code will be returned. If
|
||||||
it is invalid, it will be returned as an error node. If disabled,
|
it is invalid, it will be returned as an error node. If disabled,
|
||||||
you will get a ParseError when encountering syntax errors in your
|
you will get a ParseError when encountering syntax errors in your
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
"""
|
"""
|
||||||
If you know what an syntax tree is, you'll see that this module is pretty much
|
This is the syntax tree for Python syntaxes (2 & 3). The classes represent
|
||||||
that. The classes represent syntax elements like functions and imports.
|
syntax elements like functions and imports.
|
||||||
|
|
||||||
This is the "business logic" part of the parser. There's a lot of logic here
|
All of the nodes can be traced back to the `Python grammar file
|
||||||
that makes it easier for Jedi (and other libraries) to deal with a Python syntax
|
<https://docs.python.org/3/reference/grammar.html>`_. If you want to know how
|
||||||
tree.
|
a tree is structured, just analyse that file (for each Python version it's a
|
||||||
|
bit different).
|
||||||
|
|
||||||
By using `get_code` on a module, you can get back the 1-to-1 representation of
|
There's a lot of logic here that makes it easier for Jedi (and other libraries)
|
||||||
the input given to the parser. This is important if you are using refactoring.
|
to deal with a Python syntax tree.
|
||||||
|
|
||||||
The easiest way to play with this module is to use :class:`parsing.Parser`.
|
By using :py:meth:`parso.tree.NodeOrLeaf.get_code` on a module, you can get
|
||||||
:attr:`parsing.Parser.module` holds an instance of :class:`Module`:
|
back the 1-to-1 representation of the input given to the parser. This is
|
||||||
|
important if you are using refactoring.
|
||||||
|
|
||||||
>>> from parso import parse
|
>>> from parso import parse
|
||||||
>>> parser = parse('import os')
|
>>> parser = parse('import os')
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def split_lines(string, keepends=False):
|
|||||||
Intended for Python code. In contrast to Python's :py:meth:`str.splitlines`,
|
Intended for Python code. In contrast to Python's :py:meth:`str.splitlines`,
|
||||||
looks at form feeds and other special characters as normal text. Just
|
looks at form feeds and other special characters as normal text. Just
|
||||||
splits ``\n`` and ``\r\n``.
|
splits ``\n`` and ``\r\n``.
|
||||||
Also different: Returns ``['']`` for an empty string input.
|
Also different: Returns ``[""]`` for an empty string input.
|
||||||
|
|
||||||
In Python 2.7 form feeds are used as normal characters when using
|
In Python 2.7 form feeds are used as normal characters when using
|
||||||
str.splitlines. However in Python 3 somewhere there was a decision to split
|
str.splitlines. However in Python 3 somewhere there was a decision to split
|
||||||
@@ -51,10 +51,10 @@ def split_lines(string, keepends=False):
|
|||||||
def python_bytes_to_unicode(source, encoding='utf-8', errors='strict'):
|
def python_bytes_to_unicode(source, encoding='utf-8', errors='strict'):
|
||||||
"""
|
"""
|
||||||
Checks for unicode BOMs and PEP 263 encoding declarations. Then returns a
|
Checks for unicode BOMs and PEP 263 encoding declarations. Then returns a
|
||||||
unicode object like in :py:meth:`str.decode`.
|
unicode object like in :py:meth:`bytes.decode`.
|
||||||
|
|
||||||
:param encoding: See :py:meth:`str.decode` documentation.
|
:param encoding: See :py:meth:`bytes.decode` documentation.
|
||||||
:param errors: See :py:meth:`str.decode` documentation. ``errors`` can be
|
:param errors: See :py:meth:`bytes.decode` documentation. ``errors`` can be
|
||||||
``'strict'``, ``'replace'`` or ``'ignore'``.
|
``'strict'``, ``'replace'`` or ``'ignore'``.
|
||||||
"""
|
"""
|
||||||
def detect_encoding():
|
def detect_encoding():
|
||||||
|
|||||||
Reference in New Issue
Block a user