1
0
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:
Dave Halter
2014-10-17 01:34:47 +02:00
parent ae8969a0d1
commit 19acdd32b7
5 changed files with 27 additions and 13 deletions

View File

@@ -15,8 +15,8 @@
# file_input is a module or sequence of commands read from an input file;
# eval_input is the input for the eval() functions.
# NB: compound_stmt in single_input is followed by extra NEWLINE!
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
file_input: (NEWLINE | stmt)* ENDMARKER
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
eval_input: testlist NEWLINE* ENDMARKER
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE

View File

@@ -173,6 +173,7 @@ opmap_raw = """
// DOUBLESLASH
//= DOUBLESLASHEQUAL
-> RARROW
... ELLIPSIS
"""
opmap = {}

View File

@@ -62,7 +62,8 @@ COMMENT = 52
NL = 53
RARROW = 54
ERRORTOKEN = 55
N_TOKENS = 56
ELLIPSIS = 56
N_TOKENS = 57
NT_OFFSET = 256
#--end constants--

View File

@@ -12,7 +12,6 @@ There's also a pattern matching implementation here.
__author__ = "Guido van Rossum <guido@python.org>"
import sys
import os
from . import pgen2
@@ -22,7 +21,7 @@ _type_reprs = {}
# 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):
@@ -42,7 +41,10 @@ python_grammar = pgen2.load_grammar(_GRAMMAR_FILE)
python_symbols = Symbols(python_grammar)
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):
@@ -67,12 +69,22 @@ def convert(grammar, raw_node):
from jedi.parser import representation as pr
_ast_mapping = {
'simple_stmt': pr.ExprStmt,
'expr_stmt': pr.ExprStmt,
'classdef': pr.Class,
'funcdef': pr.Function,
'file_input': pr.SubModule,
'import_name': 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())
@@ -83,7 +95,7 @@ def convert(grammar, raw_node):
if type in grammar.number2symbol:
# If there's exactly one child, return that child instead of
# creating a new node.
if len(children) == 1:
if len(children) == 1 and type != 'expr_stmt':
return children[0]
print(raw_node, type_repr(type))
#import pdb; pdb.set_trace()