X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/9f94b672a5dc32da5ad01742bd4e976315a30d9c..c6ad2948bb98d42f8e0883ef82cd14cd2d5eda60:/antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/pattern/ParseTreePattern.h diff --git a/antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/pattern/ParseTreePattern.h b/antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/pattern/ParseTreePattern.h new file mode 100644 index 0000000..d5b86ff --- /dev/null +++ b/antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/pattern/ParseTreePattern.h @@ -0,0 +1,105 @@ +/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. + * Use of this file is governed by the BSD 3-clause license that + * can be found in the LICENSE.txt file in the project root. + */ + +#pragma once + +#include "antlr4-common.h" + +namespace antlr4 { +namespace tree { +namespace pattern { + + /// + /// A pattern like {@code = ;} converted to a by + /// . + /// + class ANTLR4CPP_PUBLIC ParseTreePattern { + public: + /// + /// Construct a new instance of the class. + /// + /// The which created this + /// tree pattern. + /// The tree pattern in concrete syntax form. + /// The parser rule which serves as the root of the + /// tree pattern. + /// The tree pattern in form. + ParseTreePattern(ParseTreePatternMatcher *matcher, const std::string &pattern, int patternRuleIndex, + ParseTree *patternTree); + ParseTreePattern(ParseTreePattern const&) = default; + virtual ~ParseTreePattern(); + + /// + /// Match a specific parse tree against this tree pattern. + /// + /// The parse tree to match against this tree pattern. + /// A object describing the result of the + /// match operation. The method can be + /// used to determine whether or not the match was successful. + virtual ParseTreeMatch match(ParseTree *tree); + + /// + /// Determine whether or not a parse tree matches this tree pattern. + /// + /// The parse tree to match against this tree pattern. + /// {@code true} if {@code tree} is a match for the current tree + /// pattern; otherwise, {@code false}. + virtual bool matches(ParseTree *tree); + + /// Find all nodes using XPath and then try to match those subtrees against + /// this tree pattern. + /// @param tree The ParseTree to match against this pattern. + /// @param xpath An expression matching the nodes + /// + /// @returns A collection of ParseTreeMatch objects describing the + /// successful matches. Unsuccessful matches are omitted from the result, + /// regardless of the reason for the failure. + virtual std::vector findAll(ParseTree *tree, const std::string &xpath); + + /// + /// Get the which created this tree pattern. + /// + /// The which created this tree + /// pattern. + virtual ParseTreePatternMatcher *getMatcher() const; + + /// + /// Get the tree pattern in concrete syntax form. + /// + /// The tree pattern in concrete syntax form. + virtual std::string getPattern() const; + + /// + /// Get the parser rule which serves as the outermost rule for the tree + /// pattern. + /// + /// The parser rule which serves as the outermost rule for the tree + /// pattern. + virtual int getPatternRuleIndex() const; + + /// + /// Get the tree pattern as a . The rule and token tags from + /// the pattern are present in the parse tree as terminal nodes with a symbol + /// of type or . + /// + /// The tree pattern as a . + virtual ParseTree* getPatternTree() const; + + private: + const int patternRuleIndex; + + /// This is the backing field for . + const std::string _pattern; + + /// This is the backing field for . + ParseTree *_patternTree; + + /// This is the backing field for . + ParseTreePatternMatcher *const _matcher; + }; + +} // namespace pattern +} // namespace tree +} // namespace antlr4