Class: ParseTreePattern
Instance Attribute Summary collapse
-
#matcher ⇒ Object
Construct a new instance of the ParseTreePattern class.
-
#pattern ⇒ Object
Construct a new instance of the ParseTreePattern class.
-
#patternRuleIndex ⇒ Object
Construct a new instance of the ParseTreePattern class.
-
#patternTree ⇒ Object
Construct a new instance of the ParseTreePattern class.
Instance Method Summary collapse
-
#findAll(tree, xpath) ⇒ Object
Find all nodes using XPath and then try to match those subtrees against this tree pattern.
-
#initialize(matcher, pattern, patternRuleIndex, patternTree) ⇒ ParseTreePattern
constructor
A new instance of ParseTreePattern.
-
#match(tree) ⇒ Object
Match a specific parse tree against this tree pattern.
-
#matches(tree) ⇒ @code true
Determine whether or not a parse tree matches this tree pattern.
Constructor Details
#initialize(matcher, pattern, patternRuleIndex, patternTree) ⇒ ParseTreePattern
Returns a new instance of ParseTreePattern.
21 22 23 24 25 26 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 21 def initialize(matcher, pattern, patternRuleIndex, patternTree) self.matcher = matcher self.patternRuleIndex = patternRuleIndex self.pattern = pattern self.patternTree = patternTree end |
Instance Attribute Details
#matcher ⇒ Object
Construct a new instance of the ParseTreePattern class.
tree pattern. tree pattern.
20 21 22 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20 def matcher @matcher end |
#pattern ⇒ Object
Construct a new instance of the ParseTreePattern class.
tree pattern. tree pattern.
20 21 22 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20 def pattern @pattern end |
#patternRuleIndex ⇒ Object
Construct a new instance of the ParseTreePattern class.
tree pattern. tree pattern.
20 21 22 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20 def patternRuleIndex @patternRuleIndex end |
#patternTree ⇒ Object
Construct a new instance of the ParseTreePattern class.
tree pattern. tree pattern.
20 21 22 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20 def patternTree @patternTree end |
Instance Method Details
#findAll(tree, xpath) ⇒ Object
Find all nodes using XPath and then try to match those subtrees against this tree pattern.
successful matches. Unsuccessful matches are omitted from the result, regardless of the reason for the failure.
61 62 63 64 65 66 67 68 69 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 61 def findAll(tree, xpath) subtrees = XPath.findAll(tree, xpath, self.matcher.parser) subtrees.map do |t| match = self.match(t) if match.succeeded() then match end end.compact end |
#match(tree) ⇒ Object
Match a specific parse tree against this tree pattern.
match operation. The ParseTreeMatch#succeeded() method can be used to determine whether or not the match was successful.
36 37 38 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 36 def match(tree) return self.matcher.match(tree, self) end |
#matches(tree) ⇒ @code true
Determine whether or not a parse tree matches this tree pattern.
pattern; otherwise, false.
47 48 49 |
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 47 def matches(tree) return self.matcher.match(tree, self).succeeded() end |