View Javadoc
1   /* Generated By:JavaCC: Do not edit this line. GroupMatcherParser.java */
2   package org.apache.maven.surefire.group.parse;
3   
4   import org.apache.maven.surefire.group.match.*;
5   import java.io.*;
6   
7   public class GroupMatcherParser implements GroupMatcherParserConstants {
8       public static void main( String[] args )
9           throws Exception
10      {
11          BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
12          while( true )
13          {
14          try
15          {
16              System.out.print( "Enter expression: " );
17              String expr = reader.readLine();
18              GroupMatcherParser parser = new GroupMatcherParser( expr );
19              GroupMatcher matcher = parser.parse();
20              System.out.println( matcher );
21          }
22          catch ( ParseException e )
23          {
24              e.printStackTrace();
25          }
26          }
27      }
28  
29      public GroupMatcherParser( String expression )
30      {
31          this( (Reader)(new StringReader( expression ) ) );
32      }
33  
34      private GroupMatcher getMatcher( Op op, GroupMatcher...matchers )
35      {
36        GroupMatcher matcher = null;
37        if ( Op.AND == op )
38        {
39          matcher = new AndGroupMatcher( matchers );
40        }
41        else
42        {
43          matcher = new OrGroupMatcher( matchers );
44        }
45  
46        return matcher;
47      }
48  
49      public enum Op
50      {
51        AND, OR;
52      }
53  
54    final public GroupMatcher parse() throws ParseException {
55   GroupMatcher matcher = null;
56      matcher = expr();
57      {if (true) return matcher;}
58      throw new Error("Missing return statement in function");
59    }
60  
61    final public GroupMatcher expr() throws ParseException {
62  GroupMatcher matcher=null;
63      if (jj_2_1(3)) {
64        matcher = igroup();
65      } else if (jj_2_2(3)) {
66        matcher = group();
67      } else {
68        jj_consume_token(-1);
69        throw new ParseException();
70      }
71     {if (true) return matcher;}
72      throw new Error("Missing return statement in function");
73    }
74  
75    final public GroupMatcher igroup() throws ParseException {
76  GroupMatcher lhs=null;
77  GroupMatcher rhs=null;
78  Op op=null;
79      lhs = value();
80      if (jj_2_3(3)) {
81        op = op();
82        rhs = expr();
83      } else {
84        ;
85      }
86      GroupMatcher matcher = lhs;
87      if ( op != null )
88      {
89        matcher = getMatcher( op, lhs, rhs );
90      }
91  
92      {if (true) return matcher;}
93      throw new Error("Missing return statement in function");
94    }
95  
96    final public GroupMatcher group() throws ParseException {
97  boolean inverted=false;
98  GroupMatcher lhs=null;
99  GroupMatcher rhs=null;
100 Op op=null;
101     if (jj_2_4(3)) {
102       not();
103     inverted=true;
104     } else {
105       ;
106     }
107     jj_consume_token(LPAREN);
108     lhs = expr();
109     if (jj_2_5(3)) {
110       op = op();
111       rhs = expr();
112     } else {
113       ;
114     }
115     jj_consume_token(RPAREN);
116     GroupMatcher matcher = lhs;
117     if ( op != null )
118     {
119       matcher = getMatcher( op, lhs, rhs );
120     }
121 
122     {if (true) return inverted ? new InverseGroupMatcher( matcher ) : matcher;}
123     throw new Error("Missing return statement in function");
124   }
125 
126   final public GroupMatcher value() throws ParseException {
127 boolean inverted=false;
128 Token val=null;
129     if (jj_2_6(3)) {
130       not();
131    inverted=true;
132     } else {
133       ;
134     }
135     val = jj_consume_token(STRING);
136     GroupMatcher m = new SingleGroupMatcher( val.image );
137     {if (true) return inverted ? new InverseGroupMatcher( m ) : m;}
138     throw new Error("Missing return statement in function");
139   }
140 
141   final public Op op() throws ParseException {
142  Op o=null;
143     if (jj_2_7(3)) {
144       jj_consume_token(AND);
145    o=Op.AND;
146     } else if (jj_2_8(3)) {
147       jj_consume_token(OR);
148    o=Op.OR;
149     } else if (jj_2_9(3)) {
150       jj_consume_token(AMP2);
151    o=Op.AND;
152     } else if (jj_2_10(3)) {
153       jj_consume_token(PIPE2);
154    o=Op.OR;
155     } else if (jj_2_11(3)) {
156       jj_consume_token(COMMA);
157    o=Op.OR;
158     } else {
159       jj_consume_token(-1);
160       throw new ParseException();
161     }
162    {if (true) return o;}
163     throw new Error("Missing return statement in function");
164   }
165 
166   final public void not() throws ParseException {
167     if (jj_2_12(3)) {
168       jj_consume_token(NOT);
169     } else if (jj_2_13(3)) {
170       jj_consume_token(BANG);
171     } else {
172       jj_consume_token(-1);
173       throw new ParseException();
174     }
175   }
176 
177   private boolean jj_2_1(int xla) {
178     jj_la = xla; jj_lastpos = jj_scanpos = token;
179     try { return !jj_3_1(); }
180     catch(LookaheadSuccess ls) { return true; }
181     finally { jj_save(0, xla); }
182   }
183 
184   private boolean jj_2_2(int xla) {
185     jj_la = xla; jj_lastpos = jj_scanpos = token;
186     try { return !jj_3_2(); }
187     catch(LookaheadSuccess ls) { return true; }
188     finally { jj_save(1, xla); }
189   }
190 
191   private boolean jj_2_3(int xla) {
192     jj_la = xla; jj_lastpos = jj_scanpos = token;
193     try { return !jj_3_3(); }
194     catch(LookaheadSuccess ls) { return true; }
195     finally { jj_save(2, xla); }
196   }
197 
198   private boolean jj_2_4(int xla) {
199     jj_la = xla; jj_lastpos = jj_scanpos = token;
200     try { return !jj_3_4(); }
201     catch(LookaheadSuccess ls) { return true; }
202     finally { jj_save(3, xla); }
203   }
204 
205   private boolean jj_2_5(int xla) {
206     jj_la = xla; jj_lastpos = jj_scanpos = token;
207     try { return !jj_3_5(); }
208     catch(LookaheadSuccess ls) { return true; }
209     finally { jj_save(4, xla); }
210   }
211 
212   private boolean jj_2_6(int xla) {
213     jj_la = xla; jj_lastpos = jj_scanpos = token;
214     try { return !jj_3_6(); }
215     catch(LookaheadSuccess ls) { return true; }
216     finally { jj_save(5, xla); }
217   }
218 
219   private boolean jj_2_7(int xla) {
220     jj_la = xla; jj_lastpos = jj_scanpos = token;
221     try { return !jj_3_7(); }
222     catch(LookaheadSuccess ls) { return true; }
223     finally { jj_save(6, xla); }
224   }
225 
226   private boolean jj_2_8(int xla) {
227     jj_la = xla; jj_lastpos = jj_scanpos = token;
228     try { return !jj_3_8(); }
229     catch(LookaheadSuccess ls) { return true; }
230     finally { jj_save(7, xla); }
231   }
232 
233   private boolean jj_2_9(int xla) {
234     jj_la = xla; jj_lastpos = jj_scanpos = token;
235     try { return !jj_3_9(); }
236     catch(LookaheadSuccess ls) { return true; }
237     finally { jj_save(8, xla); }
238   }
239 
240   private boolean jj_2_10(int xla) {
241     jj_la = xla; jj_lastpos = jj_scanpos = token;
242     try { return !jj_3_10(); }
243     catch(LookaheadSuccess ls) { return true; }
244     finally { jj_save(9, xla); }
245   }
246 
247   private boolean jj_2_11(int xla) {
248     jj_la = xla; jj_lastpos = jj_scanpos = token;
249     try { return !jj_3_11(); }
250     catch(LookaheadSuccess ls) { return true; }
251     finally { jj_save(10, xla); }
252   }
253 
254   private boolean jj_2_12(int xla) {
255     jj_la = xla; jj_lastpos = jj_scanpos = token;
256     try { return !jj_3_12(); }
257     catch(LookaheadSuccess ls) { return true; }
258     finally { jj_save(11, xla); }
259   }
260 
261   private boolean jj_2_13(int xla) {
262     jj_la = xla; jj_lastpos = jj_scanpos = token;
263     try { return !jj_3_13(); }
264     catch(LookaheadSuccess ls) { return true; }
265     finally { jj_save(12, xla); }
266   }
267 
268   private boolean jj_3_8() {
269     if (jj_scan_token(OR)) return true;
270     return false;
271   }
272 
273   private boolean jj_3_7() {
274     if (jj_scan_token(AND)) return true;
275     return false;
276   }
277 
278   private boolean jj_3_3() {
279     if (jj_3R_3()) return true;
280     if (jj_3R_4()) return true;
281     return false;
282   }
283 
284   private boolean jj_3R_3() {
285     Token xsp;
286     xsp = jj_scanpos;
287     if (jj_3_7()) {
288     jj_scanpos = xsp;
289     if (jj_3_8()) {
290     jj_scanpos = xsp;
291     if (jj_3_9()) {
292     jj_scanpos = xsp;
293     if (jj_3_10()) {
294     jj_scanpos = xsp;
295     if (jj_3_11()) return true;
296     }
297     }
298     }
299     }
300     return false;
301   }
302 
303   private boolean jj_3_6() {
304     if (jj_3R_5()) return true;
305     return false;
306   }
307 
308   private boolean jj_3R_6() {
309     Token xsp;
310     xsp = jj_scanpos;
311     if (jj_3_6()) jj_scanpos = xsp;
312     if (jj_scan_token(STRING)) return true;
313     return false;
314   }
315 
316   private boolean jj_3R_1() {
317     if (jj_3R_6()) return true;
318     Token xsp;
319     xsp = jj_scanpos;
320     if (jj_3_3()) jj_scanpos = xsp;
321     return false;
322   }
323 
324   private boolean jj_3_13() {
325     if (jj_scan_token(BANG)) return true;
326     return false;
327   }
328 
329   private boolean jj_3_2() {
330     if (jj_3R_2()) return true;
331     return false;
332   }
333 
334   private boolean jj_3_1() {
335     if (jj_3R_1()) return true;
336     return false;
337   }
338 
339   private boolean jj_3R_5() {
340     Token xsp;
341     xsp = jj_scanpos;
342     if (jj_3_12()) {
343     jj_scanpos = xsp;
344     if (jj_3_13()) return true;
345     }
346     return false;
347   }
348 
349   private boolean jj_3_12() {
350     if (jj_scan_token(NOT)) return true;
351     return false;
352   }
353 
354   private boolean jj_3R_4() {
355     Token xsp;
356     xsp = jj_scanpos;
357     if (jj_3_1()) {
358     jj_scanpos = xsp;
359     if (jj_3_2()) return true;
360     }
361     return false;
362   }
363 
364   private boolean jj_3_5() {
365     if (jj_3R_3()) return true;
366     if (jj_3R_4()) return true;
367     return false;
368   }
369 
370   private boolean jj_3_11() {
371     if (jj_scan_token(COMMA)) return true;
372     return false;
373   }
374 
375   private boolean jj_3_10() {
376     if (jj_scan_token(PIPE2)) return true;
377     return false;
378   }
379 
380   private boolean jj_3_4() {
381     if (jj_3R_5()) return true;
382     return false;
383   }
384 
385   private boolean jj_3R_2() {
386     Token xsp;
387     xsp = jj_scanpos;
388     if (jj_3_4()) jj_scanpos = xsp;
389     if (jj_scan_token(LPAREN)) return true;
390     if (jj_3R_4()) return true;
391     xsp = jj_scanpos;
392     if (jj_3_5()) jj_scanpos = xsp;
393     if (jj_scan_token(RPAREN)) return true;
394     return false;
395   }
396 
397   private boolean jj_3_9() {
398     if (jj_scan_token(AMP2)) return true;
399     return false;
400   }
401 
402   /** Generated Token Manager. */
403   public GroupMatcherParserTokenManager token_source;
404   SimpleCharStream jj_input_stream;
405   /** Current token. */
406   public Token token;
407   /** Next token. */
408   public Token jj_nt;
409   private int jj_ntk;
410   private Token jj_scanpos, jj_lastpos;
411   private int jj_la;
412   private int jj_gen;
413   final private int[] jj_la1 = new int[0];
414   static private int[] jj_la1_0;
415   static {
416       jj_la1_init_0();
417    }
418    private static void jj_la1_init_0() {
419       jj_la1_0 = new int[] {};
420    }
421   final private JJCalls[] jj_2_rtns = new JJCalls[13];
422   private boolean jj_rescan = false;
423   private int jj_gc = 0;
424 
425   /** Constructor with InputStream. */
426   public GroupMatcherParser(java.io.InputStream stream) {
427      this(stream, null);
428   }
429   /** Constructor with InputStream and supplied encoding */
430   public GroupMatcherParser(java.io.InputStream stream, String encoding) {
431     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
432     token_source = new GroupMatcherParserTokenManager(jj_input_stream);
433     token = new Token();
434     jj_ntk = -1;
435     jj_gen = 0;
436     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
437     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
438   }
439 
440   /** Reinitialise. */
441   public void ReInit(java.io.InputStream stream) {
442      ReInit(stream, null);
443   }
444   /** Reinitialise. */
445   public void ReInit(java.io.InputStream stream, String encoding) {
446     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
447     token_source.ReInit(jj_input_stream);
448     token = new Token();
449     jj_ntk = -1;
450     jj_gen = 0;
451     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
452     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
453   }
454 
455   /** Constructor. */
456   public GroupMatcherParser(java.io.Reader stream) {
457     jj_input_stream = new SimpleCharStream(stream, 1, 1);
458     token_source = new GroupMatcherParserTokenManager(jj_input_stream);
459     token = new Token();
460     jj_ntk = -1;
461     jj_gen = 0;
462     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
463     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
464   }
465 
466   /** Reinitialise. */
467   public void ReInit(java.io.Reader stream) {
468     jj_input_stream.ReInit(stream, 1, 1);
469     token_source.ReInit(jj_input_stream);
470     token = new Token();
471     jj_ntk = -1;
472     jj_gen = 0;
473     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
474     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
475   }
476 
477   /** Constructor with generated Token Manager. */
478   public GroupMatcherParser(GroupMatcherParserTokenManager tm) {
479     token_source = tm;
480     token = new Token();
481     jj_ntk = -1;
482     jj_gen = 0;
483     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
484     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
485   }
486 
487   /** Reinitialise. */
488   public void ReInit(GroupMatcherParserTokenManager tm) {
489     token_source = tm;
490     token = new Token();
491     jj_ntk = -1;
492     jj_gen = 0;
493     for (int i = 0; i < 0; i++) jj_la1[i] = -1;
494     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
495   }
496 
497   private Token jj_consume_token(int kind) throws ParseException {
498     Token oldToken;
499     if ((oldToken = token).next != null) token = token.next;
500     else token = token.next = token_source.getNextToken();
501     jj_ntk = -1;
502     if (token.kind == kind) {
503       jj_gen++;
504       if (++jj_gc > 100) {
505         jj_gc = 0;
506         for (int i = 0; i < jj_2_rtns.length; i++) {
507           JJCalls c = jj_2_rtns[i];
508           while (c != null) {
509             if (c.gen < jj_gen) c.first = null;
510             c = c.next;
511           }
512         }
513       }
514       return token;
515     }
516     token = oldToken;
517     jj_kind = kind;
518     throw generateParseException();
519   }
520 
521   static private final class LookaheadSuccess extends java.lang.Error { }
522   final private LookaheadSuccess jj_ls = new LookaheadSuccess();
523   private boolean jj_scan_token(int kind) {
524     if (jj_scanpos == jj_lastpos) {
525       jj_la--;
526       if (jj_scanpos.next == null) {
527         jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
528       } else {
529         jj_lastpos = jj_scanpos = jj_scanpos.next;
530       }
531     } else {
532       jj_scanpos = jj_scanpos.next;
533     }
534     if (jj_rescan) {
535       int i = 0; Token tok = token;
536       while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
537       if (tok != null) jj_add_error_token(kind, i);
538     }
539     if (jj_scanpos.kind != kind) return true;
540     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
541     return false;
542   }
543 
544 
545 /** Get the next Token. */
546   final public Token getNextToken() {
547     if (token.next != null) token = token.next;
548     else token = token.next = token_source.getNextToken();
549     jj_ntk = -1;
550     jj_gen++;
551     return token;
552   }
553 
554 /** Get the specific Token. */
555   final public Token getToken(int index) {
556     Token t = token;
557     for (int i = 0; i < index; i++) {
558       if (t.next != null) t = t.next;
559       else t = t.next = token_source.getNextToken();
560     }
561     return t;
562   }
563 
564   private int jj_ntk() {
565     if ((jj_nt=token.next) == null)
566       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
567     else
568       return (jj_ntk = jj_nt.kind);
569   }
570 
571   private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
572   private int[] jj_expentry;
573   private int jj_kind = -1;
574   private int[] jj_lasttokens = new int[100];
575   private int jj_endpos;
576 
577   private void jj_add_error_token(int kind, int pos) {
578     if (pos >= 100) return;
579     if (pos == jj_endpos + 1) {
580       jj_lasttokens[jj_endpos++] = kind;
581     } else if (jj_endpos != 0) {
582       jj_expentry = new int[jj_endpos];
583       for (int i = 0; i < jj_endpos; i++) {
584         jj_expentry[i] = jj_lasttokens[i];
585       }
586       jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) {
587         int[] oldentry = (int[])(it.next());
588         if (oldentry.length == jj_expentry.length) {
589           for (int i = 0; i < jj_expentry.length; i++) {
590             if (oldentry[i] != jj_expentry[i]) {
591               continue jj_entries_loop;
592             }
593           }
594           jj_expentries.add(jj_expentry);
595           break jj_entries_loop;
596         }
597       }
598       if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
599     }
600   }
601 
602   /** Generate ParseException. */
603   public ParseException generateParseException() {
604     jj_expentries.clear();
605     boolean[] la1tokens = new boolean[16];
606     if (jj_kind >= 0) {
607       la1tokens[jj_kind] = true;
608       jj_kind = -1;
609     }
610     for (int i = 0; i < 0; i++) {
611       if (jj_la1[i] == jj_gen) {
612         for (int j = 0; j < 32; j++) {
613           if ((jj_la1_0[i] & (1<<j)) != 0) {
614             la1tokens[j] = true;
615           }
616         }
617       }
618     }
619     for (int i = 0; i < 16; i++) {
620       if (la1tokens[i]) {
621         jj_expentry = new int[1];
622         jj_expentry[0] = i;
623         jj_expentries.add(jj_expentry);
624       }
625     }
626     jj_endpos = 0;
627     jj_rescan_token();
628     jj_add_error_token(0, 0);
629     int[][] exptokseq = new int[jj_expentries.size()][];
630     for (int i = 0; i < jj_expentries.size(); i++) {
631       exptokseq[i] = jj_expentries.get(i);
632     }
633     return new ParseException(token, exptokseq, tokenImage);
634   }
635 
636   /** Enable tracing. */
637   final public void enable_tracing() {
638   }
639 
640   /** Disable tracing. */
641   final public void disable_tracing() {
642   }
643 
644   private void jj_rescan_token() {
645     jj_rescan = true;
646     for (int i = 0; i < 13; i++) {
647     try {
648       JJCalls p = jj_2_rtns[i];
649       do {
650         if (p.gen > jj_gen) {
651           jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
652           switch (i) {
653             case 0: jj_3_1(); break;
654             case 1: jj_3_2(); break;
655             case 2: jj_3_3(); break;
656             case 3: jj_3_4(); break;
657             case 4: jj_3_5(); break;
658             case 5: jj_3_6(); break;
659             case 6: jj_3_7(); break;
660             case 7: jj_3_8(); break;
661             case 8: jj_3_9(); break;
662             case 9: jj_3_10(); break;
663             case 10: jj_3_11(); break;
664             case 11: jj_3_12(); break;
665             case 12: jj_3_13(); break;
666           }
667         }
668         p = p.next;
669       } while (p != null);
670       } catch(LookaheadSuccess ls) { }
671     }
672     jj_rescan = false;
673   }
674 
675   private void jj_save(int index, int xla) {
676     JJCalls p = jj_2_rtns[index];
677     while (p.gen > jj_gen) {
678       if (p.next == null) { p = p.next = new JJCalls(); break; }
679       p = p.next;
680     }
681     p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
682   }
683 
684   static final class JJCalls {
685     int gen;
686     Token first;
687     int arg;
688     JJCalls next;
689   }
690 
691 }