mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 01:38:36 +08:00
Remove the classify function in the parser. This could make Jedi a tiny bit faster.
This commit is contained in:
@@ -115,9 +115,16 @@ class PgenParser(object):
|
|||||||
return self.rootnode
|
return self.rootnode
|
||||||
|
|
||||||
def addtoken(self, type, value, prefix, start_pos):
|
def addtoken(self, type, value, prefix, start_pos):
|
||||||
"""Add a token; return True iff this is the end of the program."""
|
"""Add a token; return True if this is the end of the program."""
|
||||||
# Map from token to label
|
# Map from token to label
|
||||||
ilabel = self.classify(type, value, start_pos)
|
if type == tokenize.NAME:
|
||||||
|
# Check for reserved words (keywords)
|
||||||
|
try:
|
||||||
|
ilabel = self.grammar.keywords[value]
|
||||||
|
except KeyError:
|
||||||
|
ilabel = self.grammar.tokens[type]
|
||||||
|
else:
|
||||||
|
ilabel = self.grammar.tokens[type]
|
||||||
|
|
||||||
# Loop until the token is shifted; may raise exceptions
|
# Loop until the token is shifted; may raise exceptions
|
||||||
while True:
|
while True:
|
||||||
@@ -163,16 +170,6 @@ class PgenParser(object):
|
|||||||
value, start_pos, prefix, self.addtoken)
|
value, start_pos, prefix, self.addtoken)
|
||||||
break
|
break
|
||||||
|
|
||||||
def classify(self, type, value, start_pos):
|
|
||||||
"""Turn a token into a label. (Internal)"""
|
|
||||||
if type == tokenize.NAME:
|
|
||||||
# Check for reserved words (keywords)
|
|
||||||
try:
|
|
||||||
return self.grammar.keywords[value]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
return self.grammar.tokens[type]
|
|
||||||
|
|
||||||
def shift(self, type, value, newstate, prefix, start_pos):
|
def shift(self, type, value, newstate, prefix, start_pos):
|
||||||
"""Shift a token. (Internal)"""
|
"""Shift a token. (Internal)"""
|
||||||
dfa, state, node = self.stack[-1]
|
dfa, state, node = self.stack[-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user