KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javacc > jjdoc > JJDocMain


1
2 /*
3  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
5  * intellectual property rights relating to technology embodied in the product
6  * that is described in this document. In particular, and without limitation,
7  * these intellectual property rights may include one or more of the U.S.
8  * patents listed at http://www.sun.com/patents and one or more additional
9  * patents or pending patent applications in the U.S. and in other countries.
10  * U.S. Government Rights - Commercial software. Government users are subject
11  * to the Sun Microsystems, Inc. standard license agreement and applicable
12  * provisions of the FAR and its supplements. Use is subject to license terms.
13  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
14  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
15  * product is covered and controlled by U.S. Export Control laws and may be
16  * subject to the export or import laws in other countries. Nuclear, missile,
17  * chemical biological weapons or nuclear maritime end uses or end users,
18  * whether direct or indirect, are strictly prohibited. Export or reexport
19  * to countries subject to U.S. embargo or to entities identified on U.S.
20  * export exclusion lists, including, but not limited to, the denied persons
21  * and specially designated nationals lists is strictly prohibited.
22  */

23
24
25 package org.javacc.jjdoc;
26
27 import org.javacc.parser.*;
28
29 public class JJDocMain {
30
31   static void help_message() {
32     java.io.PrintWriter JavaDoc ostr = new java.io.PrintWriter JavaDoc(new java.io.OutputStreamWriter JavaDoc(System.out));
33
34     ostr.println(" jjdoc option-settings - (to read from standard input)");
35     ostr.println("OR");
36     ostr.println(" jjdoc option-settings inputfile (to read from a file)");
37     ostr.println("");
38     ostr.println("WHERE");
39     ostr.println(" \"option-settings\" is a sequence of settings separated by spaces.");
40     ostr.println("");
41
42     ostr.println("Each option setting must be of one of the following forms:");
43     ostr.println("");
44     ostr.println(" -optionname=value (e.g., -TEXT=false)");
45     ostr.println(" -optionname:value (e.g., -TEXT:false)");
46     ostr.println(" -optionname (equivalent to -optionname=true. e.g., -TEXT)");
47     ostr.println(" -NOoptionname (equivalent to -optionname=false. e.g., -NOTEXT)");
48     ostr.println("");
49     ostr.println("Option settings are not case-sensitive, so one can say \"-nOtExT\" instead");
50     ostr.println("of \"-NOTEXT\". Option values must be appropriate for the corresponding");
51     ostr.println("option, and must be either an integer, boolean or string value.");
52     ostr.println("");
53     ostr.println("The string valued options are:");
54     ostr.println("");
55     ostr.println(" OUTPUT_FILE");
56     ostr.println("");
57     ostr.println("The boolean valued options are:");
58     ostr.println("");
59     ostr.println(" ONE_TABLE (default true)");
60     ostr.println(" TEXT (default false)");
61     ostr.println("");
62
63     ostr.println("");
64     ostr.println("EXAMPLES:");
65     ostr.println(" jjdoc -ONE_TABLE=false mygrammar.jj");
66     ostr.println(" jjdoc - < mygrammar.jj");
67     ostr.println("");
68     ostr.println("ABOUT JJDoc:");
69     ostr.println(" JJDoc generates JavaDoc documentation from JavaCC grammar files.");
70     ostr.println("");
71     ostr.println(" For more information, ???");
72   }
73
74   /**
75    * A main program that exercises the parser.
76    */

77   public static void main(String JavaDoc args[]) throws Exception JavaDoc {
78
79     JavaCCGlobals.bannerLine("Documentation Generator", "0.1.4");
80
81     JavaCCParser parser = null;
82     if (args.length == 0) {
83       System.out.println("");
84       help_message();
85       System.exit(1);
86     } else {
87       System.out.println("(type \"jjdoc\" with no arguments for help)");
88     }
89
90     JJDocOptions.init();
91
92     if (JJDocOptions.isOption(args[args.length-1])) {
93       System.out.println("Last argument \"" + args[args.length-1] + "\" is not a filename or \"-\". ");
94       System.exit(1);
95     }
96     for (int arg = 0; arg < args.length-1; arg++) {
97       if (!JJDocOptions.isOption(args[arg])) {
98         System.out.println("Argument \"" + args[arg] + "\" must be an option setting. ");
99         System.exit(1);
100       }
101       JJDocOptions.setCmdLineOption(args[arg]);
102     }
103
104     if (args[args.length-1].equals("-")) {
105       System.out.println("Reading from standard input . . .");
106       parser = new JavaCCParser(new java.io.DataInputStream JavaDoc(System.in));
107       JJDocGlobals.input_file = "standard input";
108       JJDocGlobals.output_file = "standard output";
109     } else {
110       System.out.println("Reading from file " + args[args.length-1] + " . . .");
111       try {
112         java.io.File JavaDoc fp = new java.io.File JavaDoc(args[args.length-1]);
113         if (!fp.exists()) {
114            System.out.println("File " + args[args.length-1] + " not found.");
115            System.exit(1);
116         }
117         if (fp.isDirectory()) {
118            System.out.println(args[args.length-1] + " is a directory. Please use a valid file name.");
119            System.exit(1);
120         }
121     JJDocGlobals.input_file = fp.getName();
122         parser = new JavaCCParser(new java.io.FileReader JavaDoc(args[args.length-1]));
123       } catch (NullPointerException JavaDoc ne) { // Should never happen
124
} catch (SecurityException JavaDoc se) {
125         System.out.println("Security voilation while trying to open " + args[args.length-1]);
126         System.exit(1);
127       } catch (java.io.FileNotFoundException JavaDoc e) {
128         System.out.println("File " + args[args.length-1] + " not found.");
129         System.exit(1);
130       }
131     }
132     try {
133
134       parser.javacc_input();
135       JJDoc.start();
136
137       if (JavaCCErrors.get_error_count() == 0) {
138         if (JavaCCErrors.get_warning_count() == 0) {
139           System.out.println("Grammar documentation generated successfully in " + JJDocGlobals.output_file);
140         } else {
141           System.out.println("Grammar documentation generated with 0 errors and "
142                              + JavaCCErrors.get_warning_count() + " warnings.");
143         }
144         System.exit(0);
145       } else {
146         System.out.println("Detected " + JavaCCErrors.get_error_count() + " errors and "
147                            + JavaCCErrors.get_warning_count() + " warnings.");
148         System.exit((JavaCCErrors.get_error_count()==0)?0:1);
149       }
150     } catch (org.javacc.parser.MetaParseException e) {
151       System.out.println(e.toString());
152       System.out.println("Detected " + JavaCCErrors.get_error_count() + " errors and "
153                          + JavaCCErrors.get_warning_count() + " warnings.");
154       System.exit(1);
155     } catch (org.javacc.parser.ParseException e) {
156       System.out.println(e.toString());
157       System.out.println("Detected " + (JavaCCErrors.get_error_count()+1) + " errors and "
158                          + JavaCCErrors.get_warning_count() + " warnings.");
159       System.exit(1);
160     }
161   }
162 }
163
Popular Tags