Class: ParseTreeMatch
Overview
Represents the result of matching a ParseTree against a tree pattern.
Instance Attribute Summary collapse
-
#labels ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
-
#mismatchedNode ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
-
#pattern ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
-
#tree ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
Instance Method Summary collapse
-
#get(label) ⇒ Object
Get the last node associated with a specific label.
-
#getAll(label) ⇒ Object
Return all nodes matching a rule or token tag with the specified label.
-
#initialize(tree, pattern, labels, mismatchedNode) ⇒ ParseTreeMatch
constructor
A new instance of ParseTreeMatch.
-
#succeeded ⇒ @code true
Gets a value indicating whether the match operation succeeded.
-
#to_s ⇒ Object
@inheritDoc.
Constructor Details
#initialize(tree, pattern, labels, mismatchedNode) ⇒ ParseTreeMatch
Returns a new instance of ParseTreeMatch.
19 20 21 22 23 24 25 26 27 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 19 def initialize(tree, pattern, labels, mismatchedNode) raise Exception.new("tree cannot be null") if tree.nil? raise Exception.new("pattern cannot be null") if pattern.nil? raise Exception.new("labels cannot be null") if labels.nil? self.tree = tree self.pattern = pattern self.labels = labels self.mismatchedNode = mismatchedNode end |
Instance Attribute Details
#labels ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
ParseTree objects located by the tree pattern matching process. pattern during the matching process.
18 19 20 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 18 def labels @labels end |
#mismatchedNode ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
ParseTree objects located by the tree pattern matching process. pattern during the matching process.
18 19 20 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 18 def mismatchedNode @mismatchedNode end |
#pattern ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
ParseTree objects located by the tree pattern matching process. pattern during the matching process.
18 19 20 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 18 def pattern @pattern end |
#tree ⇒ Object
Constructs a new instance of ParseTreeMatch from the specified parse tree and pattern.
ParseTree objects located by the tree pattern matching process. pattern during the matching process.
18 19 20 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 18 def tree @tree end |
Instance Method Details
#get(label) ⇒ Object
Get the last node associated with a specific label.
<p>For example, for pattern <id:ID>, get(“id”) returns the node matched for that ID. If more than one node matched the specified label, only the last is returned. If there is no node associated with the label, this returns null.</p>
<p>Pattern tags like <ID> and <expr> without labels are considered to be labeled with ID and expr, respectively.</p>
label, or null if no parse tree matched a tag with the label.
44 45 46 47 48 49 50 51 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 44 def get(label) parseTrees = self.labels.get(label, nil) if parseTrees.nil? or parseTrees.empty? then return nil else return parseTrees[-1] end end |
#getAll(label) ⇒ Object
Return all nodes matching a rule or token tag with the specified label.
<p>If the label is the name of a parser rule or token in the grammar, the resulting list will contain both the parse trees matching rule or tags explicitly labeled with the label and the complete set of parse trees matching the labeled and unlabeled tags in the pattern for the parser rule or token. For example, if label is “foo”, the result will contain all of the following.</p>
<ul> <li>Parse tree nodes matching tags of the form <foo:anyRuleName> and <foo:AnyTokenName>.</li> <li>Parse tree nodes matching tags of the form <anyLabel:foo>.</li> <li>Parse tree nodes matching tags of the form <foo>.</li> </ul>
the specified label. If no nodes matched the label, an empty list is returned.
75 76 77 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 75 def getAll(label) self.labels.get(label, Array.new) end |
#succeeded ⇒ @code true
Gets a value indicating whether the match operation succeeded.
false.
85 86 87 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 85 def succeeded return self.mismatchedNode.nil? end |
#to_s ⇒ Object
@inheritDoc
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/antlr4/tree/ParseTreeMatch.rb', line 91 def to_s StringIO.open do |buf| buf.write("Match ") if self.succeeded() buf.write("succeeded") else buf.write("failed") end buf.write("; found ") buf.write(self.labels.length.to_s) buf.write(" labels") return buf.string end end |