Class: ParseTreePattern

Inherits:
Object show all
Defined in:
lib/antlr4/tree/ParseTreePattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#matcherObject

Construct a new instance of the ParseTreePattern class.

tree pattern. tree pattern.

Parameters:

  • matcher

    The ParseTreePatternMatcher which created this

  • pattern

    The tree pattern in concrete syntax form.

  • patternRuleIndex

    The parser rule which serves as the root of the

  • patternTree

    The tree pattern in ParseTree form.



20
21
22
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20

def matcher
  @matcher
end

#patternObject

Construct a new instance of the ParseTreePattern class.

tree pattern. tree pattern.

Parameters:

  • matcher

    The ParseTreePatternMatcher which created this

  • pattern

    The tree pattern in concrete syntax form.

  • patternRuleIndex

    The parser rule which serves as the root of the

  • patternTree

    The tree pattern in ParseTree form.



20
21
22
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20

def pattern
  @pattern
end

#patternRuleIndexObject

Construct a new instance of the ParseTreePattern class.

tree pattern. tree pattern.

Parameters:

  • matcher

    The ParseTreePatternMatcher which created this

  • pattern

    The tree pattern in concrete syntax form.

  • patternRuleIndex

    The parser rule which serves as the root of the

  • patternTree

    The tree pattern in ParseTree form.



20
21
22
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 20

def patternRuleIndex
  @patternRuleIndex
end

#patternTreeObject

Construct a new instance of the ParseTreePattern class.

tree pattern. tree pattern.

Parameters:

  • matcher

    The ParseTreePatternMatcher which created this

  • pattern

    The tree pattern in concrete syntax form.

  • patternRuleIndex

    The parser rule which serves as the root of the

  • patternTree

    The tree pattern in ParseTree form.



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.

Parameters:

  • tree

    The ParseTree to match against this pattern.

  • xpath

    An expression matching the nodes

Returns:

  • A collection of ParseTreeMatch objects describing the



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.

Parameters:

  • tree

    The parse tree to match against this tree pattern.



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.

Parameters:

  • tree

    The parse tree to match against this tree pattern.

Returns:

  • (@code true)

    if tree is a match for the current tree



47
48
49
# File 'lib/antlr4/tree/ParseTreePattern.rb', line 47

def matches(tree)
    return self.matcher.match(tree, self).succeeded()
end