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
Boxiang Sun
cython
Commits
2baa1889
Commit
2baa1889
authored
Oct 10, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor source modernisations and cleanups in Scanning.py
parent
73aa3651
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
19 deletions
+32
-19
Cython/Compiler/Scanning.pxd
Cython/Compiler/Scanning.pxd
+3
-0
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+29
-19
No files found.
Cython/Compiler/Scanning.pxd
View file @
2baa1889
...
...
@@ -4,6 +4,9 @@ import cython
from
..Plex.Scanners
cimport
Scanner
cdef
get_lexicon
()
cdef
initial_compile_time_env
()
cdef
class
Method
:
cdef
object
name
cdef
object
__name__
...
...
Cython/Compiler/Scanning.py
View file @
2baa1889
...
...
@@ -5,13 +5,15 @@
from
__future__
import
absolute_import
import
cython
cython
.
declare
(
EncodedString
=
object
,
make_lexicon
=
object
,
lexicon
=
object
,
any_string_prefix
=
unicode
,
IDENT
=
unicode
,
print_function
=
object
,
error
=
object
,
warning
=
object
,
os
=
object
,
platform
=
object
)
import
os
import
platform
import
cython
cython
.
declare
(
EncodedString
=
object
,
any_string_prefix
=
unicode
,
IDENT
=
unicode
,
print_function
=
object
,
error
=
object
,
warning
=
object
)
from
..
import
Utils
from
..Plex.Scanners
import
Scanner
from
..Plex.Errors
import
UnrecognizedInput
...
...
@@ -28,12 +30,14 @@ scanner_dump_file = None
lexicon
=
None
def
get_lexicon
():
global
lexicon
if
not
lexicon
:
lexicon
=
make_lexicon
()
return
lexicon
#------------------------------------------------------------------
py_reserved_words
=
[
...
...
@@ -49,15 +53,17 @@ pyx_reserved_words = py_reserved_words + [
"cimport"
,
"DEF"
,
"IF"
,
"ELIF"
,
"ELSE"
]
class
Method
(
object
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
__name__
=
name
# for Plex tracing
self
.
__name__
=
name
# for Plex tracing
def
__call__
(
self
,
stream
,
text
):
return
getattr
(
stream
,
self
.
name
)(
text
)
#------------------------------------------------------------------
class
CompileTimeScope
(
object
):
...
...
@@ -88,6 +94,7 @@ class CompileTimeScope(object):
else
:
raise
def
initial_compile_time_env
():
benv
=
CompileTimeScope
()
names
=
(
'UNAME_SYSNAME'
,
'UNAME_NODENAME'
,
'UNAME_RELEASE'
,
...
...
@@ -116,6 +123,7 @@ def initial_compile_time_env():
denv
=
CompileTimeScope
(
benv
)
return
denv
#------------------------------------------------------------------
class
SourceDescriptor
(
object
):
...
...
@@ -166,6 +174,7 @@ class SourceDescriptor(object):
except
AttributeError
:
return
False
class
FileSourceDescriptor
(
SourceDescriptor
):
"""
Represents a code source. A code source is a more generic abstraction
...
...
@@ -235,6 +244,7 @@ class FileSourceDescriptor(SourceDescriptor):
def
__repr__
(
self
):
return
"<FileSourceDescriptor:%s>"
%
self
.
filename
class
StringSourceDescriptor
(
SourceDescriptor
):
"""
Instances of this class can be used instead of a filenames if the
...
...
@@ -275,6 +285,7 @@ class StringSourceDescriptor(SourceDescriptor):
def
__repr__
(
self
):
return
"<StringSourceDescriptor:%s>"
%
self
.
name
#------------------------------------------------------------------
class
PyrexScanner
(
Scanner
):
...
...
@@ -284,8 +295,8 @@ class PyrexScanner(Scanner):
# compile_time_eval boolean In a true conditional compilation context
# compile_time_expr boolean In a compile-time expression context
def
__init__
(
self
,
file
,
filename
,
parent_scanner
=
None
,
scope
=
None
,
context
=
None
,
source_encoding
=
None
,
parse_comments
=
True
,
initial_pos
=
None
):
def
__init__
(
self
,
file
,
filename
,
parent_scanner
=
None
,
scope
=
None
,
context
=
None
,
source_encoding
=
None
,
parse_comments
=
True
,
initial_pos
=
None
):
Scanner
.
__init__
(
self
,
get_lexicon
(),
file
,
filename
,
initial_pos
)
if
parent_scanner
:
self
.
context
=
parent_scanner
.
context
...
...
@@ -299,8 +310,8 @@ class PyrexScanner(Scanner):
self
.
compile_time_env
=
initial_compile_time_env
()
self
.
compile_time_eval
=
1
self
.
compile_time_expr
=
0
if
hasattr
(
context
.
options
,
'compile_time_env'
)
and
\
context
.
options
.
compile_time_env
is
not
None
:
if
(
hasattr
(
context
.
options
,
'compile_time_env'
)
and
context
.
options
.
compile_time_env
is
not
None
)
:
self
.
compile_time_env
.
update
(
context
.
options
.
compile_time_env
)
self
.
parse_comments
=
parse_comments
self
.
source_encoding
=
source_encoding
...
...
@@ -326,11 +337,11 @@ class PyrexScanner(Scanner):
return
self
.
indentation_stack
[
-
1
]
def
open_bracket_action
(
self
,
text
):
self
.
bracket_nesting_level
=
self
.
bracket_nesting_level
+
1
self
.
bracket_nesting_level
+=
1
return
text
def
close_bracket_action
(
self
,
text
):
self
.
bracket_nesting_level
=
self
.
bracket_nesting_level
-
1
self
.
bracket_nesting_level
-=
1
return
text
def
newline_action
(
self
,
text
):
...
...
@@ -406,6 +417,7 @@ class PyrexScanner(Scanner):
sy
,
systring
=
self
.
read
()
except
UnrecognizedInput
:
self
.
error
(
"Unrecognized character"
)
return
# just a marker, error() always raises
if
sy
==
IDENT
:
if
systring
in
self
.
keywords
:
if
systring
==
u'print'
and
print_function
in
self
.
context
.
future_directives
:
...
...
@@ -445,21 +457,21 @@ class PyrexScanner(Scanner):
# This method should be added to Plex
self
.
queue
.
insert
(
0
,
(
token
,
value
))
def
error
(
self
,
message
,
pos
=
None
,
fatal
=
True
):
def
error
(
self
,
message
,
pos
=
None
,
fatal
=
True
):
if
pos
is
None
:
pos
=
self
.
position
()
if
self
.
sy
==
'INDENT'
:
err
=
err
or
(
pos
,
"Possible inconsistent indentation"
)
error
(
pos
,
"Possible inconsistent indentation"
)
err
=
error
(
pos
,
message
)
if
fatal
:
raise
err
def
expect
(
self
,
what
,
message
=
None
):
def
expect
(
self
,
what
,
message
=
None
):
if
self
.
sy
==
what
:
self
.
next
()
else
:
self
.
expected
(
what
,
message
)
def
expect_keyword
(
self
,
what
,
message
=
None
):
def
expect_keyword
(
self
,
what
,
message
=
None
):
if
self
.
sy
==
IDENT
and
self
.
systring
==
what
:
self
.
next
()
else
:
...
...
@@ -476,12 +488,10 @@ class PyrexScanner(Scanner):
self
.
error
(
"Expected '%s', found '%s'"
%
(
what
,
found
))
def
expect_indent
(
self
):
self
.
expect
(
'INDENT'
,
"Expected an increase in indentation level"
)
self
.
expect
(
'INDENT'
,
"Expected an increase in indentation level"
)
def
expect_dedent
(
self
):
self
.
expect
(
'DEDENT'
,
"Expected a decrease in indentation level"
)
self
.
expect
(
'DEDENT'
,
"Expected a decrease in indentation level"
)
def
expect_newline
(
self
,
message
=
"Expected a newline"
,
ignore_semicolon
=
False
):
# Expect either a newline or end of file
...
...
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