class SexpPath::Matcher::Base
This is the base class for all Sexp
matchers.
A matcher should implement the following methods:
-
satisfy?
-
inspect
satisfy?
determines whether the matcher matches a given input, and inspect
will print the matcher nicely in a user’s console.
The base matcher is created with the SexpQueryBuilder as follows
Q?{ s() }
Public Instance Methods
&(o)
click to toggle source
Combines the Matcher with another Matcher, the resulting one will be satisfied only if both Matchers would be satisfied.
Example:
t(:a) & include(:b)
# File lib/sexp_path/matcher/base.rb, line 28 def & o SexpPath::Matcher::All.new(self, o) end
-@()
click to toggle source
Returns a Matcher that matches whenever this Matcher would not have matched
Example:
-s(:a)
# File lib/sexp_path/matcher/base.rb, line 36 def -@ SexpPath::Matcher::Not.new(self) end
>>(o)
click to toggle source
Returns a Matcher that matches if this has a sibling o
Example:
s(:a) >> s(:b)
# File lib/sexp_path/matcher/base.rb, line 44 def >> o SexpPath::Matcher::Sibling.new(self, o) end
greedy?()
click to toggle source
# File lib/sexp_path/matcher/base.rb, line 48 def greedy? false end
inspect()
click to toggle source
Formats the matcher as:
q(:a, :b)
# File lib/sexp_path/matcher/base.rb, line 54 def inspect children = map{|e| e.inspect}.join(', ') "q(#{children})" end
|(o)
click to toggle source
Combines the Matcher with another Matcher, the resulting one will be satisfied if either Matcher would be satisfied.
Example:
s(:a) | s(:b)
# File lib/sexp_path/matcher/base.rb, line 19 def | o SexpPath::Matcher::Any.new(self, o) end