forked from VimPlug/jedi
Small optimizations to make parsing faster.
This commit is contained in:
@@ -178,8 +178,13 @@ class Parser(object):
|
|||||||
def pop(self):
|
def pop(self):
|
||||||
"""Pop a nonterminal. (Internal)"""
|
"""Pop a nonterminal. (Internal)"""
|
||||||
popdfa, popstate, popnode = self.stack.pop()
|
popdfa, popstate, popnode = self.stack.pop()
|
||||||
|
children = popnode[3]
|
||||||
|
if len(children) != 1 or popnode[0] in (self.grammar.symbol2number['expr_stmt'],
|
||||||
|
self.grammar.symbol2number['file_input']):
|
||||||
newnode = self.convert(self.grammar, popnode)
|
newnode = self.convert(self.grammar, popnode)
|
||||||
if newnode is not None:
|
else:
|
||||||
|
newnode = children[0]
|
||||||
|
|
||||||
if self.stack:
|
if self.stack:
|
||||||
dfa, state, node = self.stack[-1]
|
dfa, state, node = self.stack[-1]
|
||||||
node[-1].append(newnode)
|
node[-1].append(newnode)
|
||||||
|
|||||||
@@ -57,15 +57,7 @@ def type_repr(type_num):
|
|||||||
return _type_reprs.setdefault(type_num, type_num)
|
return _type_reprs.setdefault(type_num, type_num)
|
||||||
|
|
||||||
|
|
||||||
def convert(grammar, raw_node):
|
def gen_ast_mapping():
|
||||||
"""
|
|
||||||
Convert raw node information to a Node or Leaf instance.
|
|
||||||
|
|
||||||
This is passed to the parser driver which calls it whenever a reduction of a
|
|
||||||
grammar rule produces a new complete node, so that the tree is build
|
|
||||||
strictly bottom-up.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
_ast_mapping = {
|
_ast_mapping = {
|
||||||
'expr_stmt': pr.ExprStmt,
|
'expr_stmt': pr.ExprStmt,
|
||||||
@@ -91,9 +83,23 @@ def convert(grammar, raw_node):
|
|||||||
'try_stmt': pr.TryStmt,
|
'try_stmt': pr.TryStmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global ast_mapping, pr
|
||||||
ast_mapping = dict((getattr(python_symbols, k), v) for k, v in _ast_mapping.items())
|
ast_mapping = dict((getattr(python_symbols, k), v) for k, v in _ast_mapping.items())
|
||||||
|
|
||||||
|
|
||||||
|
def convert(grammar, raw_node):
|
||||||
|
"""
|
||||||
|
Convert raw node information to a Node or Leaf instance.
|
||||||
|
|
||||||
|
This is passed to the parser driver which calls it whenever a reduction of a
|
||||||
|
grammar rule produces a new complete node, so that the tree is build
|
||||||
|
strictly bottom-up.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
ast_mapping
|
||||||
|
except NameError:
|
||||||
|
gen_ast_mapping()
|
||||||
|
|
||||||
#import pdb; pdb.set_trace()
|
#import pdb; pdb.set_trace()
|
||||||
type, value, context, children = raw_node
|
type, value, context, children = raw_node
|
||||||
if type in grammar.number2symbol:
|
if type in grammar.number2symbol:
|
||||||
|
|||||||
Reference in New Issue
Block a user