/** <summary>
         *  Do the work for parse. Check to see if the t2 pattern fits the
         *  structure and token types in t1.  Check text if the pattern has
         *  text arguments on nodes.  Fill labels map with pointers to nodes
         *  in tree matched against nodes in pattern with labels.
         *  </summary>
         */
        protected virtual bool ParseCore(object t1, TreePattern tpattern, IDictionary <string, object> labels)
        {
            // make sure both are non-null
            if (t1 == null || tpattern == null)
            {
                return(false);
            }
            // check roots (wildcard matches anything)
            if (tpattern.GetType() != typeof(WildcardTreePattern))
            {
                if (adaptor.GetType(t1) != tpattern.Type)
                {
                    return(false);
                }
                // if pattern has text, check node text
                if (tpattern.hasTextArg && !adaptor.GetText(t1).Equals(tpattern.Text))
                {
                    return(false);
                }
            }
            if (tpattern.label != null && labels != null)
            {
                // map label in pattern to node in t1
                labels[tpattern.label] = t1;
            }
            // check children
            int n1 = adaptor.GetChildCount(t1);
            int n2 = tpattern.ChildCount;

            if (n1 != n2)
            {
                return(false);
            }
            for (int i = 0; i < n1; i++)
            {
                object      child1 = adaptor.GetChild(t1, i);
                TreePattern child2 = (TreePattern)tpattern.GetChild(i);
                if (!ParseCore(child1, child2, labels))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Do the work for Parse(). Check to see if the t2 pattern fits the
        /// structure and token types in t1.  Check text if the pattern has
        /// text arguments on nodes.  Fill labels map with pointers to nodes
        /// in tree matched against nodes in pattern with labels.
        /// </summary>
        protected bool _Parse(object t1, TreePattern t2, IDictionary labels)
        {
            // make sure both are non-null
            if (t1 == null || t2 == null)
            {
                return(false);
            }
            // check roots (wildcard matches anything)
            if (t2.GetType() != typeof(WildcardTreePattern))
            {
                if (adaptor.GetNodeType(t1) != t2.Type)
                {
                    return(false);
                }
                if (t2.hasTextArg && !adaptor.GetNodeText(t1).Equals(t2.Text))
                {
                    return(false);
                }
            }
            if (t2.label != null && labels != null)
            {
                // map label in pattern to node in t1
                labels[t2.label] = t1;
            }
            // check children
            int n1 = adaptor.GetChildCount(t1);
            int n2 = t2.ChildCount;

            if (n1 != n2)
            {
                return(false);
            }
            for (int i = 0; i < n1; i++)
            {
                object      child1 = adaptor.GetChild(t1, i);
                TreePattern child2 = (TreePattern)t2.GetChild(i);
                if (!_Parse(child1, child2, labels))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
 /** <summary>
  *  Do the work for parse. Check to see if the t2 pattern fits the
  *  structure and token types in t1.  Check text if the pattern has
  *  text arguments on nodes.  Fill labels map with pointers to nodes
  *  in tree matched against nodes in pattern with labels.
  *  </summary>
  */
 protected virtual bool _Parse( object t1, TreePattern tpattern, IDictionary<string, object> labels )
 {
     // make sure both are non-null
     if ( t1 == null || tpattern == null )
     {
         return false;
     }
     // check roots (wildcard matches anything)
     if ( tpattern.GetType() != typeof( WildcardTreePattern ) )
     {
         if ( adaptor.GetType( t1 ) != tpattern.Type )
         {
             return false;
         }
         // if pattern has text, check node text
         if ( tpattern.hasTextArg && !adaptor.GetText( t1 ).Equals( tpattern.Text ) )
         {
             return false;
         }
     }
     if ( tpattern.label != null && labels != null )
     {
         // map label in pattern to node in t1
         labels[tpattern.label] = t1;
     }
     // check children
     int n1 = adaptor.GetChildCount( t1 );
     int n2 = tpattern.ChildCount;
     if ( n1 != n2 )
     {
         return false;
     }
     for ( int i = 0; i < n1; i++ )
     {
         object child1 = adaptor.GetChild( t1, i );
         TreePattern child2 = (TreePattern)tpattern.GetChild( i );
         if ( !_Parse( child1, child2, labels ) )
         {
             return false;
         }
     }
     return true;
 }
 protected virtual bool ParseCore(object t1, TreePattern tpattern, IDictionary<string, object> labels)
 {
     if ((t1 == null) || (tpattern == null))
     {
         return false;
     }
     if (tpattern.GetType() != typeof(WildcardTreePattern))
     {
         if (this.adaptor.GetType(t1) != tpattern.Type)
         {
             return false;
         }
         if (tpattern.hasTextArg && !this.adaptor.GetText(t1).Equals(tpattern.Text))
         {
             return false;
         }
     }
     if ((tpattern.label != null) && (labels != null))
     {
         labels[tpattern.label] = t1;
     }
     int childCount = this.adaptor.GetChildCount(t1);
     int num2 = tpattern.ChildCount;
     if (childCount != num2)
     {
         return false;
     }
     for (int i = 0; i < childCount; i++)
     {
         object child = this.adaptor.GetChild(t1, i);
         TreePattern pattern = (TreePattern) tpattern.GetChild(i);
         if (!this.ParseCore(child, pattern, labels))
         {
             return false;
         }
     }
     return true;
 }