View Javadoc

1   /* Generated By:JJTree&JavaCC: Do not edit this line. CommandLineParser.java */
2   package org.apache.geronimo.gshell.parser;
3   
4   import java.io.Reader;
5   import java.io.StringReader;
6   
7   import org.slf4j.Logger;
8   import org.slf4j.LoggerFactory;
9   
10  /**
11   * Command line parser.
12   *
13   * @version $Rev: 694373 $ $Date: 2008-09-11 19:31:19 +0200 (Thu, 11 Sep 2008) $
14   */
15  public class CommandLineParser/*@bgen(jjtree)*/implements CommandLineParserTreeConstants, CommandLineParserConstants {/*@bgen(jjtree)*/
16    protected JJTCommandLineParserState jjtree = new JJTCommandLineParserState();private final Logger log = LoggerFactory.getLogger(getClass());
17  
18      public CommandLineParser() {
19          this(new StringReader(""));
20      }
21  
22      public ASTCommandLine parse(final Reader reader) throws ParseException {
23          assert reader != null;
24  
25          log.debug("Parsing from reader: {}", reader);
26  
27          this.ReInit(reader);
28  
29          return this.commandLine();
30      }
31  
32  ///////////////////////////////////////////////////////////////////////////////
33    final public ASTCommandLine commandLine() throws ParseException {
34                                              /*@bgen(jjtree) CommandLine */
35    ASTCommandLine jjtn000 = new ASTCommandLine(JJTCOMMANDLINE);
36    boolean jjtc000 = true;
37    jjtree.openNodeScope(jjtn000);
38      try {
39        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
40        case STRING:
41        case OPAQUE_STRING:
42        case QUOTED_STRING:
43          expression();
44          label_1:
45          while (true) {
46            switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
47            case SEMICOLON:
48              ;
49              break;
50            default:
51              jj_la1[0] = jj_gen;
52              break label_1;
53            }
54            jj_consume_token(SEMICOLON);
55            switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
56            case STRING:
57            case OPAQUE_STRING:
58            case QUOTED_STRING:
59              expression();
60              break;
61            default:
62              jj_la1[1] = jj_gen;
63              ;
64            }
65          }
66          break;
67        case 0:
68          jj_consume_token(0);
69          break;
70        default:
71          jj_la1[2] = jj_gen;
72          jj_consume_token(-1);
73          throw new ParseException();
74        }
75        jjtree.closeNodeScope(jjtn000, true);
76        jjtc000 = false;
77          {if (true) return jjtn000;}
78      } catch (Throwable jjte000) {
79        if (jjtc000) {
80          jjtree.clearNodeScope(jjtn000);
81          jjtc000 = false;
82        } else {
83          jjtree.popNode();
84        }
85        if (jjte000 instanceof RuntimeException) {
86          {if (true) throw (RuntimeException)jjte000;}
87        }
88        if (jjte000 instanceof ParseException) {
89          {if (true) throw (ParseException)jjte000;}
90        }
91        {if (true) throw (Error)jjte000;}
92      } finally {
93        if (jjtc000) {
94          jjtree.closeNodeScope(jjtn000, true);
95        }
96      }
97      throw new Error("Missing return statement in function");
98    }
99  
100   final public void expression() throws ParseException {
101                                 /*@bgen(jjtree) Expression */
102   ASTExpression jjtn000 = new ASTExpression(JJTEXPRESSION);
103   boolean jjtc000 = true;
104   jjtree.openNodeScope(jjtn000);
105     try {
106       process();
107       label_2:
108       while (true) {
109         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
110         case PIPE:
111           ;
112           break;
113         default:
114           jj_la1[3] = jj_gen;
115           break label_2;
116         }
117         jj_consume_token(PIPE);
118         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
119         case STRING:
120         case OPAQUE_STRING:
121         case QUOTED_STRING:
122           process();
123           break;
124         default:
125           jj_la1[4] = jj_gen;
126           ;
127         }
128       }
129     } catch (Throwable jjte000) {
130       if (jjtc000) {
131         jjtree.clearNodeScope(jjtn000);
132         jjtc000 = false;
133       } else {
134         jjtree.popNode();
135       }
136       if (jjte000 instanceof RuntimeException) {
137         {if (true) throw (RuntimeException)jjte000;}
138       }
139       if (jjte000 instanceof ParseException) {
140         {if (true) throw (ParseException)jjte000;}
141       }
142       {if (true) throw (Error)jjte000;}
143     } finally {
144       if (jjtc000) {
145         jjtree.closeNodeScope(jjtn000, true);
146       }
147     }
148   }
149 
150   final public void process() throws ParseException {
151                           /*@bgen(jjtree) Process */
152   ASTProcess jjtn000 = new ASTProcess(JJTPROCESS);
153   boolean jjtc000 = true;
154   jjtree.openNodeScope(jjtn000);
155     try {
156       label_3:
157       while (true) {
158         argument();
159         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
160         case STRING:
161         case OPAQUE_STRING:
162         case QUOTED_STRING:
163           ;
164           break;
165         default:
166           jj_la1[5] = jj_gen;
167           break label_3;
168         }
169       }
170     } catch (Throwable jjte000) {
171       if (jjtc000) {
172         jjtree.clearNodeScope(jjtn000);
173         jjtc000 = false;
174       } else {
175         jjtree.popNode();
176       }
177       if (jjte000 instanceof RuntimeException) {
178         {if (true) throw (RuntimeException)jjte000;}
179       }
180       if (jjte000 instanceof ParseException) {
181         {if (true) throw (ParseException)jjte000;}
182       }
183       {if (true) throw (Error)jjte000;}
184     } finally {
185       if (jjtc000) {
186         jjtree.closeNodeScope(jjtn000, true);
187       }
188     }
189   }
190 
191   final public void argument() throws ParseException {
192     string();
193   }
194 
195   final public void string() throws ParseException {
196     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
197     case QUOTED_STRING:
198       quotedString();
199       break;
200     case OPAQUE_STRING:
201       opaqueString();
202       break;
203     case STRING:
204       plainString();
205       break;
206     default:
207       jj_la1[6] = jj_gen;
208       jj_consume_token(-1);
209       throw new ParseException();
210     }
211   }
212 
213   final public void quotedString() throws ParseException {
214  /*@bgen(jjtree) QuotedString */
215     ASTQuotedString jjtn000 = new ASTQuotedString(JJTQUOTEDSTRING);
216     boolean jjtc000 = true;
217     jjtree.openNodeScope(jjtn000);Token t;
218     try {
219       t = jj_consume_token(QUOTED_STRING);
220       jjtree.closeNodeScope(jjtn000, true);
221       jjtc000 = false;
222         jjtn000.setToken(t);
223     } finally {
224       if (jjtc000) {
225         jjtree.closeNodeScope(jjtn000, true);
226       }
227     }
228   }
229 
230   final public void opaqueString() throws ParseException {
231  /*@bgen(jjtree) OpaqueString */
232     ASTOpaqueString jjtn000 = new ASTOpaqueString(JJTOPAQUESTRING);
233     boolean jjtc000 = true;
234     jjtree.openNodeScope(jjtn000);Token t;
235     try {
236       t = jj_consume_token(OPAQUE_STRING);
237       jjtree.closeNodeScope(jjtn000, true);
238       jjtc000 = false;
239         jjtn000.setToken(t);
240     } finally {
241       if (jjtc000) {
242         jjtree.closeNodeScope(jjtn000, true);
243       }
244     }
245   }
246 
247   final public void plainString() throws ParseException {
248  /*@bgen(jjtree) PlainString */
249     ASTPlainString jjtn000 = new ASTPlainString(JJTPLAINSTRING);
250     boolean jjtc000 = true;
251     jjtree.openNodeScope(jjtn000);Token t;
252     try {
253       t = jj_consume_token(STRING);
254       jjtree.closeNodeScope(jjtn000, true);
255       jjtc000 = false;
256         jjtn000.setToken(t);
257     } finally {
258       if (jjtc000) {
259         jjtree.closeNodeScope(jjtn000, true);
260       }
261     }
262   }
263 
264   /** Generated Token Manager. */
265   public CommandLineParserTokenManager token_source;
266   SimpleCharStream jj_input_stream;
267   /** Current token. */
268   public Token token;
269   /** Next token. */
270   public Token jj_nt;
271   private int jj_ntk;
272   private int jj_gen;
273   final private int[] jj_la1 = new int[7];
274   static private int[] jj_la1_0;
275   static {
276       jj_la1_init_0();
277    }
278    private static void jj_la1_init_0() {
279       jj_la1_0 = new int[] {0x400,0x380,0x381,0x800,0x380,0x380,0x380,};
280    }
281 
282   /** Constructor with InputStream. */
283   public CommandLineParser(java.io.InputStream stream) {
284      this(stream, null);
285   }
286   /** Constructor with InputStream and supplied encoding */
287   public CommandLineParser(java.io.InputStream stream, String encoding) {
288     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
289     token_source = new CommandLineParserTokenManager(jj_input_stream);
290     token = new Token();
291     jj_ntk = -1;
292     jj_gen = 0;
293     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
294   }
295 
296   /** Reinitialise. */
297   public void ReInit(java.io.InputStream stream) {
298      ReInit(stream, null);
299   }
300   /** Reinitialise. */
301   public void ReInit(java.io.InputStream stream, String encoding) {
302     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
303     token_source.ReInit(jj_input_stream);
304     token = new Token();
305     jj_ntk = -1;
306     jjtree.reset();
307     jj_gen = 0;
308     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
309   }
310 
311   /** Constructor. */
312   public CommandLineParser(java.io.Reader stream) {
313     jj_input_stream = new SimpleCharStream(stream, 1, 1);
314     token_source = new CommandLineParserTokenManager(jj_input_stream);
315     token = new Token();
316     jj_ntk = -1;
317     jj_gen = 0;
318     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
319   }
320 
321   /** Reinitialise. */
322   public void ReInit(java.io.Reader stream) {
323     jj_input_stream.ReInit(stream, 1, 1);
324     token_source.ReInit(jj_input_stream);
325     token = new Token();
326     jj_ntk = -1;
327     jjtree.reset();
328     jj_gen = 0;
329     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
330   }
331 
332   /** Constructor with generated Token Manager. */
333   public CommandLineParser(CommandLineParserTokenManager tm) {
334     token_source = tm;
335     token = new Token();
336     jj_ntk = -1;
337     jj_gen = 0;
338     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
339   }
340 
341   /** Reinitialise. */
342   public void ReInit(CommandLineParserTokenManager tm) {
343     token_source = tm;
344     token = new Token();
345     jj_ntk = -1;
346     jjtree.reset();
347     jj_gen = 0;
348     for (int i = 0; i < 7; i++) jj_la1[i] = -1;
349   }
350 
351   private Token jj_consume_token(int kind) throws ParseException {
352     Token oldToken;
353     if ((oldToken = token).next != null) token = token.next;
354     else token = token.next = token_source.getNextToken();
355     jj_ntk = -1;
356     if (token.kind == kind) {
357       jj_gen++;
358       return token;
359     }
360     token = oldToken;
361     jj_kind = kind;
362     throw generateParseException();
363   }
364 
365 
366 /** Get the next Token. */
367   final public Token getNextToken() {
368     if (token.next != null) token = token.next;
369     else token = token.next = token_source.getNextToken();
370     jj_ntk = -1;
371     jj_gen++;
372     return token;
373   }
374 
375 /** Get the specific Token. */
376   final public Token getToken(int index) {
377     Token t = token;
378     for (int i = 0; i < index; i++) {
379       if (t.next != null) t = t.next;
380       else t = t.next = token_source.getNextToken();
381     }
382     return t;
383   }
384 
385   private int jj_ntk() {
386     if ((jj_nt=token.next) == null)
387       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
388     else
389       return (jj_ntk = jj_nt.kind);
390   }
391 
392   private java.util.List jj_expentries = new java.util.ArrayList();
393   private int[] jj_expentry;
394   private int jj_kind = -1;
395 
396   /** Generate ParseException. */
397   public ParseException generateParseException() {
398     jj_expentries.clear();
399     boolean[] la1tokens = new boolean[12];
400     if (jj_kind >= 0) {
401       la1tokens[jj_kind] = true;
402       jj_kind = -1;
403     }
404     for (int i = 0; i < 7; i++) {
405       if (jj_la1[i] == jj_gen) {
406         for (int j = 0; j < 32; j++) {
407           if ((jj_la1_0[i] & (1<<j)) != 0) {
408             la1tokens[j] = true;
409           }
410         }
411       }
412     }
413     for (int i = 0; i < 12; i++) {
414       if (la1tokens[i]) {
415         jj_expentry = new int[1];
416         jj_expentry[0] = i;
417         jj_expentries.add(jj_expentry);
418       }
419     }
420     int[][] exptokseq = new int[jj_expentries.size()][];
421     for (int i = 0; i < jj_expentries.size(); i++) {
422       exptokseq[i] = (int[])jj_expentries.get(i);
423     }
424     return new ParseException(token, exptokseq, tokenImage);
425   }
426 
427   /** Enable tracing. */
428   final public void enable_tracing() {
429   }
430 
431   /** Disable tracing. */
432   final public void disable_tracing() {
433   }
434 
435 }