Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
53fc37a9
Commit
53fc37a9
authored
Mar 19, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapt to stricter version of the CPython implementation (that follows the actual PEP)
parent
d7ac5174
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
74 deletions
+51
-74
Cython/Compiler/Lexicon.py
Cython/Compiler/Lexicon.py
+6
-7
Cython/Compiler/Tests/TestGrammar.py
Cython/Compiler/Tests/TestGrammar.py
+40
-48
tests/run/int_literals.pyx
tests/run/int_literals.pyx
+5
-19
No files found.
Cython/Compiler/Lexicon.py
View file @
53fc37a9
...
...
@@ -24,25 +24,24 @@ def make_lexicon():
bindigit
=
Any
(
"01"
)
octdigit
=
Any
(
"01234567"
)
hexdigit
=
Any
(
"0123456789ABCDEFabcdef"
)
allow_
=
Rep
(
Str
(
"_"
))
indentation
=
Bol
+
Rep
(
Any
(
"
\
t
"
))
def
underscore_digits
(
d
):
return
d
+
Rep
(
Str
(
"_"
)
|
d
)
return
Rep1
(
d
)
+
Rep
(
Str
(
"_"
)
+
Rep1
(
d
)
)
decimal
=
underscore_digits
(
digit
)
dot
=
Str
(
"."
)
exponent
=
allow_
+
Any
(
"Ee"
)
+
Opt
(
Any
(
"+-"
))
+
decimal
exponent
=
Any
(
"Ee"
)
+
Opt
(
Any
(
"+-"
))
+
decimal
decimal_fract
=
(
decimal
+
dot
+
Opt
(
decimal
))
|
(
dot
+
decimal
)
name
=
letter
+
Rep
(
letter
|
digit
)
intconst
=
decimal
|
(
Str
(
"0"
)
+
((
Any
(
"Xx"
)
+
allow_
+
underscore_digits
(
hexdigit
))
|
(
Any
(
"Oo"
)
+
allow_
+
underscore_digits
(
octdigit
))
|
(
Any
(
"Bb"
)
+
allow_
+
underscore_digits
(
bindigit
))
))
intconst
=
decimal
|
(
Str
(
"0"
)
+
((
Any
(
"Xx"
)
+
underscore_digits
(
hexdigit
))
|
(
Any
(
"Oo"
)
+
underscore_digits
(
octdigit
))
|
(
Any
(
"Bb"
)
+
underscore_digits
(
bindigit
))
))
intsuffix
=
(
Opt
(
Any
(
"Uu"
))
+
Opt
(
Any
(
"Ll"
))
+
Opt
(
Any
(
"Ll"
)))
|
(
Opt
(
Any
(
"Ll"
))
+
Opt
(
Any
(
"Ll"
))
+
Opt
(
Any
(
"Uu"
)))
intliteral
=
intconst
+
intsuffix
fltconst
=
(
decimal_fract
+
Opt
(
exponent
))
|
(
decimal
+
exponent
)
imagconst
=
(
intconst
|
fltconst
)
+
allow_
+
Any
(
"jJ"
)
imagconst
=
(
intconst
|
fltconst
)
+
Any
(
"jJ"
)
beginstring
=
Opt
(
Any
(
string_prefixes
)
+
Opt
(
Any
(
raw_prefixes
))
|
Any
(
raw_prefixes
)
+
Opt
(
Any
(
bytes_prefixes
))
|
...
...
Cython/Compiler/Tests/TestGrammar.py
View file @
53fc37a9
...
...
@@ -10,58 +10,66 @@ from __future__ import absolute_import
from
...TestUtils
import
CythonTest
from
..Errors
import
CompileError
# Copied from CPython's test_grammar.py
VALID_UNDERSCORE_LITERALS
=
[
# Copied from CPython's test_grammar.py
'0_0_0'
,
'4_2'
,
'4_______2'
,
'1_0000_0000'
,
'0b_1001_0100'
,
'0x_ffff_ffff'
,
'0o_5_7_7'
,
'1__.4'
,
'42_j'
,
'1.4_j'
,
'1.4e5_j'
,
'1_00_00_.5'
,
'1_e10'
,
'1_E10'
,
'1_e1_0'
,
'0b1001_0100'
,
'0xffff_ffff'
,
'0o5_7_7'
,
'1_00_00.5'
,
'1e1_0'
,
'.1_4'
,
]
# Copied from CPython's test_grammar.py
INVALID_UNDERSCORE_LITERALS
=
[
# Trailing underscores:
'0_'
,
'42_'
,
'1.4j_'
,
'0b1_'
,
'0xf_'
,
'0o5_'
,
]
INVALID_UNDERSCORE_LITERALS
=
[
# Copied from CPython's test_grammar.py
# Trailing underscores:
# Underscores in the base selector:
'0_b0'
,
'0_xf'
,
'0_o5'
,
# Underscore right after the base selector:
'0b_0'
,
'0x_f'
,
'0o_5'
,
# Old-style octal, still disallowed:
#'0_7',
#'09_99',
# Underscore after non-digit:
'1.4j_'
,
'1.4e_1'
,
'.1_4e_1'
,
'1.0e+_1'
,
# Special case with exponent:
'0 if 1_Else 1'
,
# Underscore right before a dot:
'1_.4'
,
'1_.4j'
,
# Underscore right after a dot:
'1._4'
,
'1._4j'
,
'1._4e5_j'
,
'._5'
,
]
UNDERSCORE_EXPRESSIONS
=
[
(
'0 if 1_____else 1'
,
True
),
(
'0 if 1_____Else 1'
,
False
),
(
'0 if 1.0_____else 1'
,
True
),
(
'0 if 1.0_____Else 1'
,
False
),
# Underscore right after a sign:
'1.0e+_1'
,
# Multiple consecutive underscores:
'4_______2'
,
'0.1__4'
,
'0b1001__0100'
,
'0xffff__ffff'
,
'0o5__77'
,
'1e1__0'
,
# Underscore right before j:
'1.4_j'
,
'1.4e5_j'
,
# Underscore right before e:
'1_e1'
,
'1.4_e1'
,
# Underscore right after e:
'1e_1'
,
'1.4e_1'
,
]
...
...
@@ -88,22 +96,6 @@ class TestGrammar(CythonTest):
# cython: language_level=3
'''
+
code
)
is
not
None
def
test_underscore_number_expressions
(
self
):
for
expression
,
is_valid
in
UNDERSCORE_EXPRESSIONS
:
code
=
'x = '
+
expression
fragment
=
u'''
\
# cython: language_level=3
'''
+
code
if
is_valid
:
assert
self
.
fragment
(
fragment
)
is
not
None
else
:
try
:
self
.
fragment
(
fragment
)
except
CompileError
as
exc
:
assert
code
in
[
s
.
strip
()
for
s
in
str
(
exc
).
splitlines
()],
str
(
exc
)
else
:
assert
False
,
"Invalid Cython code '%s' failed to raise an exception"
%
code
if
__name__
==
"__main__"
:
import
unittest
...
...
tests/run/int_literals.pyx
View file @
53fc37a9
...
...
@@ -16,27 +16,13 @@ def valid_underscore_literals():
# Copied from CPython's test_grammar.py
assert
0_0_0
==
0
assert
4_2
==
42
assert
4
_______2
==
42
assert
1_0000_0000
==
100000000
assert
0b_1001_0100
==
0b10010100
assert
0x_ffff_ffff
==
0xffffffff
assert
0o_5_7_7
==
0o577
assert
1
__
.
4
==
1.4
assert
42
_j
==
42j
assert
1.4
_j
==
1.4j
assert
1.4e5
_j
==
1.4e5j
assert
1_00_00
_
.
5
==
10000.5
assert
1
_e10
==
1e10
assert
1
_E10
==
1E10
assert
1
_e1_0
==
1e10
assert
0b1001_0100
==
0b10010100
assert
0xffff_ffff
==
0xffffffff
assert
0o5_7_7
==
0o577
assert
1_00_00.5
==
10000.5
assert
1e1_0
==
1e10
assert
.
1_4
==
.
14
assert
0
_
==
0
assert
42
_
==
42
assert
0b1
_
==
0b1
assert
0xf
_
==
0xf
assert
0o5
_
==
0o5
assert
(
0
if
1
_____else
1
)
==
0
assert
(
0
if
1.0
_____else
1
)
==
0
@
cython
.
test_assert_path_exists
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment