mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-30 08:04:40 +08:00
Work with token types whenever possible
This commit is contained in:
@@ -41,15 +41,6 @@ class Grammar(object):
|
||||
accesses the instance variables directly. The class here does not
|
||||
provide initialization of the tables; several subclasses exist to
|
||||
do this (see the conv and pgen modules).
|
||||
|
||||
The instance variables are as follows:
|
||||
|
||||
start -- the number of the grammar's start nonterminal.
|
||||
|
||||
keywords -- a dict mapping keyword strings to arc labels.
|
||||
|
||||
tokens -- a dict mapping token numbers to arc labels.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, bnf_grammar, start_nonterminal, rule_to_dfas, token_namespace):
|
||||
@@ -57,7 +48,6 @@ class Grammar(object):
|
||||
self._nonterminal_to_dfas = rule_to_dfas
|
||||
|
||||
self.reserved_syntax_strings = {}
|
||||
self.tokens = {}
|
||||
self.start_nonterminal = start_nonterminal
|
||||
|
||||
self._make_grammar()
|
||||
@@ -94,7 +84,6 @@ class Grammar(object):
|
||||
|
||||
# A named token (e.g. NAME, NUMBER, STRING)
|
||||
token_type = getattr(self._token_namespace, label, None)
|
||||
self.tokens[token_type] = token_type
|
||||
return token_type
|
||||
else:
|
||||
# Either a keyword or an operator
|
||||
|
||||
@@ -74,10 +74,7 @@ def token_to_ilabel(grammar, type_, value):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return grammar.tokens[type_]
|
||||
except KeyError:
|
||||
return None
|
||||
return type_
|
||||
|
||||
|
||||
class PgenParser(object):
|
||||
|
||||
Reference in New Issue
Block a user