Exemplo n.º 1
0
  /**
   * A list of dependency generators that are accumulated aaaas (and if) the tool is required to
   * sort the provided grammars into build dependency order. protected Map<String,
   * BuildDependencyGenerator> buildDependencyGenerators;
   */
  public static void main(String[] args) {
    Tool antlr = new Tool(args);

    if (!exitNow) {
      antlr.process();
      if (ErrorManager.getNumErrors() > 0) {
        System.exit(1);
      }
      System.exit(0);
    }
  }
Exemplo n.º 2
0
 /** Return true if all is ok, no errors */
 protected boolean antlr(
     String fileName, String grammarFileName, String grammarStr, boolean debug) {
   boolean allIsWell = true;
   mkdir(tmpdir);
   writeFile(tmpdir, fileName, grammarStr);
   try {
     final List options = new ArrayList();
     if (debug) {
       options.add("-debug");
     }
     options.add("-o");
     options.add(tmpdir);
     options.add("-lib");
     options.add(tmpdir);
     options.add(new File(tmpdir, grammarFileName).toString());
     final String[] optionsA = new String[options.size()];
     options.toArray(optionsA);
     /*
     final ErrorQueue equeue = new ErrorQueue();
     ErrorManager.setErrorListener(equeue);
     */
     Tool antlr = newTool(optionsA);
     antlr.process();
     ANTLRErrorListener listener = ErrorManager.getErrorListener();
     if (listener instanceof ErrorQueue) {
       ErrorQueue equeue = (ErrorQueue) listener;
       if (equeue.errors.size() > 0) {
         allIsWell = false;
         System.err.println("antlr reports errors from " + options);
         for (int i = 0; i < equeue.errors.size(); i++) {
           Message msg = (Message) equeue.errors.get(i);
           System.err.println(msg);
         }
         System.out.println("!!!\ngrammar:");
         System.out.println(grammarStr);
         System.out.println("###");
       }
     }
   } catch (Exception e) {
     allIsWell = false;
     System.err.println("problems building grammar: " + e);
     e.printStackTrace(System.err);
   }
   return allIsWell;
 }
Exemplo n.º 3
0
 protected Tool newTool() {
   Tool tool = new Tool();
   tool.setOutputDirectory(tmpdir);
   return tool;
 }
Exemplo n.º 4
0
 protected Tool newTool(String[] args) {
   Tool tool = new Tool(args);
   tool.setOutputDirectory(tmpdir);
   return tool;
 }