Module: Synvert::Core::NodeQuery
- Defined in:
- lib/synvert/core/node_query.rb,
lib/synvert/core/node_query/parser.racc.rb
Overview
NodeQuery defines a node query language, which is a css like syntax for matching nodes.
It supports the following selectors:
-
AST node type:
.class
,.send
-
attribute value: [receiver = nil], [message = create]
-
attribute regex:
[key=~/\A:([^'"]+)\z/]
,[key!~/\A:([^'"]+)\z/]
-
attribute conditions: [message != nil], [value > 1], [value >= 1], [value < 1], [value <= 1]
-
nested attribute: [caller.message = map], [arguments.size = 2]
-
first or last child:
.def:first-child
,.send:last-child
-
nth-child or nth-last-child: .def:nth-child(2), .send:nth-last-child(2)
-
descendant: .class .send
-
child: .class > .def
-
following sibling:
.def:first-child + .def
-
subsequnt sibling: .def:first-child ~ .def
-
has: .class:has(.def)
It also supports some custom selectors:
-
nested selector: .send[arguments = [size = 2][first = .sym][last = .hash]]
-
array value: .send[arguments = (a, b)]
-
IN operator: .send[message IN (try, try!)]
-
NOT IN operator: .send[message NOT IN (create, build)]
-
INCLUDES operator: .send[arguments INCLUDES &block]
-
dynamic attribute value: .hash > .pair