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
67c43e52
Commit
67c43e52
authored
Mar 17, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support simple name substitution from the Naming module in utility code sections
parent
c9c4ba98
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+14
-3
No files found.
Cython/Compiler/Code.py
View file @
67c43e52
...
@@ -12,6 +12,7 @@ cython.declare(os=object, re=object, operator=object,
...
@@ -12,6 +12,7 @@ cython.declare(os=object, re=object, operator=object,
import
os
import
os
import
re
import
re
import
sys
import
sys
from
string
import
Template
import
operator
import
operator
import
Naming
import
Naming
...
@@ -60,6 +61,7 @@ class UtilityCodeBase(object):
...
@@ -60,6 +61,7 @@ class UtilityCodeBase(object):
##### MyUtility #####
##### MyUtility #####
#@requires: MyOtherUtility
#@requires: MyOtherUtility
#@substitute: naming
for prototypes and implementation respectively. For non-python or
for prototypes and implementation respectively. For non-python or
-cython files backslashes should be used instead. 5 to 30 comment
-cython files backslashes should be used instead. 5 to 30 comment
...
@@ -79,8 +81,17 @@ class UtilityCodeBase(object):
...
@@ -79,8 +81,17 @@ class UtilityCodeBase(object):
if
utility
is
None
:
if
utility
is
None
:
return
return
# remember correct line numbers as least until after templating
code
=
'
\
n
'
.
join
(
lines
)
code
=
'
\
n
'
*
begin_lineno
+
'
\
n
'
.
join
(
lines
)
if
tags
and
'substitute'
in
tags
and
tags
[
'substitute'
]
==
set
([
'naming'
]):
del
tags
[
'substitute'
]
try
:
code
=
Template
(
code
).
substitute
(
vars
(
Naming
))
except
(
KeyError
,
ValueError
),
e
:
raise
RuntimeError
(
"Error parsing templated utility code of type '%s' at line %d: %s"
%
(
type
,
begin_lineno
,
e
))
# remember correct line numbers at least until after templating
code
=
'
\
n
'
*
begin_lineno
+
code
if
type
==
'proto'
:
if
type
==
'proto'
:
utility
[
0
]
=
code
utility
[
0
]
=
code
...
@@ -115,7 +126,7 @@ class UtilityCodeBase(object):
...
@@ -115,7 +126,7 @@ class UtilityCodeBase(object):
replace_comments = re.compile(r'
^
\
s
*//
.
*|^
\
s
*/
\
*
[
^*
]
*
\
*/
').sub
replace_comments = re.compile(r'
^
\
s
*//
.
*|^
\
s
*/
\
*
[
^*
]
*
\
*/
').sub
match_special = re.compile(
match_special = re.compile(
(r'
^%
(
C
)
s
{
5
,
30
}
\
s
*
(
?
P
<
name
>
(
?
:
\
w
|
\
.)
+
)
\
s
*%
(
C
)
s
{
5
,
30
}
|
'
(r'
^%
(
C
)
s
{
5
,
30
}
\
s
*
(
?
P
<
name
>
(
?
:
\
w
|
\
.)
+
)
\
s
*%
(
C
)
s
{
5
,
30
}
|
'
r'
^%
(
C
)
s
+@
(
?
P
<
tag
>
requires
)
\
s
*
:
\
s
*
(
?
P
<
value
>
(
?
:
\
w
|
[.:])
+
)
' # add more tag names here at need
r'
^%
(
C
)
s
+@
(
?
P
<
tag
>
\
w
+
)
\
s
*
:
\
s
*
(
?
P
<
value
>
(
?
:
\
w
|
[.:])
+
)
' # add more tag names here at need
) % {'
C
':comment}).match
) % {'
C
':comment}).match
match_type = re.compile('
(.
+
)[.](
proto
|
impl
|
init
|
cleanup
)
$
').match
match_type = re.compile('
(.
+
)[.](
proto
|
impl
|
init
|
cleanup
)
$
').match
...
...
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