/*! * Copyright 2016 The ANTLR Project. All rights reserved. * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information. */ import { MultiMap } from "../../misc/MultiMap"; import { ParseTree } from "../ParseTree"; import { ParseTreePattern } from "./ParseTreePattern"; /** * Represents the result of matching a {@link ParseTree} against a tree pattern. */ export declare class ParseTreeMatch { /** * This is the backing field for `tree`. */ private _tree; /** * This is the backing field for `pattern`. */ private _pattern; /** * This is the backing field for `labels`. */ private _labels; /** * This is the backing field for `mismatchedNode`. */ private _mismatchedNode?; /** * Constructs a new instance of {@link ParseTreeMatch} from the specified * parse tree and pattern. * * @param tree The parse tree to match against the pattern. * @param pattern The parse tree pattern. * @param labels A mapping from label names to collections of * {@link ParseTree} objects located by the tree pattern matching process. * @param mismatchedNode The first node which failed to match the tree * pattern during the matching process. * * @exception IllegalArgumentException if {@code tree} is {@code null} * @exception IllegalArgumentException if {@code pattern} is {@code null} * @exception IllegalArgumentException if {@code labels} is {@code null} */ constructor(tree: ParseTree, pattern: ParseTreePattern, labels: MultiMap, mismatchedNode: ParseTree | undefined); /** * Get the last node associated with a specific {@code label}. * *

For example, for pattern {@code }, {@code get("id")} returns the * node matched for that {@code 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 {@code null}.

* *

Pattern tags like {@code } and {@code } without labels are * considered to be labeled with {@code ID} and {@code expr}, respectively.

* * @param label The label to check. * * @return The last {@link ParseTree} to match a tag with the specified * label, or {@code null} if no parse tree matched a tag with the label. */ get(label: string): ParseTree | undefined; /** * Return all nodes matching a rule or token tag with the specified label. * *

If the {@code 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 {@code label} is {@code "foo"}, * the result will contain all of the following.

* * * * @param label The label. * * @return A collection of all {@link ParseTree} nodes matching tags with * the specified {@code label}. If no nodes matched the label, an empty list * is returned. */ getAll(label: string): ParseTree[]; /** * Return a mapping from label → [list of nodes]. * *

The map includes special entries corresponding to the names of rules and * tokens referenced in tags in the original pattern. For additional * information, see the description of {@link #getAll(String)}.

* * @return A mapping from labels to parse tree nodes. If the parse tree * pattern did not contain any rule or token tags, this map will be empty. */ readonly labels: MultiMap; /** * Get the node at which we first detected a mismatch. * * @return the node at which we first detected a mismatch, or {@code null} * if the match was successful. */ readonly mismatchedNode: ParseTree | undefined; /** * Gets a value indicating whether the match operation succeeded. * * @return {@code true} if the match operation succeeded; otherwise, * {@code false}. */ readonly succeeded: boolean; /** * Get the tree pattern we are matching against. * * @return The tree pattern we are matching against. */ readonly pattern: ParseTreePattern; /** * Get the parse tree we are trying to match to a pattern. * * @return The {@link ParseTree} we are trying to match to a pattern. */ readonly tree: ParseTree; /** * {@inheritDoc} */ toString(): string; }