Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STErrorListener


   'for'=8
   *
   *  This is independent of the target language; used by antlr internally
   */
  ST getTokenVocabOutput() {
    ST vocabFileST = new ST(vocabFilePattern);
    Map<String,Integer> tokens = new LinkedHashMap<String,Integer>();
    // make constants for the token names
    for (String t : g.tokenNameToTypeMap.keySet()) {
      int tokenType = g.tokenNameToTypeMap.get(t);
      if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) {
        tokens.put(t, tokenType);
      }
    }
    vocabFileST.add("tokens", tokens);

    // now dump the strings
    Map<String,Integer> literals = new LinkedHashMap<String,Integer>();
    for (String literal : g.stringLiteralToTypeMap.keySet()) {
      int tokenType = g.stringLiteralToTypeMap.get(literal);
      if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) {
        literals.put(literal, tokenType);
      }
    }
    vocabFileST.add("literals", literals);

    return vocabFileST;
  }
View Full Code Here


  public void writeHeaderFile() {
    String fileName = getHeaderFileName();
    if ( fileName==null ) return;
    if ( getTemplates().isDefined("headerFile") ) {
      ST extST = getTemplates().getInstanceOf("headerFileExtension");
      ST headerFileST = null;
      // TODO:  don't hide this header file generation here!
      getTarget().genRecognizerHeaderFile(g, headerFileST, extST.render(lineWidth));
    }
  }
View Full Code Here

  }

  public void writeVocabFile() {
    // write out the vocab interchange file; used by antlr,
    // does not change per target
    ST tokenVocabSerialization = getTokenVocabOutput();
    String fileName = getVocabFileName();
    if ( fileName!=null ) {
      getTarget().genFile(g, tokenVocabSerialization, fileName);
    }
  }
View Full Code Here

  /** Generate TParser.java and TLexer.java from T.g4 if combined, else
   *  just use T.java as output regardless of type.
   */
  public String getRecognizerFileName() {
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String recognizerName = g.getRecognizerName();
    return recognizerName+extST.render();
  }
View Full Code Here

  /** A given grammar T, return the listener name such as
   *  TListener.java, if we're using the Java target.
    */
  public String getListenerFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "Listener";
    return listenerName+extST.render();
  }
View Full Code Here

  /** A given grammar T, return the visitor name such as
   *  TVisitor.java, if we're using the Java target.
    */
  public String getVisitorFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "Visitor";
    return listenerName+extST.render();
  }
View Full Code Here

             language);
    }
    if ( result==null ) return null;
    result.registerRenderer(Integer.class, new NumberRenderer());
    result.registerRenderer(String.class, new StringRenderer());
    result.setListener(new STErrorListener() {
      @Override
      public void compileTimeError(STMessage msg) {
        reportError(msg);
      }
View Full Code Here

    String templates =
      "import\n" +
      "foo() ::= <<>>\n";
    writeFile(tmpdir, "t.stg", templates);

    STErrorListener errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 2:0: mismatched input 'foo' expecting STRING"+newline+
      "t.stg 2:3: missing EOF at '('"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

    String templates =
      "import Super.stg\n" +
      "foo() ::= <<>>\n";
    writeFile(tmpdir, "t.stg", templates);

    STErrorListener errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 1:7: mismatched input 'Super' expecting STRING"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

    String templates =
      "foo() ::= \n";
    writeFile(tmpdir, "t.stg", templates);

    STGroupFile group = null;
    STErrorListener errors = new ErrorBuffer();
    group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 2:0: missing template at '<EOF>'"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STErrorListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.