A pattern like <ID> = <expr>; converted to a Antlr4.Runtime.Tree.IParseTree by ParseTreePatternMatcher.Compile(string, int) .
Exemplo n.º 1
0
        /// <summary>
        /// Does
        /// <paramref name="pattern"/>
        /// matched as rule patternRuleIndex match tree? Pass in a
        /// compiled pattern instead of a string representation of a tree pattern.
        /// </summary>
        public virtual bool Matches(IParseTree tree, ParseTreePattern pattern)
        {
            MultiMap <string, IParseTree> labels = new MultiMap <string, IParseTree>();
            IParseTree mismatchedNode            = MatchImpl(tree, pattern.PatternTree, labels);

            return(mismatchedNode == null);
        }
Exemplo n.º 2
0
        public virtual ParseTreeMatch Match(IParseTree tree, ParseTreePattern pattern)
        {
            MultiMap <string, IParseTree> labels = new MultiMap <string, IParseTree>();

            IParseTree mismatchedNode = MatchImpl(tree, pattern.PatternTree, labels);

            return(new ParseTreeMatch(tree, pattern, labels, mismatchedNode));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs a new instance of
 /// <see cref="ParseTreeMatch"/>
 /// from the specified
 /// parse tree and pattern.
 /// </summary>
 /// <param name="tree">The parse tree to match against the pattern.</param>
 /// <param name="pattern">The parse tree pattern.</param>
 /// <param name="labels">
 /// A mapping from label names to collections of
 /// <see cref="Antlr4.Runtime.Tree.IParseTree"/>
 /// objects located by the tree pattern matching process.
 /// </param>
 /// <param name="mismatchedNode">
 /// The first node which failed to match the tree
 /// pattern during the matching process.
 /// </param>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="tree"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="pattern"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="labels"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 public ParseTreeMatch(IParseTree tree, ParseTreePattern pattern, MultiMap<string, IParseTree> labels, IParseTree mismatchedNode)
 {
     if (tree == null)
     {
         throw new ArgumentException("tree cannot be null");
     }
     if (pattern == null)
     {
         throw new ArgumentException("pattern cannot be null");
     }
     if (labels == null)
     {
         throw new ArgumentException("labels cannot be null");
     }
     this.tree = tree;
     this.pattern = pattern;
     this.labels = labels;
     this.mismatchedNode = mismatchedNode;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Constructs a new instance of
 /// <see cref="ParseTreeMatch"/>
 /// from the specified
 /// parse tree and pattern.
 /// </summary>
 /// <param name="tree">The parse tree to match against the pattern.</param>
 /// <param name="pattern">The parse tree pattern.</param>
 /// <param name="labels">
 /// A mapping from label names to collections of
 /// <see cref="Antlr4.Runtime.Tree.IParseTree"/>
 /// objects located by the tree pattern matching process.
 /// </param>
 /// <param name="mismatchedNode">
 /// The first node which failed to match the tree
 /// pattern during the matching process.
 /// </param>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="tree"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="pattern"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 /// <exception>
 /// IllegalArgumentException
 /// if
 /// <paramref name="labels"/>
 /// is
 /// <see langword="null"/>
 /// </exception>
 public ParseTreeMatch(IParseTree tree, ParseTreePattern pattern, MultiMap <string, IParseTree> labels, IParseTree mismatchedNode)
 {
     if (tree == null)
     {
         throw new ArgumentException("tree cannot be null");
     }
     if (pattern == null)
     {
         throw new ArgumentException("pattern cannot be null");
     }
     if (labels == null)
     {
         throw new ArgumentException("labels cannot be null");
     }
     this.tree           = tree;
     this.pattern        = pattern;
     this.labels         = labels;
     this.mismatchedNode = mismatchedNode;
 }
 public virtual ParseTreeMatch Match(IParseTree tree, ParseTreePattern pattern)
 {
     MultiMap<string, IParseTree> labels = new MultiMap<string, IParseTree>();
     IParseTree mismatchedNode = MatchImpl(tree, pattern.PatternTree, labels);
     return new ParseTreeMatch(tree, pattern, labels, mismatchedNode);
 }
 /// <summary>
 /// Does
 /// <code>pattern</code>
 /// matched as rule patternRuleIndex match tree? Pass in a
 /// compiled pattern instead of a string representation of a tree pattern.
 /// </summary>
 public virtual bool Matches(IParseTree tree, ParseTreePattern pattern)
 {
     MultiMap<string, IParseTree> labels = new MultiMap<string, IParseTree>();
     IParseTree mismatchedNode = MatchImpl(tree, pattern.PatternTree, labels);
     return mismatchedNode == null;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Compare
        /// <paramref name="pattern"/>
        /// matched as rule
        /// <paramref name="patternRuleIndex"/>
        /// against
        /// <paramref name="tree"/>
        /// and return a
        /// <see cref="ParseTreeMatch"/>
        /// object that contains the
        /// matched elements, or the node at which the match failed.
        /// </summary>
        public virtual ParseTreeMatch Match(IParseTree tree, string pattern, int patternRuleIndex)
        {
            ParseTreePattern p = Compile(pattern, patternRuleIndex);

            return(Match(tree, p));
        }