mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Grammar modifications so that the Python2.7 grammar looks more like the Python 3.4 grammar.
This commit is contained in:
@@ -109,6 +109,7 @@ class Parser(object):
|
|||||||
'comp_for': pt.CompFor,
|
'comp_for': pt.CompFor,
|
||||||
'decorator': pt.Decorator,
|
'decorator': pt.Decorator,
|
||||||
'lambdef': pt.Lambda,
|
'lambdef': pt.Lambda,
|
||||||
|
'old_lambdef': pt.Lambda,
|
||||||
'lambdef_nocond': pt.Lambda,
|
'lambdef_nocond': pt.Lambda,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,13 +122,13 @@ arith_expr: term (('+'|'-') term)*
|
|||||||
term: factor (('*'|'/'|'%'|'//') factor)*
|
term: factor (('*'|'/'|'%'|'//') factor)*
|
||||||
factor: ('+'|'-'|'~') factor | power
|
factor: ('+'|'-'|'~') factor | power
|
||||||
power: atom trailer* ['**' factor]
|
power: atom trailer* ['**' factor]
|
||||||
atom: ('(' [yield_expr|testlist_gexp] ')' |
|
atom: ('(' [yield_expr|testlist_comp] ')' |
|
||||||
'[' [listmaker] ']' |
|
'[' [testlist_comp] ']' |
|
||||||
'{' [dictsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
'`' testlist1 '`' |
|
'`' testlist1 '`' |
|
||||||
NAME | NUMBER | STRING+ | '.' '.' '.')
|
NAME | NUMBER | STRING+ | '.' '.' '.')
|
||||||
listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
# Modification by David Halter, remove `testlist_gexp` and `listmaker`
|
||||||
testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
||||||
lambdef: 'lambda' [varargslist] ':' test
|
lambdef: 'lambda' [varargslist] ':' test
|
||||||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
||||||
subscriptlist: subscript (',' subscript)* [',']
|
subscriptlist: subscript (',' subscript)* [',']
|
||||||
@@ -136,7 +136,9 @@ subscript: test | [test] ':' [test] [sliceop]
|
|||||||
sliceop: ':' [test]
|
sliceop: ':' [test]
|
||||||
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
|
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
|
||||||
testlist: test (',' test)* [',']
|
testlist: test (',' test)* [',']
|
||||||
dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
|
# Modification by David Halter, dictsetmaker -> dictorsetmaker (so that it's
|
||||||
|
# the same as in the 3.4 grammar).
|
||||||
|
dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
|
||||||
(test (comp_for | (',' test)* [','])) )
|
(test (comp_for | (',' test)* [','])) )
|
||||||
|
|
||||||
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
|
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
|
||||||
|
|||||||
@@ -152,6 +152,6 @@ def test_error_correction_with():
|
|||||||
try:
|
try:
|
||||||
f."""
|
f."""
|
||||||
comps = jedi.Script(source).completions()
|
comps = jedi.Script(source).completions()
|
||||||
assert len(comps) > 40
|
assert len(comps) > 30
|
||||||
# `open` completions have a closed attribute.
|
# `open` completions have a closed attribute.
|
||||||
assert [1 for c in comps if c.name == 'closed']
|
assert [1 for c in comps if c.name == 'closed']
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ asdfasdf""" + "h"
|
|||||||
|
|
||||||
def test_simple_no_whitespace(self):
|
def test_simple_no_whitespace(self):
|
||||||
# Test a simple one line string, no preceding whitespace
|
# Test a simple one line string, no preceding whitespace
|
||||||
simple_docstring = '"""simple one line docstring"""'
|
simple_docstring = u'"""simple one line docstring"""'
|
||||||
simple_docstring_io = StringIO(simple_docstring)
|
simple_docstring_io = StringIO(simple_docstring)
|
||||||
tokens = parser.tokenize.generate_tokens(simple_docstring_io.readline)
|
tokens = parser.tokenize.generate_tokens(simple_docstring_io.readline)
|
||||||
token_list = list(tokens)
|
token_list = list(tokens)
|
||||||
|
|||||||
Reference in New Issue
Block a user