forked from VimPlug/jedi
Fixed issues with the Python3.4 grammar file.
The order of symbols matters. 'file_input' needs to be the first symbol.
This commit is contained in:
@@ -23,9 +23,9 @@
|
|||||||
#diagram:rules
|
#diagram:rules
|
||||||
|
|
||||||
# Start symbols for the grammar:
|
# Start symbols for the grammar:
|
||||||
# file_input is a module or sequence of commands read from an input file;
|
# file_input is a module or sequence of commands read from an input file;
|
||||||
# single_input is a single interactive statement;
|
# single_input is a single interactive statement;
|
||||||
# eval_input is the input for the eval() and input() functions.
|
# eval_input is the input for the eval() and input() functions.
|
||||||
# NB: compound_stmt in single_input is followed by extra NEWLINE!
|
# NB: compound_stmt in single_input is followed by extra NEWLINE!
|
||||||
file_input: (NEWLINE | stmt)* ENDMARKER
|
file_input: (NEWLINE | stmt)* ENDMARKER
|
||||||
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
||||||
@@ -88,9 +88,9 @@ while_stmt: 'while' test ':' suite ['else' ':' suite]
|
|||||||
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
|
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
|
||||||
try_stmt: ('try' ':' suite
|
try_stmt: ('try' ':' suite
|
||||||
((except_clause ':' suite)+
|
((except_clause ':' suite)+
|
||||||
['else' ':' suite]
|
['else' ':' suite]
|
||||||
['finally' ':' suite] |
|
['finally' ':' suite] |
|
||||||
'finally' ':' suite))
|
'finally' ':' suite))
|
||||||
with_stmt: 'with' with_item (',' with_item)* ':' suite
|
with_stmt: 'with' with_item (',' with_item)* ':' suite
|
||||||
with_item: test ['as' expr]
|
with_item: test ['as' expr]
|
||||||
with_var: 'as' expr
|
with_var: 'as' expr
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
# file_input is a module or sequence of commands read from an input file;
|
# file_input is a module or sequence of commands read from an input file;
|
||||||
# eval_input is the input for the eval() functions.
|
# eval_input is the input for the eval() functions.
|
||||||
# NB: compound_stmt in single_input is followed by extra NEWLINE!
|
# NB: compound_stmt in single_input is followed by extra NEWLINE!
|
||||||
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
|
||||||
file_input: (NEWLINE | stmt)* ENDMARKER
|
file_input: (NEWLINE | stmt)* ENDMARKER
|
||||||
|
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
||||||
eval_input: testlist NEWLINE* ENDMARKER
|
eval_input: testlist NEWLINE* ENDMARKER
|
||||||
|
|
||||||
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
|
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ opmap_raw = """
|
|||||||
// DOUBLESLASH
|
// DOUBLESLASH
|
||||||
//= DOUBLESLASHEQUAL
|
//= DOUBLESLASHEQUAL
|
||||||
-> RARROW
|
-> RARROW
|
||||||
|
... ELLIPSIS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
opmap = {}
|
opmap = {}
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ COMMENT = 52
|
|||||||
NL = 53
|
NL = 53
|
||||||
RARROW = 54
|
RARROW = 54
|
||||||
ERRORTOKEN = 55
|
ERRORTOKEN = 55
|
||||||
N_TOKENS = 56
|
ELLIPSIS = 56
|
||||||
|
N_TOKENS = 57
|
||||||
NT_OFFSET = 256
|
NT_OFFSET = 256
|
||||||
#--end constants--
|
#--end constants--
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ There's also a pattern matching implementation here.
|
|||||||
|
|
||||||
__author__ = "Guido van Rossum <guido@python.org>"
|
__author__ = "Guido van Rossum <guido@python.org>"
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from . import pgen2
|
from . import pgen2
|
||||||
@@ -22,7 +21,7 @@ _type_reprs = {}
|
|||||||
|
|
||||||
|
|
||||||
# The grammar file
|
# The grammar file
|
||||||
_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "grammar.txt")
|
_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "grammar3.4.txt")
|
||||||
|
|
||||||
|
|
||||||
class Symbols(object):
|
class Symbols(object):
|
||||||
@@ -42,7 +41,10 @@ python_grammar = pgen2.load_grammar(_GRAMMAR_FILE)
|
|||||||
python_symbols = Symbols(python_grammar)
|
python_symbols = Symbols(python_grammar)
|
||||||
|
|
||||||
python_grammar_no_print_statement = python_grammar.copy()
|
python_grammar_no_print_statement = python_grammar.copy()
|
||||||
del python_grammar_no_print_statement.keywords["print"]
|
try:
|
||||||
|
del python_grammar_no_print_statement.keywords["print"]
|
||||||
|
except KeyError:
|
||||||
|
pass # Doesn't exist in the Python 3 grammar.
|
||||||
|
|
||||||
|
|
||||||
def type_repr(type_num):
|
def type_repr(type_num):
|
||||||
@@ -67,12 +69,22 @@ def convert(grammar, raw_node):
|
|||||||
|
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
_ast_mapping = {
|
_ast_mapping = {
|
||||||
'simple_stmt': pr.ExprStmt,
|
'expr_stmt': pr.ExprStmt,
|
||||||
'classdef': pr.Class,
|
'classdef': pr.Class,
|
||||||
'funcdef': pr.Function,
|
'funcdef': pr.Function,
|
||||||
'file_input': pr.SubModule,
|
'file_input': pr.SubModule,
|
||||||
'import_name': pr.Import,
|
'import_name': pr.Import,
|
||||||
'import_from': pr.Import,
|
'import_from': pr.Import,
|
||||||
|
'break_stmt': pr.KeywordStatement,
|
||||||
|
'continue_stmt': pr.KeywordStatement,
|
||||||
|
'return_stmt': pr.KeywordStatement,
|
||||||
|
'raise_stmt': pr.KeywordStatement,
|
||||||
|
'yield_stmt': pr.KeywordStatement,
|
||||||
|
'del_stmt': pr.KeywordStatement,
|
||||||
|
'pass_stmt': pr.KeywordStatement,
|
||||||
|
'global_stmt': pr.KeywordStatement,
|
||||||
|
'nonlocal_stmt': pr.KeywordStatement,
|
||||||
|
'assert_stmt': pr.KeywordStatement,
|
||||||
}
|
}
|
||||||
|
|
||||||
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())
|
||||||
@@ -83,7 +95,7 @@ def convert(grammar, raw_node):
|
|||||||
if type in grammar.number2symbol:
|
if type in grammar.number2symbol:
|
||||||
# If there's exactly one child, return that child instead of
|
# If there's exactly one child, return that child instead of
|
||||||
# creating a new node.
|
# creating a new node.
|
||||||
if len(children) == 1:
|
if len(children) == 1 and type != 'expr_stmt':
|
||||||
return children[0]
|
return children[0]
|
||||||
print(raw_node, type_repr(type))
|
print(raw_node, type_repr(type))
|
||||||
#import pdb; pdb.set_trace()
|
#import pdb; pdb.set_trace()
|
||||||
|
|||||||
Reference in New Issue
Block a user