protected void checkPlusEqualsLabels(Grammar g,
                                             string ruleName,
                                             string tokenLabelsStr,
                                             string ruleLabelsStr)
        //throws Exception
        {
            // make sure expected += labels are there
            Rule                 r           = g.GetRule(ruleName);
            StringTokenizer      st          = new StringTokenizer(tokenLabelsStr, ", ");
            ICollection <string> tokenLabels = null;

            while (st.hasMoreTokens())
            {
                if (tokenLabels == null)
                {
                    tokenLabels = new List <string>();
                }
                string labelName = st.nextToken();
                tokenLabels.Add(labelName);
            }
            ICollection <string> ruleLabels = null;

            if (ruleLabelsStr != null)
            {
                st         = new StringTokenizer(ruleLabelsStr, ", ");
                ruleLabels = new List <string>();
                while (st.hasMoreTokens())
                {
                    string labelName = st.nextToken();
                    ruleLabels.Add(labelName);
                }
            }
            Assert.IsTrue((tokenLabels != null && r.TokenListLabels != null) ||
                          (tokenLabels == null && r.TokenListLabels == null),
                          "token += labels mismatch; " + tokenLabels + "!=" + r.TokenListLabels);
            Assert.IsTrue((ruleLabels != null && r.RuleListLabels != null) ||
                          (ruleLabels == null && r.RuleListLabels == null),
                          "rule += labels mismatch; " + ruleLabels + "!=" + r.RuleListLabels);
            if (tokenLabels != null)
            {
                Assert.IsTrue(tokenLabels.SequenceEqual(r.TokenListLabels.Keys));
            }
            if (ruleLabels != null)
            {
                Assert.IsTrue(ruleLabels.SequenceEqual(r.RuleListLabels.Keys));
            }
        }
Exemple #2
0
 protected static string[] DecodeReportData(string data) {
     string[] fields = new string[NumRuntimeStats];
     StringTokenizer st = new StringTokenizer(data, "\t");
     int i = 0;
     while (st.hasMoreTokens()) {
         fields[i] = st.nextToken();
         i++;
     }
     if (i != NumRuntimeStats) {
         return null;
     }
     return fields;
 }
 public virtual string[] GetEventElements( string @event )
 {
     if ( @event == null )
     {
         return null;
     }
     string[] elements = new string[MAX_EVENT_ELEMENTS];
     string str = null; // a string element if present (must be last)
     try
     {
         int firstQuoteIndex = @event.IndexOf( '"' );
         if ( firstQuoteIndex >= 0 )
         {
             // treat specially; has a string argument like "a comment\n
             // Note that the string is terminated by \n not end quote.
             // Easier to parse that way.
             string eventWithoutString = @event.Substring( 0, firstQuoteIndex );
             str = @event.Substring( firstQuoteIndex + 1 );
             @event = eventWithoutString;
         }
         StringTokenizer st = new StringTokenizer( @event, "\t", false );
         int i = 0;
         while ( st.hasMoreTokens() )
         {
             if ( i >= MAX_EVENT_ELEMENTS )
             {
                 // ErrorManager.internalError("event has more than "+MAX_EVENT_ELEMENTS+" args: "+event);
                 return elements;
             }
             elements[i] = st.nextToken();
             i++;
         }
         if ( str != null )
         {
             elements[i] = str;
         }
     }
     catch ( Exception e )
     {
         e.PrintStackTrace( Console.Error );
     }
     return elements;
 }
 //throws Exception
 protected void checkPlusEqualsLabels( Grammar g,
                                      string ruleName,
                                      string tokenLabelsStr,
                                      string ruleLabelsStr )
 {
     // make sure expected += labels are there
     Rule r = g.GetRule( ruleName );
     StringTokenizer st = new StringTokenizer( tokenLabelsStr, ", " );
     ICollection<string> tokenLabels = null;
     while ( st.hasMoreTokens() )
     {
         if ( tokenLabels == null )
         {
             tokenLabels = new List<string>();
         }
         string labelName = st.nextToken();
         tokenLabels.Add( labelName );
     }
     ICollection<string> ruleLabels = null;
     if ( ruleLabelsStr != null )
     {
         st = new StringTokenizer( ruleLabelsStr, ", " );
         ruleLabels = new List<string>();
         while ( st.hasMoreTokens() )
         {
             string labelName = st.nextToken();
             ruleLabels.Add( labelName );
         }
     }
     Assert.IsTrue((tokenLabels != null && r.TokenListLabels != null) ||
                (tokenLabels == null && r.TokenListLabels == null),
                "token += labels mismatch; " + tokenLabels + "!=" + r.TokenListLabels);
     Assert.IsTrue((ruleLabels != null && r.RuleListLabels != null) ||
                (ruleLabels == null && r.RuleListLabels == null),
                "rule += labels mismatch; " + ruleLabels + "!=" + r.RuleListLabels);
     if ( tokenLabels != null )
     {
         Assert.IsTrue( tokenLabels.SequenceEqual( r.TokenListLabels.Keys ) );
     }
     if ( ruleLabels != null )
     {
         Assert.IsTrue( ruleLabels.SequenceEqual( r.RuleListLabels.Keys ) );
     }
 }