-
-
Save yorickpeterse/597c8504e6f71c5c1a48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby /tmp/viz.rb | |
def on_test(ast_node, context) | ast_node = "(test nil \"foo\")" | |
nodes = XML::NodeSet.new | context = "(something ...)" | |
predicate = ast_node.children[2] | | |
xpath_index = 1 | | |
| | |
context.each do |xml_node| | | |
next unless node_matches?(xml_node, ast_node) | | |
| | |
if predicate | | |
retval = with_node_set(context) do | | |
process(predicate, XML::NodeSet.new([xml_node])) | | |
end | | |
| | |
# Numeric values are used as node set indexes. | | |
if retval.is_a?(Numeric) | | |
nodes << xml_node if retval.to_i == xpath_index | | |
| | |
# Node sets, strings, booleans, etc | | |
elsif retval | | |
if retval.respond_to?(:empty?) and retval.empty? | | |
next | | |
end | | |
| | |
nodes << xml_node | | |
end | | |
else | | |
nodes << xml_node | | |
end | | |
| | |
xpath_index += 1 | | |
end | | |
| | |
return nodes | | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment