mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 21:04:29 +08:00
Better documentation for leafs/nodes.
This commit is contained in:
2
docs/_themes/flask/layout.html
vendored
2
docs/_themes/flask/layout.html
vendored
@@ -7,7 +7,7 @@
|
|||||||
<link media="only screen and (max-device-width: 480px)" href="{{
|
<link media="only screen and (max-device-width: 480px)" href="{{
|
||||||
pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" />
|
pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" />
|
||||||
<a href="https://github.com/davidhalter/jedi">
|
<a href="https://github.com/davidhalter/jedi">
|
||||||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub">
|
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me">
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{%- block relbar2 %}{% endblock %}
|
{%- block relbar2 %}{% endblock %}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
.. include:: ../global.rst
|
||||||
|
|
||||||
.. _parser-tree:
|
.. _parser-tree:
|
||||||
|
|
||||||
Parser Tree
|
Parser Tree
|
||||||
@@ -5,19 +7,33 @@ Parser Tree
|
|||||||
|
|
||||||
The parser tree is returned by calling :py:meth:`parso.Grammar.parse`.
|
The parser tree is returned by calling :py:meth:`parso.Grammar.parse`.
|
||||||
|
|
||||||
Parser Tree Base Class
|
.. note:: Note that parso positions are always 1 based for lines and zero
|
||||||
----------------------
|
based for columns. This means the first position in a file is (1, 0).
|
||||||
|
|
||||||
|
Parser Tree Base Classes
|
||||||
|
------------------------
|
||||||
|
|
||||||
All nodes and leaves have these methods/properties:
|
All nodes and leaves have these methods/properties:
|
||||||
|
|
||||||
|
.. autoclass:: parso.tree.BaseNode
|
||||||
|
:show-inheritance:
|
||||||
|
:members:
|
||||||
|
|
||||||
|
.. autoclass:: parso.tree.Leaf
|
||||||
|
:show-inheritance:
|
||||||
|
:members:
|
||||||
|
|
||||||
.. autoclass:: parso.tree.NodeOrLeaf
|
.. autoclass:: parso.tree.NodeOrLeaf
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
|
|
||||||
Python Parser Tree
|
Python Parser Tree
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
.. currentmodule:: parso.python.tree
|
||||||
|
|
||||||
.. automodule:: parso.python.tree
|
.. automodule:: parso.python.tree
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ class NodeOrLeaf(object):
|
|||||||
The base class for nodes and leaves.
|
The base class for nodes and leaves.
|
||||||
"""
|
"""
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
type = None
|
||||||
|
'''
|
||||||
|
The type is a string that typically matches the types of the grammar file.
|
||||||
|
'''
|
||||||
|
|
||||||
def get_root_node(self):
|
def get_root_node(self):
|
||||||
"""
|
"""
|
||||||
@@ -156,13 +160,27 @@ class NodeOrLeaf(object):
|
|||||||
|
|
||||||
|
|
||||||
class Leaf(NodeOrLeaf):
|
class Leaf(NodeOrLeaf):
|
||||||
|
'''
|
||||||
|
Leafs are basically tokens with a better API. Leafs exactly know where they
|
||||||
|
were defined and what text preceeds them.
|
||||||
|
'''
|
||||||
__slots__ = ('value', 'parent', 'line', 'column', 'prefix')
|
__slots__ = ('value', 'parent', 'line', 'column', 'prefix')
|
||||||
|
|
||||||
def __init__(self, value, start_pos, prefix=''):
|
def __init__(self, value, start_pos, prefix=''):
|
||||||
self.value = value
|
self.value = value
|
||||||
|
'''
|
||||||
|
(:py:func:`str`) The value of the current token.
|
||||||
|
'''
|
||||||
self.start_pos = start_pos
|
self.start_pos = start_pos
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
'''
|
||||||
|
(:py:func:`str`) Typically a mixture of whitespace and comments. Stuff
|
||||||
|
that is syntactically irrelevant for the syntax tree.
|
||||||
|
'''
|
||||||
self.parent = None
|
self.parent = None
|
||||||
|
'''
|
||||||
|
The parent :class:`BaseNode` of this leaf.
|
||||||
|
'''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def start_pos(self):
|
def start_pos(self):
|
||||||
@@ -220,9 +238,7 @@ class TypedLeaf(Leaf):
|
|||||||
class BaseNode(NodeOrLeaf):
|
class BaseNode(NodeOrLeaf):
|
||||||
"""
|
"""
|
||||||
The super class for all nodes.
|
The super class for all nodes.
|
||||||
|
A node has children, a type and possibly a parent node.
|
||||||
If you create custom nodes, you will probably want to inherit from this
|
|
||||||
``BaseNode``.
|
|
||||||
"""
|
"""
|
||||||
__slots__ = ('children', 'parent')
|
__slots__ = ('children', 'parent')
|
||||||
type = None
|
type = None
|
||||||
@@ -231,7 +247,14 @@ class BaseNode(NodeOrLeaf):
|
|||||||
for c in children:
|
for c in children:
|
||||||
c.parent = self
|
c.parent = self
|
||||||
self.children = children
|
self.children = children
|
||||||
|
"""
|
||||||
|
A list of :class:`NodeOrLeaf` child nodes.
|
||||||
|
"""
|
||||||
self.parent = None
|
self.parent = None
|
||||||
|
'''
|
||||||
|
The parent :class:`BaseNode` of this leaf.
|
||||||
|
None if this is the root node.
|
||||||
|
'''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def start_pos(self):
|
def start_pos(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user