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
df9b6431
Commit
df9b6431
authored
Mar 13, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
major cleanup to fix Py3 code issues (found by 2to3 and 'python2.6 -3')
parent
fb4dc542
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
57 additions
and
66 deletions
+57
-66
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-3
Cython/Distutils/build_ext.py
Cython/Distutils/build_ext.py
+2
-2
Cython/Distutils/extension.py
Cython/Distutils/extension.py
+1
-1
Cython/Mac/MacSystem.py
Cython/Mac/MacSystem.py
+6
-6
Cython/Mac/TS_Misc_Suite.py
Cython/Mac/TS_Misc_Suite.py
+5
-5
Cython/Plex/DFA.py
Cython/Plex/DFA.py
+9
-9
Cython/Plex/Machines.py
Cython/Plex/Machines.py
+6
-9
Cython/Plex/Regexps.py
Cython/Plex/Regexps.py
+6
-7
Cython/Plex/Traditional.py
Cython/Plex/Traditional.py
+2
-2
Cython/Plex/Transitions.py
Cython/Plex/Transitions.py
+8
-13
Cython/Shadow.py
Cython/Shadow.py
+9
-9
No files found.
Cython/Compiler/Nodes.py
View file @
df9b6431
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# Pyrex - Parse tree nodes
# Pyrex - Parse tree nodes
#
#
import
s
tring
,
s
ys
,
os
,
time
,
copy
import
sys
,
os
,
time
,
copy
import
Code
import
Code
import
Builtin
import
Builtin
...
@@ -1412,7 +1412,7 @@ class CFuncDefNode(FuncDefNode):
...
@@ -1412,7 +1412,7 @@ class CFuncDefNode(FuncDefNode):
arg_decls
=
[
"void"
]
arg_decls
=
[
"void"
]
if
cname
is
None
:
if
cname
is
None
:
cname
=
self
.
entry
.
func_cname
cname
=
self
.
entry
.
func_cname
entity
=
type
.
function_header_code
(
cname
,
string
.
join
(
arg_decls
,
", "
))
entity
=
type
.
function_header_code
(
cname
,
', '
.
join
(
arg_decls
))
if
visibility
==
'public'
:
if
visibility
==
'public'
:
dll_linkage
=
"DL_EXPORT"
dll_linkage
=
"DL_EXPORT"
else
:
else
:
...
@@ -3790,7 +3790,7 @@ class WhileStatNode(LoopNode, StatNode):
...
@@ -3790,7 +3790,7 @@ class WhileStatNode(LoopNode, StatNode):
def
ForStatNode
(
pos
,
**
kw
):
def
ForStatNode
(
pos
,
**
kw
):
if
kw
.
has_key
(
'iterator'
)
:
if
'iterator'
in
kw
:
return
ForInStatNode
(
pos
,
**
kw
)
return
ForInStatNode
(
pos
,
**
kw
)
else
:
else
:
return
ForFromStatNode
(
pos
,
**
kw
)
return
ForFromStatNode
(
pos
,
**
kw
)
...
...
Cython/Distutils/build_ext.py
View file @
df9b6431
...
@@ -7,7 +7,7 @@ building Cython extension modules."""
...
@@ -7,7 +7,7 @@ building Cython extension modules."""
__revision__
=
"$Id:$"
__revision__
=
"$Id:$"
import
sys
,
os
,
string
,
re
import
sys
,
os
,
re
from
types
import
*
from
types
import
*
from
distutils.core
import
Command
from
distutils.core
import
Command
from
distutils.errors
import
*
from
distutils.errors
import
*
...
@@ -72,7 +72,7 @@ class build_ext(_build_ext.build_ext):
...
@@ -72,7 +72,7 @@ class build_ext(_build_ext.build_ext):
self
.
pyrex_include_dirs
=
[]
self
.
pyrex_include_dirs
=
[]
elif
type
(
self
.
pyrex_include_dirs
)
is
StringType
:
elif
type
(
self
.
pyrex_include_dirs
)
is
StringType
:
self
.
pyrex_include_dirs
=
\
self
.
pyrex_include_dirs
=
\
s
tring
.
split
(
self
.
pyrex_include_dirs
,
os
.
pathsep
)
s
elf
.
pyrex_include_dirs
.
split
(
os
.
pathsep
)
# finalize_options ()
# finalize_options ()
def
build_extensions
(
self
):
def
build_extensions
(
self
):
...
...
Cython/Distutils/extension.py
View file @
df9b6431
...
@@ -5,7 +5,7 @@ Pyrex extension modules in setup scripts."""
...
@@ -5,7 +5,7 @@ Pyrex extension modules in setup scripts."""
__revision__
=
"$Id:$"
__revision__
=
"$Id:$"
import
os
,
s
tring
,
s
ys
import
os
,
sys
from
types
import
*
from
types
import
*
import
distutils.extension
as
_Extension
import
distutils.extension
as
_Extension
...
...
Cython/Mac/MacSystem.py
View file @
df9b6431
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# Pyrex -- Mac system interface
# Pyrex -- Mac system interface
#
#
import
os
,
sys
,
string
import
os
,
sys
import
aetools
import
aetools
from
aetools
import
TalkTo
from
aetools
import
TalkTo
from
StdSuites.Standard_Suite
import
Standard_Suite_Events
as
Standard_Suite
from
StdSuites.Standard_Suite
import
Standard_Suite_Events
as
Standard_Suite
...
@@ -57,8 +57,8 @@ def do_toolserver_command(command):
...
@@ -57,8 +57,8 @@ def do_toolserver_command(command):
errn
,
stat
,
stdout
,
stderr
=
result
errn
,
stat
,
stdout
,
stderr
=
result
if
errn
:
if
errn
:
raise
CCompilerError
(
"ToolServer error: %s"
%
errn
)
raise
CCompilerError
(
"ToolServer error: %s"
%
errn
)
stdout
=
st
ring
.
replace
(
stdout
,
"
\
r
"
,
"
\
n
"
)
stdout
=
st
dout
.
replace
(
"
\
r
"
,
"
\
n
"
)
stderr
=
st
ring
.
replace
(
stderr
,
"
\
r
"
,
"
\
n
"
)
stderr
=
st
derr
.
replace
(
"
\
r
"
,
"
\
n
"
)
if
stdout
:
if
stdout
:
#print "<<< Begin ToolServer StdOut >>>"
#print "<<< Begin ToolServer StdOut >>>"
sys
.
stderr
.
write
(
stdout
)
sys
.
stderr
.
write
(
stdout
)
...
@@ -85,7 +85,7 @@ def c_compile(c_file):
...
@@ -85,7 +85,7 @@ def c_compile(c_file):
command
=
"%s -opt %s -nomapcr -w off -r %s %s -o %s"
%
(
command
=
"%s -opt %s -nomapcr -w off -r %s %s -o %s"
%
(
c_compiler
,
c_compiler
,
c_optimizations
,
c_optimizations
,
string
.
join
(
include_options
),
' '
.
join
(
include_options
),
c_file
,
c_file
,
o_file
,
o_file
,
#e_file
#e_file
...
@@ -106,9 +106,9 @@ def c_link_list(obj_files):
...
@@ -106,9 +106,9 @@ def c_link_list(obj_files):
out_file
=
replace_suffix
(
obj_files
[
0
],
shared_lib_suffix
)
out_file
=
replace_suffix
(
obj_files
[
0
],
shared_lib_suffix
)
command
=
"%s -xm s -export all %s %s %s -o %s"
%
(
command
=
"%s -xm s -export all %s %s %s -o %s"
%
(
c_linker
,
c_linker
,
string
.
join
(
obj_files
),
' '
.
join
(
obj_files
),
pythoncore
,
pythoncore
,
string
.
join
(
libraries
),
' '
.
join
(
libraries
),
out_file
)
out_file
)
stat
=
do_toolserver_command
(
command
)
stat
=
do_toolserver_command
(
command
)
if
stat
:
if
stat
:
...
...
Cython/Mac/TS_Misc_Suite.py
View file @
df9b6431
...
@@ -20,7 +20,7 @@ class TS_Misc_Suite(object):
...
@@ -20,7 +20,7 @@ class TS_Misc_Suite(object):
_code
=
'misc'
_code
=
'misc'
_subcode
=
'dosc'
_subcode
=
'dosc'
if
_arguments
:
raise
TypeError
,
'No optional args expected'
if
_arguments
:
raise
TypeError
(
'No optional args expected'
)
_arguments
[
'----'
]
=
_object
_arguments
[
'----'
]
=
_object
...
@@ -35,15 +35,15 @@ class TS_Misc_Suite(object):
...
@@ -35,15 +35,15 @@ class TS_Misc_Suite(object):
stat
=
0
stat
=
0
stdout
=
""
stdout
=
""
stderr
=
""
stderr
=
""
if
_arguments
.
has_key
(
'errn'
)
:
if
'errn'
in
_arguments
:
errn
=
_arguments
[
'errn'
]
errn
=
_arguments
[
'errn'
]
if
errn
:
if
errn
:
errn
=
aetools
.
decodeerror
(
_arguments
)
errn
=
aetools
.
decodeerror
(
_arguments
)
if
_arguments
.
has_key
(
'stat'
)
:
if
'stat'
in
_arguments
:
stat
=
_arguments
[
'stat'
]
stat
=
_arguments
[
'stat'
]
if
_arguments
.
has_key
(
'----'
)
:
if
'----'
in
_arguments
:
stdout
=
_arguments
[
'----'
]
stdout
=
_arguments
[
'----'
]
if
_arguments
.
has_key
(
'diag'
)
:
if
'diag'
in
_arguments
:
stderr
=
_arguments
[
'diag'
]
stderr
=
_arguments
[
'diag'
]
return
(
errn
,
stat
,
stdout
,
stderr
)
return
(
errn
,
stat
,
stdout
,
stderr
)
...
...
Cython/Plex/DFA.py
View file @
df9b6431
...
@@ -29,18 +29,18 @@ def nfa_to_dfa(old_machine, debug = None):
...
@@ -29,18 +29,18 @@ def nfa_to_dfa(old_machine, debug = None):
# Seed the process using the initial states of the old machine.
# Seed the process using the initial states of the old machine.
# Make the corresponding new states into initial states of the new
# Make the corresponding new states into initial states of the new
# machine with the same names.
# machine with the same names.
for
(
key
,
old_state
)
in
old_machine
.
initial_states
.
items
():
for
(
key
,
old_state
)
in
old_machine
.
initial_states
.
ite
rite
ms
():
new_state
=
state_map
.
old_to_new
(
epsilon_closure
(
old_state
))
new_state
=
state_map
.
old_to_new
(
epsilon_closure
(
old_state
))
new_machine
.
make_initial_state
(
key
,
new_state
)
new_machine
.
make_initial_state
(
key
,
new_state
)
# Tricky bit here: we add things to the end of this list while we're
# Tricky bit here: we add things to the end of this list while we're
# iterating over it. The iteration stops when closure is achieved.
# iterating over it. The iteration stops when closure is achieved.
for
new_state
in
new_machine
.
states
:
for
new_state
in
new_machine
.
states
:
transitions
=
TransitionMap
()
transitions
=
TransitionMap
()
for
old_state
in
state_map
.
new_to_old
(
new_state
)
.
keys
()
:
for
old_state
in
state_map
.
new_to_old
(
new_state
):
for
event
,
old_target_states
in
old_state
.
transitions
.
items
():
for
event
,
old_target_states
in
old_state
.
transitions
.
ite
rite
ms
():
if
event
and
old_target_states
:
if
event
and
old_target_states
:
transitions
.
add_set
(
event
,
set_epsilon_closure
(
old_target_states
))
transitions
.
add_set
(
event
,
set_epsilon_closure
(
old_target_states
))
for
event
,
old_states
in
transitions
.
items
():
for
event
,
old_states
in
transitions
.
ite
rite
ms
():
new_machine
.
add_transitions
(
new_state
,
event
,
state_map
.
old_to_new
(
old_states
))
new_machine
.
add_transitions
(
new_state
,
event
,
state_map
.
old_to_new
(
old_states
))
if
debug
:
if
debug
:
debug
.
write
(
"
\
n
===== State Mapping =====
\
n
"
)
debug
.
write
(
"
\
n
===== State Mapping =====
\
n
"
)
...
@@ -53,8 +53,8 @@ def set_epsilon_closure(state_set):
...
@@ -53,8 +53,8 @@ def set_epsilon_closure(state_set):
closures of its member states.
closures of its member states.
"""
"""
result
=
{}
result
=
{}
for
state1
in
state_set
.
keys
()
:
for
state1
in
state_set
:
for
state2
in
epsilon_closure
(
state1
)
.
keys
()
:
for
state2
in
epsilon_closure
(
state1
):
result
[
state2
]
=
1
result
[
state2
]
=
1
return
result
return
result
...
@@ -80,7 +80,7 @@ def add_to_epsilon_closure(state_set, state):
...
@@ -80,7 +80,7 @@ def add_to_epsilon_closure(state_set, state):
state_set
[
state
]
=
1
state_set
[
state
]
=
1
state_set_2
=
state
.
transitions
.
get_epsilon
()
state_set_2
=
state
.
transitions
.
get_epsilon
()
if
state_set_2
:
if
state_set_2
:
for
state2
in
state_set_2
.
keys
()
:
for
state2
in
state_set_2
:
add_to_epsilon_closure
(
state_set
,
state2
)
add_to_epsilon_closure
(
state_set
,
state2
)
class
StateMap
(
object
):
class
StateMap
(
object
):
...
@@ -119,7 +119,7 @@ class StateMap(object):
...
@@ -119,7 +119,7 @@ class StateMap(object):
def
highest_priority_action
(
self
,
state_set
):
def
highest_priority_action
(
self
,
state_set
):
best_action
=
None
best_action
=
None
best_priority
=
LOWEST_PRIORITY
best_priority
=
LOWEST_PRIORITY
for
state
in
state_set
.
keys
()
:
for
state
in
state_set
:
priority
=
state
.
action_priority
priority
=
state
.
action_priority
if
priority
>
best_priority
:
if
priority
>
best_priority
:
best_action
=
state
.
action
best_action
=
state
.
action
...
@@ -142,7 +142,7 @@ class StateMap(object):
...
@@ -142,7 +142,7 @@ class StateMap(object):
Convert a set of states into a uniquified
Convert a set of states into a uniquified
sorted tuple suitable for use as a dictionary key.
sorted tuple suitable for use as a dictionary key.
"""
"""
lst
=
state_set
.
keys
(
)
lst
=
list
(
state_set
)
lst
.
sort
()
lst
.
sort
()
return
tuple
(
lst
)
return
tuple
(
lst
)
...
...
Cython/Plex/Machines.py
View file @
df9b6431
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#
#
#=======================================================================
#=======================================================================
import
string
import
sys
import
sys
from
sys
import
maxint
from
sys
import
maxint
from
types
import
TupleType
from
types
import
TupleType
...
@@ -54,7 +53,7 @@ class Machine(object):
...
@@ -54,7 +53,7 @@ class Machine(object):
file
.
write
(
"Plex.Machine:
\
n
"
)
file
.
write
(
"Plex.Machine:
\
n
"
)
if
self
.
initial_states
is
not
None
:
if
self
.
initial_states
is
not
None
:
file
.
write
(
" Initial states:
\
n
"
)
file
.
write
(
" Initial states:
\
n
"
)
for
(
name
,
state
)
in
self
.
initial_states
.
items
():
for
(
name
,
state
)
in
self
.
initial_states
.
ite
rite
ms
():
file
.
write
(
" '%s': %d
\
n
"
%
(
name
,
state
.
number
))
file
.
write
(
" '%s': %d
\
n
"
%
(
name
,
state
.
number
))
for
s
in
self
.
states
:
for
s
in
self
.
states
:
s
.
dump
(
file
)
s
.
dump
(
file
)
...
@@ -108,7 +107,6 @@ class Node(object):
...
@@ -108,7 +107,6 @@ class Node(object):
return
"State %d"
%
self
.
number
return
"State %d"
%
self
.
number
def
dump
(
self
,
file
):
def
dump
(
self
,
file
):
import
string
# Header
# Header
file
.
write
(
" State %d:
\
n
"
%
self
.
number
)
file
.
write
(
" State %d:
\
n
"
%
self
.
number
)
# Transitions
# Transitions
...
@@ -143,11 +141,11 @@ class FastMachine(object):
...
@@ -143,11 +141,11 @@ class FastMachine(object):
for
old_state
in
old_machine
.
states
:
for
old_state
in
old_machine
.
states
:
new_state
=
self
.
new_state
()
new_state
=
self
.
new_state
()
old_to_new
[
old_state
]
=
new_state
old_to_new
[
old_state
]
=
new_state
for
name
,
old_state
in
old_machine
.
initial_states
.
items
():
for
name
,
old_state
in
old_machine
.
initial_states
.
ite
rite
ms
():
initial_states
[
name
]
=
old_to_new
[
old_state
]
initial_states
[
name
]
=
old_to_new
[
old_state
]
for
old_state
in
old_machine
.
states
:
for
old_state
in
old_machine
.
states
:
new_state
=
old_to_new
[
old_state
]
new_state
=
old_to_new
[
old_state
]
for
event
,
old_state_set
in
old_state
.
transitions
.
items
():
for
event
,
old_state_set
in
old_state
.
transitions
.
ite
rite
ms
():
if
old_state_set
:
if
old_state_set
:
new_state
[
event
]
=
old_to_new
[
old_state_set
.
keys
()[
0
]]
new_state
[
event
]
=
old_to_new
[
old_state_set
.
keys
()[
0
]]
else
:
else
:
...
@@ -188,13 +186,12 @@ class FastMachine(object):
...
@@ -188,13 +186,12 @@ class FastMachine(object):
def
dump
(
self
,
file
):
def
dump
(
self
,
file
):
file
.
write
(
"Plex.FastMachine:
\
n
"
)
file
.
write
(
"Plex.FastMachine:
\
n
"
)
file
.
write
(
" Initial states:
\
n
"
)
file
.
write
(
" Initial states:
\
n
"
)
for
name
,
state
in
self
.
initial_states
.
items
():
for
name
,
state
in
self
.
initial_states
.
ite
rite
ms
():
file
.
write
(
" %s: %s
\
n
"
%
(
repr
(
name
),
state
[
'number'
]))
file
.
write
(
" %s: %s
\
n
"
%
(
repr
(
name
),
state
[
'number'
]))
for
state
in
self
.
states
:
for
state
in
self
.
states
:
self
.
dump_state
(
state
,
file
)
self
.
dump_state
(
state
,
file
)
def
dump_state
(
self
,
state
,
file
):
def
dump_state
(
self
,
state
,
file
):
import
string
# Header
# Header
file
.
write
(
" State %d:
\
n
"
%
state
[
'number'
])
file
.
write
(
" State %d:
\
n
"
%
state
[
'number'
])
# Transitions
# Transitions
...
@@ -207,7 +204,7 @@ class FastMachine(object):
...
@@ -207,7 +204,7 @@ class FastMachine(object):
def
dump_transitions
(
self
,
state
,
file
):
def
dump_transitions
(
self
,
state
,
file
):
chars_leading_to_state
=
{}
chars_leading_to_state
=
{}
special_to_state
=
{}
special_to_state
=
{}
for
(
c
,
s
)
in
state
.
items
():
for
(
c
,
s
)
in
state
.
ite
rite
ms
():
if
len
(
c
)
==
1
:
if
len
(
c
)
==
1
:
chars
=
chars_leading_to_state
.
get
(
id
(
s
),
None
)
chars
=
chars_leading_to_state
.
get
(
id
(
s
),
None
)
if
chars
is
None
:
if
chars
is
None
:
...
@@ -249,7 +246,7 @@ class FastMachine(object):
...
@@ -249,7 +246,7 @@ class FastMachine(object):
return
tuple
(
result
)
return
tuple
(
result
)
def
ranges_to_string
(
self
,
range_list
):
def
ranges_to_string
(
self
,
range_list
):
return
string
.
join
(
map
(
self
.
range_to_string
,
range_list
),
","
)
return
','
.
join
(
map
(
self
.
range_to_string
,
range_list
)
)
def
range_to_string
(
self
,
range_tuple
):
def
range_to_string
(
self
,
range_tuple
):
(
c1
,
c2
)
=
range_tuple
(
c1
,
c2
)
=
range_tuple
...
...
Cython/Plex/Regexps.py
View file @
df9b6431
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
#=======================================================================
#=======================================================================
import
array
import
array
import
string
import
types
import
types
from
sys
import
maxint
from
sys
import
maxint
...
@@ -330,7 +329,7 @@ class Seq(RE):
...
@@ -330,7 +329,7 @@ class Seq(RE):
match_bol
=
re
.
match_nl
or
(
match_bol
and
re
.
nullable
)
match_bol
=
re
.
match_nl
or
(
match_bol
and
re
.
nullable
)
def
calc_str
(
self
):
def
calc_str
(
self
):
return
"Seq(%s)"
%
string
.
join
(
map
(
str
,
self
.
re_list
),
","
)
return
"Seq(%s)"
%
','
.
join
(
map
(
str
,
self
.
re_list
)
)
class
Alt
(
RE
):
class
Alt
(
RE
):
...
@@ -369,7 +368,7 @@ class Alt(RE):
...
@@ -369,7 +368,7 @@ class Alt(RE):
re
.
build_machine
(
m
,
initial_state
,
final_state
,
0
,
nocase
)
re
.
build_machine
(
m
,
initial_state
,
final_state
,
0
,
nocase
)
def
calc_str
(
self
):
def
calc_str
(
self
):
return
"Alt(%s)"
%
string
.
join
(
map
(
str
,
self
.
re_list
),
","
)
return
"Alt(%s)"
%
','
.
join
(
map
(
str
,
self
.
re_list
)
)
class
Rep1
(
RE
):
class
Rep1
(
RE
):
...
@@ -437,7 +436,7 @@ def Str1(s):
...
@@ -437,7 +436,7 @@ def Str1(s):
"""
"""
Str1(s) is an RE which matches the literal string |s|.
Str1(s) is an RE which matches the literal string |s|.
"""
"""
result
=
apply
(
Seq
,
tuple
(
map
(
Char
,
s
)))
result
=
Seq
(
*
tuple
(
map
(
Char
,
s
)))
result
.
str
=
"Str(%s)"
%
repr
(
s
)
result
.
str
=
"Str(%s)"
%
repr
(
s
)
return
result
return
result
...
@@ -449,8 +448,8 @@ def Str(*strs):
...
@@ -449,8 +448,8 @@ def Str(*strs):
if
len
(
strs
)
==
1
:
if
len
(
strs
)
==
1
:
return
Str1
(
strs
[
0
])
return
Str1
(
strs
[
0
])
else
:
else
:
result
=
apply
(
Alt
,
tuple
(
map
(
Str1
,
strs
)))
result
=
Alt
(
*
tuple
(
map
(
Str1
,
strs
)))
result
.
str
=
"Str(%s)"
%
string
.
join
(
map
(
repr
,
strs
),
","
)
result
.
str
=
"Str(%s)"
%
','
.
join
(
map
(
repr
,
strs
)
)
return
result
return
result
def
Any
(
s
):
def
Any
(
s
):
...
@@ -495,7 +494,7 @@ def Range(s1, s2 = None):
...
@@ -495,7 +494,7 @@ def Range(s1, s2 = None):
ranges
=
[]
ranges
=
[]
for
i
in
range
(
0
,
len
(
s1
),
2
):
for
i
in
range
(
0
,
len
(
s1
),
2
):
ranges
.
append
(
CodeRange
(
ord
(
s1
[
i
]),
ord
(
s1
[
i
+
1
])
+
1
))
ranges
.
append
(
CodeRange
(
ord
(
s1
[
i
]),
ord
(
s1
[
i
+
1
])
+
1
))
result
=
apply
(
Alt
,
tuple
(
ranges
)
)
result
=
Alt
(
*
ranges
)
result
.
str
=
"Range(%s)"
%
repr
(
s1
)
result
.
str
=
"Range(%s)"
%
repr
(
s1
)
return
result
return
result
...
...
Cython/Plex/Traditional.py
View file @
df9b6431
...
@@ -41,7 +41,7 @@ class REParser(object):
...
@@ -41,7 +41,7 @@ class REParser(object):
while
self
.
c
==
'|'
:
while
self
.
c
==
'|'
:
self
.
next
()
self
.
next
()
re_list
.
append
(
self
.
parse_seq
())
re_list
.
append
(
self
.
parse_seq
())
re
=
apply
(
Alt
,
tuple
(
re_list
)
)
re
=
Alt
(
*
re_list
)
return
re
return
re
def
parse_seq
(
self
):
def
parse_seq
(
self
):
...
@@ -49,7 +49,7 @@ class REParser(object):
...
@@ -49,7 +49,7 @@ class REParser(object):
re_list
=
[]
re_list
=
[]
while
not
self
.
end
and
not
self
.
c
in
"|)"
:
while
not
self
.
end
and
not
self
.
c
in
"|)"
:
re_list
.
append
(
self
.
parse_mod
())
re_list
.
append
(
self
.
parse_mod
())
return
apply
(
Seq
,
tuple
(
re_list
)
)
return
Seq
(
*
re_list
)
def
parse_mod
(
self
):
def
parse_mod
(
self
):
"""Parse a primitive regexp followed by *, +, ? modifiers."""
"""Parse a primitive regexp followed by *, +, ? modifiers."""
...
...
Cython/Plex/Transitions.py
View file @
df9b6431
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#
#
from
copy
import
copy
from
copy
import
copy
import
string
from
sys
import
maxint
from
sys
import
maxint
from
types
import
TupleType
from
types
import
TupleType
...
@@ -89,10 +88,10 @@ class TransitionMap(object):
...
@@ -89,10 +88,10 @@ class TransitionMap(object):
"""
"""
return
self
.
special
.
get
(
''
,
none
)
return
self
.
special
.
get
(
''
,
none
)
def
items
(
self
,
def
ite
rite
ms
(
self
,
len
=
len
):
len
=
len
):
"""
"""
Return the mapping as a
list
of ((code1, code2), state_set) and
Return the mapping as a
n iterable
of ((code1, code2), state_set) and
(special_event, state_set) pairs.
(special_event, state_set) pairs.
"""
"""
result
=
[]
result
=
[]
...
@@ -108,10 +107,10 @@ class TransitionMap(object):
...
@@ -108,10 +107,10 @@ class TransitionMap(object):
result
.
append
(((
code0
,
code1
),
set
))
result
.
append
(((
code0
,
code1
),
set
))
code0
=
code1
code0
=
code1
i
=
i
+
2
i
=
i
+
2
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
if
set
:
if
set
:
result
.
append
((
event
,
set
))
result
.
append
((
event
,
set
))
return
result
return
iter
(
result
)
# ------------------- Private methods --------------------
# ------------------- Private methods --------------------
...
@@ -178,10 +177,10 @@ class TransitionMap(object):
...
@@ -178,10 +177,10 @@ class TransitionMap(object):
map_strs
.
append
(
state_set_str
(
map
[
i
]))
map_strs
.
append
(
state_set_str
(
map
[
i
]))
i
=
i
+
1
i
=
i
+
1
special_strs
=
{}
special_strs
=
{}
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
special_strs
[
event
]
=
state_set_str
(
set
)
special_strs
[
event
]
=
state_set_str
(
set
)
return
"[%s]+%s"
%
(
return
"[%s]+%s"
%
(
string
.
join
(
map_strs
,
","
),
','
.
join
(
map_strs
),
special_strs
special_strs
)
)
...
@@ -200,7 +199,7 @@ class TransitionMap(object):
...
@@ -200,7 +199,7 @@ class TransitionMap(object):
while
i
<
n
:
while
i
<
n
:
self
.
dump_range
(
map
[
i
],
map
[
i
+
2
],
map
[
i
+
1
],
file
)
self
.
dump_range
(
map
[
i
],
map
[
i
+
2
],
map
[
i
+
1
],
file
)
i
=
i
+
2
i
=
i
+
2
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
if
set
:
if
set
:
if
not
event
:
if
not
event
:
event
=
'empty'
event
=
'empty'
...
@@ -243,11 +242,7 @@ class TransitionMap(object):
...
@@ -243,11 +242,7 @@ class TransitionMap(object):
# set1[state] = 1
# set1[state] = 1
def
state_set_str
(
set
):
def
state_set_str
(
set
):
state_list
=
set
.
keys
()
return
"[%s]"
%
','
.
join
([
"S%d"
%
state
.
number
for
state
in
set
])
str_list
=
[]
for
state
in
state_list
:
str_list
.
append
(
"S%d"
%
state
.
number
)
return
"[%s]"
%
string
.
join
(
str_list
,
","
)
Cython/Shadow.py
View file @
df9b6431
...
@@ -57,12 +57,12 @@ class PointerType(CythonType):
...
@@ -57,12 +57,12 @@ class PointerType(CythonType):
def
__getitem__
(
self
,
ix
):
def
__getitem__
(
self
,
ix
):
if
ix
<
0
:
if
ix
<
0
:
raise
IndexError
,
"negative indexing not allowed in C"
raise
IndexError
(
"negative indexing not allowed in C"
)
return
self
.
_items
[
ix
]
return
self
.
_items
[
ix
]
def
__setitem__
(
self
,
ix
,
value
):
def
__setitem__
(
self
,
ix
,
value
):
if
ix
<
0
:
if
ix
<
0
:
raise
IndexError
,
"negative indexing not allowed in C"
raise
IndexError
(
"negative indexing not allowed in C"
)
self
.
_items
[
ix
]
=
cast
(
self
.
_basetype
,
value
)
self
.
_items
[
ix
]
=
cast
(
self
.
_basetype
,
value
)
class
ArrayType
(
PointerType
):
class
ArrayType
(
PointerType
):
...
@@ -74,22 +74,22 @@ class ArrayType(PointerType):
...
@@ -74,22 +74,22 @@ class ArrayType(PointerType):
class
StructType
(
CythonType
):
class
StructType
(
CythonType
):
def
__init__
(
self
,
**
data
):
def
__init__
(
self
,
**
data
):
for
key
,
value
in
data
.
items
():
for
key
,
value
in
data
.
ite
rite
ms
():
setattr
(
self
,
key
,
value
)
setattr
(
self
,
key
,
value
)
def
__setattr__
(
self
,
key
,
value
):
def
__setattr__
(
self
,
key
,
value
):
if
key
in
self
.
_members
:
if
key
in
self
.
_members
:
self
.
__dict__
[
key
]
=
cast
(
self
.
_members
[
key
],
value
)
self
.
__dict__
[
key
]
=
cast
(
self
.
_members
[
key
],
value
)
else
:
else
:
raise
AttributeError
,
"Struct has no member '%s'"
%
key
raise
AttributeError
(
"Struct has no member '%s'"
%
key
)
class
UnionType
(
CythonType
):
class
UnionType
(
CythonType
):
def
__init__
(
self
,
**
data
):
def
__init__
(
self
,
**
data
):
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
raise
AttributeError
,
"Union can only store one field at a time."
raise
AttributeError
(
"Union can only store one field at a time."
)
for
key
,
value
in
data
.
items
():
for
key
,
value
in
data
.
ite
rite
ms
():
setattr
(
self
,
key
,
value
)
setattr
(
self
,
key
,
value
)
def
__setattr__
(
self
,
key
,
value
):
def
__setattr__
(
self
,
key
,
value
):
...
@@ -98,7 +98,7 @@ class UnionType(CythonType):
...
@@ -98,7 +98,7 @@ class UnionType(CythonType):
elif
key
in
self
.
_members
:
elif
key
in
self
.
_members
:
self
.
__dict__
=
{
key
:
cast
(
self
.
_members
[
key
],
value
)}
self
.
__dict__
=
{
key
:
cast
(
self
.
_members
[
key
],
value
)}
else
:
else
:
raise
AttributeError
,
"Union has no member '%s'"
%
key
raise
AttributeError
(
"Union has no member '%s'"
%
key
)
def
pointer
(
basetype
):
def
pointer
(
basetype
):
class
PointerInstance
(
PointerType
):
class
PointerInstance
(
PointerType
):
...
@@ -114,14 +114,14 @@ def array(basetype, n):
...
@@ -114,14 +114,14 @@ def array(basetype, n):
def
struct
(
**
members
):
def
struct
(
**
members
):
class
StructInstance
(
StructType
):
class
StructInstance
(
StructType
):
_members
=
members
_members
=
members
for
key
in
members
.
keys
()
:
for
key
in
members
:
setattr
(
StructInstance
,
key
,
None
)
setattr
(
StructInstance
,
key
,
None
)
return
StructInstance
return
StructInstance
def
union
(
**
members
):
def
union
(
**
members
):
class
UnionInstance
(
UnionType
):
class
UnionInstance
(
UnionType
):
_members
=
members
_members
=
members
for
key
in
members
.
keys
()
:
for
key
in
members
:
setattr
(
UnionInstance
,
key
,
None
)
setattr
(
UnionInstance
,
key
,
None
)
return
UnionInstance
return
UnionInstance
...
...
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