Main { public static int mainProgram(String[] args) throws Exception { org.javacc.parser.Main.reInitAll(); JJDocOptions.init(); Tools.bannerLine("Documentation Generator", "0.1.4"); if (args.length == 0) { usage(); return 1; } else { JJDocGlobals.info("(type \"jjdoc\" with no arguments for help)"); } if (JJDocOptions.isOption(args[args.length - 1])) { JJDocGlobals.error("Last argument \"" + args[args.length - 1] + "\" is not a filename or \"-\". "); return 1; } for (int arg = 0; arg < args.length - 1; arg++) { if (!JJDocOptions.isOption(args[arg])) { JJDocGlobals.error("Argument \"" + args[arg] + "\" must be an option setting. "); return 1; } JJDocOptions.setCmdLineOption(args[arg]); } JavaCCParser parser; if (args[args.length - 1].equals("-")) { JJDocGlobals.info("Reading from standard input . . ."); parser = new JavaCCParser( new JavaCCScanner( new CharStream.Escaping( new CharStream.ForReader( new InputStreamReader(System.in))))); JJDocGlobals.inputFile = "standard input"; JJDocGlobals.outputFile = "standard output"; } else { JJDocGlobals.info("Reading from file " + args[args.length - 1] + " . . ."); try { File fp = new File(args[args.length - 1]); if (!fp.exists()) { JJDocGlobals.error("File " + args[args.length - 1] + " not found."); return 1; } if (fp.isDirectory()) { JJDocGlobals.error(args[args.length - 1] + " is a directory. Please use a valid file name."); return 1; } JJDocGlobals.inputFile = fp.getName(); BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(args[args.length - 1]), JJDocOptions.getGrammarEncoding())); parser = new JavaCCParser( new JavaCCScanner( new CharStream.Escaping( new CharStream.ForReader(reader)))); } catch (SecurityException se) { JJDocGlobals.error("Security violation while trying to open " + args[args.length - 1]); return 1; } catch (FileNotFoundException e) { JJDocGlobals.error("File " + args[args.length - 1] + " not found."); return 1; } } try { JavaCCState state = new JavaCCState(); parser.setState(state); parser.start(); IndentingPrintWriter out = JJDocGlobals.createOutputStream(); try { JJDoc doc = new JJDoc(state, JJDocGlobals.createFormatter(out)); doc.start(); } finally { out.close(); } if (JavaCCErrors.getErrorCount() == 0) { if (JavaCCErrors.getWarningCount() == 0) { JJDocGlobals.info("Grammar documentation generated successfully in " + JJDocGlobals.outputFile); } else { JJDocGlobals.info("Grammar documentation generated with 0 errors and " + JavaCCErrors.getWarningCount() + " warnings."); } return 0; } else { JJDocGlobals.error("Detected " + JavaCCErrors.getErrorCount() + " errors and " + JavaCCErrors.getWarningCount() + " warnings."); return JavaCCErrors.getErrorCount() == 0 ? 0 : 1; } } catch (MetaParseException ex) { JJDocGlobals.error(ex.toString()); JJDocGlobals.error("Detected " + JavaCCErrors.getErrorCount() + " errors and " + JavaCCErrors.getWarningCount() + " warnings."); return 1; } catch (ParseException ex) { JJDocGlobals.error(ex.toString()); JJDocGlobals.error("Detected " + (JavaCCErrors.getErrorCount() + 1) + " errors and " + JavaCCErrors.getWarningCount() + " warnings."); return 1; } }  static void main(String[] args); static int mainProgram(String[] args);  }
@Test @Ignore public void testMainProgramHTML() throws Exception { assertEquals(0, Main.mainProgram(new String[]{"-OUTPUT_FILE:" + getJJDocOutputDirectory() + "JavaCC.html", getJJInputDirectory() + "JavaCC.jj"})); }
@Test @Ignore public void testMainProgramText() throws Exception { assertEquals(0, Main.mainProgram(new String[]{"-OUTPUT_FILE:" + getJJDocOutputDirectory() + "JavaCC.txt", "-TEXT:true", getJJInputDirectory() + "JavaCC.jj"})); }