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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
075e2829
Commit
075e2829
authored
Mar 14, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move Cython language keywords out of the way when parsing .py files
parent
7072be52
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
20 deletions
+32
-20
Cython/Compiler/Scanning.pxd
Cython/Compiler/Scanning.pxd
+1
-0
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+31
-20
No files found.
Cython/Compiler/Scanning.pxd
View file @
075e2829
...
...
@@ -14,6 +14,7 @@ cdef class PyrexScanner(Scanner):
cdef
public
bint
compile_time_expr
cdef
public
bint
parse_comments
cdef
public
source_encoding
cdef
set
keywords
cdef
public
list
indentation_stack
cdef
public
indentation_char
cdef
public
int
bracket_nesting_level
...
...
Cython/Compiler/Scanning.py
View file @
075e2829
...
...
@@ -37,13 +37,17 @@ def get_lexicon():
#------------------------------------------------------------------
reserved_words
=
[
"global"
,
"include"
,
"ctypedef"
,
"cdef"
,
"def"
,
"class"
,
"print"
,
"del"
,
"pass"
,
"break"
,
"continue"
,
"return"
,
"raise"
,
"import"
,
"exec"
,
"try"
,
"except"
,
"finally"
,
"while"
,
"if"
,
"elif"
,
"else"
,
"for"
,
"in"
,
"assert"
,
"and"
,
"or"
,
"not"
,
"is"
,
"in"
,
"lambda"
,
"from"
,
"yield"
,
"cimport"
,
"by"
,
"with"
,
"cpdef"
,
"DEF"
,
"IF"
,
"ELIF"
,
"ELSE"
py_reserved_words
=
[
"global"
,
"def"
,
"class"
,
"print"
,
"del"
,
"pass"
,
"break"
,
"continue"
,
"return"
,
"raise"
,
"import"
,
"exec"
,
"try"
,
"except"
,
"finally"
,
"while"
,
"if"
,
"elif"
,
"else"
,
"for"
,
"in"
,
"assert"
,
"and"
,
"or"
,
"not"
,
"is"
,
"in"
,
"lambda"
,
"from"
,
"yield"
,
"with"
,
"nonlocal"
,
]
pyx_reserved_words
=
py_reserved_words
+
[
"include"
,
"ctypedef"
,
"cdef"
,
"cpdef"
,
"cimport"
,
"by"
,
"DEF"
,
"IF"
,
"ELIF"
,
"ELSE"
]
class
Method
(
object
):
...
...
@@ -57,17 +61,6 @@ class Method(object):
#------------------------------------------------------------------
def
build_resword_dict
():
d
=
{}
for
word
in
reserved_words
:
d
[
word
]
=
1
return
d
cython
.
declare
(
resword_dict
=
dict
)
resword_dict
=
build_resword_dict
()
#------------------------------------------------------------------
class
CompileTimeScope
(
object
):
def
__init__
(
self
,
outer
=
None
):
...
...
@@ -123,11 +116,23 @@ class SourceDescriptor(object):
"""
A SourceDescriptor should be considered immutable.
"""
_file_type
=
'pyx'
_escaped_description
=
None
_cmp_name
=
''
def
__str__
(
self
):
assert
False
# To catch all places where a descriptor is used directly as a filename
def
set_file_type_from_name
(
self
,
filename
):
name
,
ext
=
os
.
path
.
splitext
(
filename
)
self
.
_file_type
=
ext
in
(
'.pyx'
,
'.pxd'
,
'.py'
)
and
ext
[
1
:]
or
'pyx'
def
is_cython_file
(
self
):
return
self
.
_file_type
in
(
'pyx'
,
'pxd'
)
def
is_python_file
(
self
):
return
self
.
_file_type
==
'py'
def
get_escaped_description
(
self
):
if
self
.
_escaped_description
is
None
:
self
.
_escaped_description
=
\
...
...
@@ -165,6 +170,7 @@ class FileSourceDescriptor(SourceDescriptor):
"""
def
__init__
(
self
,
filename
):
self
.
filename
=
filename
self
.
set_file_type_from_name
(
filename
)
self
.
_cmp_name
=
filename
def
get_lines
(
self
,
encoding
=
None
,
error_handling
=
None
):
...
...
@@ -196,6 +202,7 @@ class StringSourceDescriptor(SourceDescriptor):
"""
def
__init__
(
self
,
name
,
code
):
self
.
name
=
name
self
.
set_file_type_from_name
(
name
)
self
.
codelines
=
[
x
+
"
\
n
"
for
x
in
code
.
split
(
"
\
n
"
)]
self
.
_cmp_name
=
name
...
...
@@ -247,6 +254,10 @@ class PyrexScanner(Scanner):
self
.
compile_time_expr
=
0
self
.
parse_comments
=
parse_comments
self
.
source_encoding
=
source_encoding
if
filename
.
is_python_file
():
self
.
keywords
=
cython
.
set
(
py_reserved_words
)
else
:
self
.
keywords
=
cython
.
set
(
pyx_reserved_words
)
self
.
trace
=
trace_scanner
self
.
indentation_stack
=
[
0
]
self
.
indentation_char
=
None
...
...
@@ -346,7 +357,7 @@ class PyrexScanner(Scanner):
except
UnrecognizedInput
:
self
.
error
(
"Unrecognized character"
)
if
sy
==
IDENT
:
if
systring
in
resword_dict
:
if
systring
in
self
.
keywords
:
if
systring
==
'print'
and
\
print_function
in
self
.
context
.
future_directives
:
systring
=
EncodedString
(
systring
)
...
...
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