Exemplo n.º 1
0
  public void testErrors(String[] pairs, boolean printTree) {
    for (int i = 0; i < pairs.length; i += 2) {
      String input = pairs[i];
      String expect = pairs[i + 1];
      ErrorQueue equeue = new ErrorQueue();
      Grammar g = null;
      try {
        String[] lines = input.split("\n");
        String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
        g = new Grammar(fileName, input, equeue);
      } catch (org.antlr.runtime.RecognitionException re) {
        re.printStackTrace(System.err);
      }
      String actual = equeue.toString(g.tool);
      System.err.println(actual);
      String msg = input;
      msg = msg.replaceAll("\n", "\\\\n");
      msg = msg.replaceAll("\r", "\\\\r");
      msg = msg.replaceAll("\t", "\\\\t");

      // ignore error number
      expect = stripErrorNum(expect);
      actual = stripErrorNum(actual);
      assertEquals("error in: " + msg, expect, actual);
    }
  }
Exemplo n.º 2
0
 protected void checkGrammarSemanticsWarning(
     ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
   ANTLRMessage foundMsg = null;
   for (int i = 0; i < equeue.warnings.size(); i++) {
     ANTLRMessage m = equeue.warnings.get(i);
     if (m.errorType == expectedMessage.errorType) {
       foundMsg = m;
     }
   }
   assertNotNull("no error; " + expectedMessage.errorType + " expected", foundMsg);
   assertTrue(
       "error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
   assertEquals(Arrays.toString(expectedMessage.args), Arrays.toString(foundMsg.args));
   if (equeue.size() != 1) {
     System.err.println(equeue);
   }
 }
Exemplo n.º 3
0
 protected void checkGrammarSemanticsError(
     ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
   /*
   System.out.println(equeue.infos);
   System.out.println(equeue.warnings);
   System.out.println(equeue.errors);
   assertTrue("number of errors mismatch", n, equeue.errors.size());
   		   */
   Message foundMsg = null;
   for (int i = 0; i < equeue.errors.size(); i++) {
     Message m = (Message) equeue.errors.get(i);
     if (m.msgID == expectedMessage.msgID) {
       foundMsg = m;
     }
   }
   assertNotNull("no error; " + expectedMessage.msgID + " expected", foundMsg);
   assertTrue(
       "error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
   assertEquals(expectedMessage.arg, foundMsg.arg);
   if (equeue.size() != 1) {
     System.err.println(equeue);
   }
 }