mirror of
https://github.com/davidhalter/parso.git
synced 2026-08-12 19:11:34 +08:00
Use nonterminals instead of numbers if possible
This commit is contained in:
+1
-2
@@ -44,10 +44,9 @@ class BaseParser(object):
|
|||||||
self._error_recovery = error_recovery
|
self._error_recovery = error_recovery
|
||||||
|
|
||||||
def parse(self, tokens):
|
def parse(self, tokens):
|
||||||
start_number = self._pgen_grammar.nonterminal2number[self._start_nonterminal]
|
|
||||||
self.pgen_parser = PgenParser(
|
self.pgen_parser = PgenParser(
|
||||||
self._pgen_grammar, self.convert_node, self.convert_leaf,
|
self._pgen_grammar, self.convert_node, self.convert_leaf,
|
||||||
self.error_recovery, start_number
|
self.error_recovery, self._start_nonterminal
|
||||||
)
|
)
|
||||||
|
|
||||||
node = self.pgen_parser.parse(tokens)
|
node = self.pgen_parser.parse(tokens)
|
||||||
|
|||||||
@@ -211,7 +211,3 @@ class Grammar(object):
|
|||||||
(nonterminal, terminal, nonterminal_or_string, inverse[terminal]))
|
(nonterminal, terminal, nonterminal_or_string, inverse[terminal]))
|
||||||
inverse[terminal] = nonterminal_or_string
|
inverse[terminal] = nonterminal_or_string
|
||||||
self._first_terminals[nonterminal] = totalset
|
self._first_terminals[nonterminal] = totalset
|
||||||
|
|
||||||
@property
|
|
||||||
def start(self):
|
|
||||||
return self.nonterminal2number[self.start_nonterminal]
|
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ class PgenParser(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, grammar, convert_node, convert_leaf, error_recovery, start):
|
def __init__(self, grammar, convert_node, convert_leaf, error_recovery,
|
||||||
|
start_nonterminal):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
The grammar argument is a grammar.Grammar instance; see the
|
The grammar argument is a grammar.Grammar instance; see the
|
||||||
@@ -144,7 +145,6 @@ class PgenParser(object):
|
|||||||
self.convert_node = convert_node
|
self.convert_node = convert_node
|
||||||
self.convert_leaf = convert_leaf
|
self.convert_leaf = convert_leaf
|
||||||
|
|
||||||
start_nonterminal = grammar.number2nonterminal[start]
|
|
||||||
self.stack = Stack([StackNode(grammar._nonterminal_to_dfas[start_nonterminal][0])])
|
self.stack = Stack([StackNode(grammar._nonterminal_to_dfas[start_nonterminal][0])])
|
||||||
self.rootnode = None
|
self.rootnode = None
|
||||||
self.error_recovery = error_recovery
|
self.error_recovery = error_recovery
|
||||||
|
|||||||
Reference in New Issue
Block a user