mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-18 02:16:03 +08:00
addtoken -> add_token.
This commit is contained in:
@@ -62,7 +62,7 @@ class PgenParser(object):
|
|||||||
p = Parser(grammar, [converter]) # create instance
|
p = Parser(grammar, [converter]) # create instance
|
||||||
p.setup([start]) # prepare for parsing
|
p.setup([start]) # prepare for parsing
|
||||||
<for each input token>:
|
<for each input token>:
|
||||||
if p.addtoken(...): # parse a token
|
if p.add_token(...): # parse a token
|
||||||
break
|
break
|
||||||
root = p.rootnode # root of abstract syntax tree
|
root = p.rootnode # root of abstract syntax tree
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class PgenParser(object):
|
|||||||
See driver.py for how to get input tokens by tokenizing a file or
|
See driver.py for how to get input tokens by tokenizing a file or
|
||||||
string.
|
string.
|
||||||
|
|
||||||
Parsing is complete when addtoken() returns True; the root of the
|
Parsing is complete when add_token() returns True; the root of the
|
||||||
abstract syntax tree can then be retrieved from the rootnode
|
abstract syntax tree can then be retrieved from the rootnode
|
||||||
instance variable. When a syntax error occurs, error_recovery()
|
instance variable. When a syntax error occurs, error_recovery()
|
||||||
is called. There is no error recovery; the parser cannot be used
|
is called. There is no error recovery; the parser cannot be used
|
||||||
@@ -125,7 +125,7 @@ class PgenParser(object):
|
|||||||
|
|
||||||
def parse(self, tokens):
|
def parse(self, tokens):
|
||||||
for type_, value, start_pos, prefix in tokens:
|
for type_, value, start_pos, prefix in tokens:
|
||||||
if self.addtoken(type_, value, start_pos, prefix):
|
if self.add_token(type_, value, start_pos, prefix):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# We never broke out -- EOF is too soon -- Unfinished statement.
|
# We never broke out -- EOF is too soon -- Unfinished statement.
|
||||||
@@ -135,7 +135,7 @@ class PgenParser(object):
|
|||||||
raise InternalParseError("incomplete input", type_, value, start_pos)
|
raise InternalParseError("incomplete input", type_, value, start_pos)
|
||||||
return self.rootnode
|
return self.rootnode
|
||||||
|
|
||||||
def addtoken(self, type_, value, start_pos, prefix):
|
def add_token(self, type_, value, start_pos, prefix):
|
||||||
"""Add a token; return True if this is the end of the program."""
|
"""Add a token; return True if this is the end of the program."""
|
||||||
ilabel = token_to_ilabel(self.grammar, type_, value)
|
ilabel = token_to_ilabel(self.grammar, type_, value)
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ class PgenParser(object):
|
|||||||
raise InternalParseError("too much input", type_, value, start_pos)
|
raise InternalParseError("too much input", type_, value, start_pos)
|
||||||
else:
|
else:
|
||||||
self.error_recovery(self.grammar, self.stack, arcs, type_,
|
self.error_recovery(self.grammar, self.stack, arcs, type_,
|
||||||
value, start_pos, prefix, self.addtoken)
|
value, start_pos, prefix, self.add_token)
|
||||||
break
|
break
|
||||||
|
|
||||||
def _shift(self, type_, value, newstate, prefix, start_pos):
|
def _shift(self, type_, value, newstate, prefix, start_pos):
|
||||||
|
|||||||
Reference in New Issue
Block a user