mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
A parso docstring.
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
"""
|
||||
parso is a Python parser. It's really easy to use and supports multiple Python
|
||||
versions, file caching, round-trips and other stuff:
|
||||
|
||||
>>> from parso import load_python_grammar
|
||||
>>> grammar = load_python_grammar(version='2.7')
|
||||
>>> module = grammar.parse('hello + 1')
|
||||
>>> stmt = module.children[0]
|
||||
>>> stmt
|
||||
PythonNode(simple_stmt, [PythonNode(arith_expr, [...]), <Newline: ''>])
|
||||
>>> stmt.get_code()
|
||||
'hello + 1'
|
||||
>>> name = stmt.children[0].children[0]
|
||||
>>> name
|
||||
<Name: hello@1,0>
|
||||
>>> name.end_pos
|
||||
(1, 5)
|
||||
"""
|
||||
|
||||
from parso.parser import ParserSyntaxError
|
||||
from parso.grammar import create_grammar, load_python_grammar
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ def create_grammar(text, tokenizer=generate_tokens, parser=BaseParser):
|
||||
"""
|
||||
:param text: A BNF representation of your grammar.
|
||||
"""
|
||||
return grammar.Grammar(text, tokenizer=tokenizer, parser=parser)
|
||||
return Grammar(text, tokenizer=tokenizer, parser=parser)
|
||||
|
||||
|
||||
def load_python_grammar(version=None):
|
||||
|
||||
@@ -208,7 +208,7 @@ class Leaf(NodeOrLeaf):
|
||||
|
||||
@utf8_repr
|
||||
def __repr__(self):
|
||||
return "<%s: %s start=%s>" % (type(self).__name__, self.value, self.start_pos)
|
||||
return "<%s: %s>" % (type(self).__name__, self.value)
|
||||
|
||||
|
||||
class BaseNode(NodeOrLeaf):
|
||||
|
||||
Reference in New Issue
Block a user