Octal fixes.

This commit is contained in:
Dave Halter
2017-07-12 22:28:54 +02:00
parent 70de06ed87
commit b618c99b08
3 changed files with 49 additions and 50 deletions
+5 -7
View File
@@ -35,9 +35,8 @@ stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | exec_stmt | assert_stmt) import_stmt | global_stmt | exec_stmt | assert_stmt)
expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) | expr_stmt: testlist (augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*) ('=' (yield_expr|testlist))*)
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=') '<<=' | '>>=' | '**=' | '//=')
# For normal assignments, additional restrictions enforced by the interpreter # For normal assignments, additional restrictions enforced by the interpreter
@@ -98,7 +97,6 @@ and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)* comparison: expr (comp_op expr)*
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
star_expr: '*' expr
expr: xor_expr ('|' xor_expr)* expr: xor_expr ('|' xor_expr)*
xor_expr: and_expr ('^' and_expr)* xor_expr: and_expr ('^' and_expr)*
and_expr: shift_expr ('&' shift_expr)* and_expr: shift_expr ('&' shift_expr)*
@@ -113,20 +111,20 @@ atom: ('(' [yield_expr|testlist_comp] ')' |
'`' testlist1 '`' | '`' testlist1 '`' |
NAME | NUMBER | STRING+ | '.' '.' '.') NAME | NUMBER | STRING+ | '.' '.' '.')
# Modification by David Halter, remove `testlist_gexp` and `listmaker` # Modification by David Halter, remove `testlist_gexp` and `listmaker`
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) testlist_comp: test ( comp_for | (',' test)* [','] )
lambdef: 'lambda' [varargslist] ':' test lambdef: 'lambda' [varargslist] ':' test
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [','] subscriptlist: subscript (',' subscript)* [',']
subscript: test | [test] ':' [test] [sliceop] subscript: test | [test] ':' [test] [sliceop]
sliceop: ':' [test] sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] exprlist: expr (',' expr)* [',']
testlist: test (',' test)* [','] testlist: test (',' test)* [',']
# Modification by David Halter, dictsetmaker -> dictorsetmaker (so that it's # Modification by David Halter, dictsetmaker -> dictorsetmaker (so that it's
# the same as in the 3.4 grammar). # the same as in the 3.4 grammar).
dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) | dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
(test (comp_for | (',' test)* [','])) ) (test (comp_for | (',' test)* [','])) )
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
arglist: (argument ',')* (argument [','] arglist: (argument ',')* (argument [',']
|'*' test (',' argument)* [',' '**' test] |'*' test (',' argument)* [',' '**' test]
+1 -1
View File
@@ -125,7 +125,7 @@ def _create_token_collection(version_int):
if version_int >= 30: if version_int >= 30:
Octnumber = r'0[oO][0-7]+' Octnumber = r'0[oO][0-7]+'
else: else:
Octnumber = '0[0-7]+' Octnumber = '0[oO]?[0-7]+'
Decnumber = r'(?:0+|[1-9][0-9]*)' Decnumber = r'(?:0+|[1-9][0-9]*)'
Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber) Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber)
Exponent = r'[eE][-+]?[0-9]+' Exponent = r'[eE][-+]?[0-9]+'
+43 -42
View File
@@ -200,68 +200,68 @@ def test_annotation_8(each_py3_version):
_invalid_syntax(s, each_py3_version) _invalid_syntax(s, each_py3_version)
def test_except_new(): def test_except_new(each_version):
s = """ s = """
try: try:
x x
except E as N: except E as N:
y""" y"""
_parse(s) _parse(s, each_version)
def test_except_old(): def test_except_old(works_in_py2):
s = """ s = """
try: try:
x x
except E, N: except E, N:
y""" y"""
_parse(s, version='2.7') works_in_py2.parse(s)
# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testAtoms # Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testAtoms
def test_set_literal_1(): def test_set_literal_1(each_version):
_parse("""x = {'one'}""") _parse("""x = {'one'}""", each_version)
def test_set_literal_2(): def test_set_literal_2(each_version):
_parse("""x = {'one', 1,}""") _parse("""x = {'one', 1,}""", each_version)
def test_set_literal_3(): def test_set_literal_3(each_version):
_parse("""x = {'one', 'two', 'three'}""") _parse("""x = {'one', 'two', 'three'}""", each_version)
def test_set_literal_4(): def test_set_literal_4(each_version):
_parse("""x = {2, 3, 4,}""") _parse("""x = {2, 3, 4,}""", each_version)
def test_new_octal_notation(): def test_new_octal_notation(each_version):
code = """0o7777777777777""" _parse("""0o7777777777777""", each_version)
if py_version >= 30: _invalid_syntax("""0o7324528887""", each_version)
_parse(code)
else:
_invalid_syntax(code)
_invalid_syntax("""0o7324528887""")
def test_new_binary_notation():
_parse("""0b101010""")
_invalid_syntax("""0b0101021""")
def test_class_new_syntax(): def test_old_octal_notation(works_in_py2):
_parse("class B(t=7): pass") works_in_py2.parse("07")
_parse("class B(t, *args): pass")
_parse("class B(t, **kwargs): pass")
_parse("class B(t, *args, **kwargs): pass")
_parse("class B(t, y=9, *args, **kwargs): pass")
def test_parser_idempotency_extended_unpacking(): def test_new_binary_notation(each_version):
_parse("""0b101010""", each_version)
_invalid_syntax("""0b0101021""", each_version)
def test_class_new_syntax(works_ge_py3):
works_ge_py3.parse("class B(t=7): pass")
works_ge_py3.parse("class B(t, *args): pass")
works_ge_py3.parse("class B(t, **kwargs): pass")
works_ge_py3.parse("class B(t, *args, **kwargs): pass")
works_ge_py3.parse("class B(t, y=9, *args, **kwargs): pass")
def test_parser_idempotency_extended_unpacking(works_ge_py3):
"""A cut-down version of pytree_idempotency.py.""" """A cut-down version of pytree_idempotency.py."""
_parse("a, *b, c = x\n") works_ge_py3.parse("a, *b, c = x\n")
_parse("[*a, b] = x\n") works_ge_py3.parse("[*a, b] = x\n")
_parse("(z, *y, w) = m\n") works_ge_py3.parse("(z, *y, w) = m\n")
_parse("for *z, m in d: pass\n") works_ge_py3.parse("for *z, m in d: pass\n")
@pytest.mark.skipif('sys.version_info[0] < 3') def test_multiline_bytes_literals(each_version):
def test_multiline_bytes_literals():
""" """
It's not possible to get the same result when using \xaa in Python 2/3, It's not possible to get the same result when using \xaa in Python 2/3,
because it's treated differently. because it's treated differently.
@@ -272,23 +272,24 @@ def test_multiline_bytes_literals():
b"and Larger Than One Block-Size Data"), b"and Larger Than One Block-Size Data"),
"6f630fad67cda0ee1fb1f562db3aa53e") "6f630fad67cda0ee1fb1f562db3aa53e")
""" """
_parse(s) _parse(s, each_version)
def test_multiline_bytes_tripquote_literals():
def test_multiline_bytes_tripquote_literals(each_version):
s = ''' s = '''
b""" b"""
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN">
""" """
''' '''
_parse(s) _parse(s, each_version)
@pytest.mark.skipif('sys.version_info[0] < 3')
def test_multiline_str_literals(): def test_multiline_str_literals(each_version):
s = """ s = """
md5test("\xaa" * 80, md5test("\xaa" * 80,
("Test Using Larger Than Block-Size Key " ("Test Using Larger Than Block-Size Key "
"and Larger Than One Block-Size Data"), "and Larger Than One Block-Size Data"),
"6f630fad67cda0ee1fb1f562db3aa53e") "6f630fad67cda0ee1fb1f562db3aa53e")
""" """
_parse(s) _parse(s, each_version)