Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STErrorListener


        String dir = getRandomDir();
        String groupFile =
            "b() ::= \"bar\"\n"+
            "b() ::= \"duh\"\n";
        writeFile(dir, "group.stg", groupFile);
    STErrorListener errors = new ErrorBuffer();
        STGroupFile group = new STGroupFile(dir+"/group.stg");
    group.setListener(errors);
        group.load();
    String expected = "group.stg 2:0: redefinition of template b"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
    }
View Full Code Here


        String templates =
            "foo() ::= \"\nfoo\"\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 1:11: \\n in string"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

            "foo) ::= << >>\n" +
            "bar() ::= <<bar>>\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 1:0: garbled template definition starting at 'foo'"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

        String templates =
            "foo(a,) ::= << >>\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 1:6: missing ID at ')'"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

  protected STGroup loadTemplates() {
    // override the superclass behavior to put all C# templates in the same folder
    STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT+"/CSharp/"+getLanguage()+STGroup.GROUP_FILE_EXTENSION);
    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

    setFileName(fileName);
    // ensure we have the composite set to something
    if ( composite.delegateGrammarTreeRoot==null ) {
      composite.setDelegationRoot(this);
    }
    STGroup lexerGrammarSTG = new STGroupString(lexerGrammarTemplate);
    lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
    target = CodeGenerator.loadLanguageTarget((String) getOption("language"));
  }
View Full Code Here

  public Grammar(Tool tool) {
    setTool(tool);
    builtFromString = true;
    composite = new CompositeGrammar(this);
    STGroup lexerGrammarSTG = new STGroupString(lexerGrammarTemplate);
    lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
    target = CodeGenerator.loadLanguageTarget((String)getOption("language"));
  }
View Full Code Here

        // new output dir for each test
        tmpdir = new File(System.getProperty("java.io.tmpdir"),
              "antlr-"+getClass().getName()+"-"+
              System.currentTimeMillis()).getAbsolutePath();
        ErrorManager.resetErrorState();
        STGroup.defaultGroup = new STGroup();
    }
View Full Code Here

    return getBadWords().contains(idNode.getText());
  }

  @Override
  protected STGroup loadTemplates() {
    STGroup result = targetTemplates.get();
    if (result == null) {
      result = super.loadTemplates();
      result.registerRenderer(String.class, new JavaStringRenderer(), true);
      targetTemplates.set(result);
    }

    return result;
  }
View Full Code Here

  public static void setLocale(Locale locale) {
    ErrorManager.locale = locale;
    String language = locale.getLanguage();
    String fileName = "org/antlr/tool/templates/messages/languages/"+language+".stg";
    try {
      messages = new STGroupFile(fileName);
    }
    catch (IllegalArgumentException iae) {
      if ( language.equals(Locale.US.getLanguage()) ) {
        rawError("ANTLR installation corrupted; cannot find English messages file "+fileName);
        panic();
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.