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
749cc80e
Commit
749cc80e
authored
Sep 18, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
somewhat hackish fix for supporting not() in TreePath - needs to be reconsidered ...
parent
42ea77b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
Cython/Compiler/Tests/TestTreePath.py
Cython/Compiler/Tests/TestTreePath.py
+5
-0
Cython/Compiler/TreePath.py
Cython/Compiler/TreePath.py
+4
-4
No files found.
Cython/Compiler/Tests/TestTreePath.py
View file @
749cc80e
...
@@ -38,6 +38,11 @@ class TestTreePath(TransformTest):
...
@@ -38,6 +38,11 @@ class TestTreePath(TransformTest):
t
=
self
.
_build_tree
()
t
=
self
.
_build_tree
()
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode[@name]"
)))
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode[@name]"
)))
def
test_node_path_attribute_exists_not
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
0
,
len
(
find_all
(
t
,
"//NameNode[not(@name)]"
)))
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode[not(@honking)]"
)))
def
test_node_path_attribute_string_predicate
(
self
):
def
test_node_path_attribute_string_predicate
(
self
):
t
=
self
.
_build_tree
()
t
=
self
.
_build_tree
()
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//NameNode[@name = 'decorator']"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//NameNode[@name = 'decorator']"
)))
...
...
Cython/Compiler/TreePath.py
View file @
749cc80e
...
@@ -49,7 +49,7 @@ def parse_func(next, token):
...
@@ -49,7 +49,7 @@ def parse_func(next, token):
token = next()
token = next()
if token[0] != '(':
if token[0] != '(':
raise ValueError("
Expected
'('
after
function
name
'%s'" % name)
raise ValueError("
Expected
'('
after
function
name
'%s'" % name)
predicate = handle_predicate(next, token
, end_marker=')'
)
predicate = handle_predicate(next, token)
return name, predicate
return name, predicate
def handle_func_not(next, token):
def handle_func_not(next, token):
...
@@ -60,7 +60,7 @@ def handle_func_not(next, token):
...
@@ -60,7 +60,7 @@ def handle_func_not(next, token):
def select(result):
def select(result):
for node in result:
for node in result:
if _get_first_or_none(predicate(
node)) is not
None:
if _get_first_or_none(predicate(
[node])) is
None:
yield node
yield node
return select
return select
...
@@ -176,10 +176,10 @@ def parse_path_value(next):
...
@@ -176,10 +176,10 @@ def parse_path_value(next):
raise ValueError("
Invalid
attribute
predicate
:
'%s'" % value)
raise ValueError("
Invalid
attribute
predicate
:
'%s'" % value)
return value
return value
def handle_predicate(next, token
, end_marker=']'
):
def handle_predicate(next, token):
token = next()
token = next()
selector = []
selector = []
while token[0] !=
end_marker
:
while token[0] !=
']'
:
selector.append( operations[token[0]](next, token) )
selector.append( operations[token[0]](next, token) )
try:
try:
token = next()
token = next()
...
...
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