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