Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created November 11, 2014 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickpeterse/597c8504e6f71c5c1a48 to your computer and use it in GitHub Desktop.
Save yorickpeterse/597c8504e6f71c5c1a48 to your computer and use it in GitHub Desktop.
$ 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