001 // $ANTLR 2.7.4: "SubtreeSpecificationChecker.g" -> "AntlrSubtreeSpecificationChecker.java"$
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 *
021 */
022
023
024 package org.apache.directory.shared.ldap.subtree;
025
026 import org.apache.directory.shared.ldap.name.LdapDN;
027 import org.apache.directory.shared.ldap.filter.FilterParser;
028 import org.apache.directory.shared.ldap.util.ComponentsMonitor;
029 import org.apache.directory.shared.ldap.util.OptionalComponentsMonitor;
030
031 import org.slf4j.Logger;
032 import org.slf4j.LoggerFactory;
033
034 import antlr.TokenBuffer;
035 import antlr.TokenStreamException;
036 import antlr.TokenStreamIOException;
037 import antlr.ANTLRException;
038 import antlr.LLkParser;
039 import antlr.Token;
040 import antlr.TokenStream;
041 import antlr.RecognitionException;
042 import antlr.NoViableAltException;
043 import antlr.MismatchedTokenException;
044 import antlr.SemanticException;
045 import antlr.ParserSharedInputState;
046 import antlr.collections.impl.BitSet;
047
048 /**
049 * The antlr generated subtree specification parser.
050 *
051 * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
052 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
053 * @version $Rev$
054 */
055 public class AntlrSubtreeSpecificationChecker extends antlr.LLkParser implements AntlrSubtreeSpecificationCheckerTokenTypes
056 {
057
058 private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationChecker.class );
059
060 private ComponentsMonitor subtreeSpecificationComponentsMonitor = null;
061
062 /**
063 * Does nothing.
064 */
065 public void init()
066 {
067 }
068
069
070 private int token2Integer( Token token ) throws RecognitionException
071 {
072 int i = 0;
073
074 try
075 {
076 i = Integer.parseInt( token.getText());
077 }
078 catch ( NumberFormatException e )
079 {
080 throw new RecognitionException( "Value of INTEGER token " +
081 token.getText() +
082 " cannot be converted to an Integer" );
083 }
084
085 return i;
086 }
087
088 protected AntlrSubtreeSpecificationChecker(TokenBuffer tokenBuf, int k) {
089 super(tokenBuf,k);
090 tokenNames = _tokenNames;
091 }
092
093 public AntlrSubtreeSpecificationChecker(TokenBuffer tokenBuf) {
094 this(tokenBuf,1);
095 }
096
097 protected AntlrSubtreeSpecificationChecker(TokenStream lexer, int k) {
098 super(lexer,k);
099 tokenNames = _tokenNames;
100 }
101
102 public AntlrSubtreeSpecificationChecker(TokenStream lexer) {
103 this(lexer,1);
104 }
105
106 public AntlrSubtreeSpecificationChecker(ParserSharedInputState state) {
107 super(state,1);
108 tokenNames = _tokenNames;
109 }
110
111 public final void wrapperEntryPoint() throws RecognitionException, TokenStreamException {
112
113
114 log.debug( "entered wrapperEntryPoint()" );
115
116
117 subtreeSpecification();
118 match(LITERAL_end);
119 }
120
121 public final void subtreeSpecification() throws RecognitionException, TokenStreamException {
122
123
124 log.debug( "entered subtreeSpecification()" );
125 subtreeSpecificationComponentsMonitor = new OptionalComponentsMonitor(
126 new String [] { "base", "specificExclusions", "minimum", "maximum", "specificationFilter" } );
127
128
129 match(OPEN_CURLY);
130 {
131 _loop1561:
132 do {
133 if ((LA(1)==SP)) {
134 match(SP);
135 }
136 else {
137 break _loop1561;
138 }
139
140 } while (true);
141 }
142 {
143 switch ( LA(1)) {
144 case ID_base:
145 case ID_specificExclusions:
146 case ID_minimum:
147 case ID_maximum:
148 case ID_specificationFilter:
149 {
150 subtreeSpecificationComponent();
151 {
152 _loop1564:
153 do {
154 if ((LA(1)==SP)) {
155 match(SP);
156 }
157 else {
158 break _loop1564;
159 }
160
161 } while (true);
162 }
163 {
164 _loop1570:
165 do {
166 if ((LA(1)==SEP)) {
167 match(SEP);
168 {
169 _loop1567:
170 do {
171 if ((LA(1)==SP)) {
172 match(SP);
173 }
174 else {
175 break _loop1567;
176 }
177
178 } while (true);
179 }
180 subtreeSpecificationComponent();
181 {
182 _loop1569:
183 do {
184 if ((LA(1)==SP)) {
185 match(SP);
186 }
187 else {
188 break _loop1569;
189 }
190
191 } while (true);
192 }
193 }
194 else {
195 break _loop1570;
196 }
197
198 } while (true);
199 }
200 break;
201 }
202 case CLOSE_CURLY:
203 {
204 break;
205 }
206 default:
207 {
208 throw new NoViableAltException(LT(1), getFilename());
209 }
210 }
211 }
212 match(CLOSE_CURLY);
213 }
214
215 public final void subtreeSpecificationComponent() throws RecognitionException, TokenStreamException {
216
217
218 log.debug( "entered subtreeSpecification()" );
219
220
221 try { // for error handling
222 switch ( LA(1)) {
223 case ID_base:
224 {
225 ss_base();
226
227 subtreeSpecificationComponentsMonitor.useComponent( "base" );
228
229 break;
230 }
231 case ID_specificExclusions:
232 {
233 ss_specificExclusions();
234
235 subtreeSpecificationComponentsMonitor.useComponent( "specificExclusions" );
236
237 break;
238 }
239 case ID_minimum:
240 {
241 ss_minimum();
242
243 subtreeSpecificationComponentsMonitor.useComponent( "minimum" );
244
245 break;
246 }
247 case ID_maximum:
248 {
249 ss_maximum();
250
251 subtreeSpecificationComponentsMonitor.useComponent( "maximum" );
252
253 break;
254 }
255 case ID_specificationFilter:
256 {
257 ss_specificationFilter();
258
259 subtreeSpecificationComponentsMonitor.useComponent( "specificationFilter" );
260
261 break;
262 }
263 default:
264 {
265 throw new NoViableAltException(LT(1), getFilename());
266 }
267 }
268 }
269 catch (IllegalArgumentException e) {
270
271 throw new RecognitionException( e.getMessage() );
272
273 }
274 }
275
276 public final void ss_base() throws RecognitionException, TokenStreamException {
277
278
279 log.debug( "entered ss_base()" );
280
281
282 match(ID_base);
283 {
284 int _cnt1574=0;
285 _loop1574:
286 do {
287 if ((LA(1)==SP)) {
288 match(SP);
289 }
290 else {
291 if ( _cnt1574>=1 ) { break _loop1574; } else {throw new NoViableAltException(LT(1), getFilename());}
292 }
293
294 _cnt1574++;
295 } while (true);
296 }
297 distinguishedName();
298 }
299
300 public final void ss_specificExclusions() throws RecognitionException, TokenStreamException {
301
302
303 log.debug( "entered ss_specificExclusions()" );
304
305
306 match(ID_specificExclusions);
307 {
308 int _cnt1577=0;
309 _loop1577:
310 do {
311 if ((LA(1)==SP)) {
312 match(SP);
313 }
314 else {
315 if ( _cnt1577>=1 ) { break _loop1577; } else {throw new NoViableAltException(LT(1), getFilename());}
316 }
317
318 _cnt1577++;
319 } while (true);
320 }
321 specificExclusions();
322 }
323
324 public final void ss_minimum() throws RecognitionException, TokenStreamException {
325
326
327 log.debug( "entered ss_minimum()" );
328
329
330 match(ID_minimum);
331 {
332 int _cnt1603=0;
333 _loop1603:
334 do {
335 if ((LA(1)==SP)) {
336 match(SP);
337 }
338 else {
339 if ( _cnt1603>=1 ) { break _loop1603; } else {throw new NoViableAltException(LT(1), getFilename());}
340 }
341
342 _cnt1603++;
343 } while (true);
344 }
345 baseDistance();
346 }
347
348 public final void ss_maximum() throws RecognitionException, TokenStreamException {
349
350
351 log.debug( "entered ss_maximum()" );
352
353
354 match(ID_maximum);
355 {
356 int _cnt1606=0;
357 _loop1606:
358 do {
359 if ((LA(1)==SP)) {
360 match(SP);
361 }
362 else {
363 if ( _cnt1606>=1 ) { break _loop1606; } else {throw new NoViableAltException(LT(1), getFilename());}
364 }
365
366 _cnt1606++;
367 } while (true);
368 }
369 baseDistance();
370 }
371
372 public final void ss_specificationFilter() throws RecognitionException, TokenStreamException {
373
374
375 log.debug( "entered ss_specificationFilter()" );
376
377
378 match(ID_specificationFilter);
379 {
380 int _cnt1609=0;
381 _loop1609:
382 do {
383 if ((LA(1)==SP)) {
384 match(SP);
385 }
386 else {
387 if ( _cnt1609>=1 ) { break _loop1609; } else {throw new NoViableAltException(LT(1), getFilename());}
388 }
389
390 _cnt1609++;
391 } while (true);
392 }
393 {
394 switch ( LA(1)) {
395 case ID_item:
396 case ID_and:
397 case ID_or:
398 case ID_not:
399 {
400 {
401 refinement();
402 }
403 break;
404 }
405 case FILTER:
406 {
407 {
408 filter();
409 }
410 break;
411 }
412 default:
413 {
414 throw new NoViableAltException(LT(1), getFilename());
415 }
416 }
417 }
418 }
419
420 public final void distinguishedName() throws RecognitionException, TokenStreamException {
421
422 Token token = null;
423
424 log.debug( "entered distinguishedName()" );
425
426
427 try { // for error handling
428 token = LT(1);
429 match(SAFEUTF8STRING);
430
431 new LdapDN( token.getText() );
432 log.debug( "recognized a DistinguishedName: " + token.getText() );
433
434 }
435 catch (Exception e) {
436
437 throw new RecognitionException( "dnParser failed for " + token.getText() + " " + e.getMessage() );
438
439 }
440 }
441
442 public final void specificExclusions() throws RecognitionException, TokenStreamException {
443
444
445 log.debug( "entered specificExclusions()" );
446
447
448 match(OPEN_CURLY);
449 {
450 _loop1580:
451 do {
452 if ((LA(1)==SP)) {
453 match(SP);
454 }
455 else {
456 break _loop1580;
457 }
458
459 } while (true);
460 }
461 {
462 switch ( LA(1)) {
463 case ID_chopBefore:
464 case ID_chopAfter:
465 {
466 specificExclusion();
467 {
468 _loop1583:
469 do {
470 if ((LA(1)==SP)) {
471 match(SP);
472 }
473 else {
474 break _loop1583;
475 }
476
477 } while (true);
478 }
479 {
480 _loop1589:
481 do {
482 if ((LA(1)==SEP)) {
483 match(SEP);
484 {
485 _loop1586:
486 do {
487 if ((LA(1)==SP)) {
488 match(SP);
489 }
490 else {
491 break _loop1586;
492 }
493
494 } while (true);
495 }
496 specificExclusion();
497 {
498 _loop1588:
499 do {
500 if ((LA(1)==SP)) {
501 match(SP);
502 }
503 else {
504 break _loop1588;
505 }
506
507 } while (true);
508 }
509 }
510 else {
511 break _loop1589;
512 }
513
514 } while (true);
515 }
516 break;
517 }
518 case CLOSE_CURLY:
519 {
520 break;
521 }
522 default:
523 {
524 throw new NoViableAltException(LT(1), getFilename());
525 }
526 }
527 }
528 match(CLOSE_CURLY);
529 }
530
531 public final void specificExclusion() throws RecognitionException, TokenStreamException {
532
533
534 log.debug( "entered specificExclusion()" );
535
536
537 switch ( LA(1)) {
538 case ID_chopBefore:
539 {
540 chopBefore();
541 break;
542 }
543 case ID_chopAfter:
544 {
545 chopAfter();
546 break;
547 }
548 default:
549 {
550 throw new NoViableAltException(LT(1), getFilename());
551 }
552 }
553 }
554
555 public final void chopBefore() throws RecognitionException, TokenStreamException {
556
557
558 log.debug( "entered chopBefore()" );
559
560
561 match(ID_chopBefore);
562 {
563 _loop1593:
564 do {
565 if ((LA(1)==SP)) {
566 match(SP);
567 }
568 else {
569 break _loop1593;
570 }
571
572 } while (true);
573 }
574 match(COLON);
575 {
576 _loop1595:
577 do {
578 if ((LA(1)==SP)) {
579 match(SP);
580 }
581 else {
582 break _loop1595;
583 }
584
585 } while (true);
586 }
587 distinguishedName();
588 }
589
590 public final void chopAfter() throws RecognitionException, TokenStreamException {
591
592
593 log.debug( "entered chopAfter()" );
594
595
596 match(ID_chopAfter);
597 {
598 _loop1598:
599 do {
600 if ((LA(1)==SP)) {
601 match(SP);
602 }
603 else {
604 break _loop1598;
605 }
606
607 } while (true);
608 }
609 match(COLON);
610 {
611 _loop1600:
612 do {
613 if ((LA(1)==SP)) {
614 match(SP);
615 }
616 else {
617 break _loop1600;
618 }
619
620 } while (true);
621 }
622 distinguishedName();
623 }
624
625 public final void baseDistance() throws RecognitionException, TokenStreamException {
626
627 Token token = null;
628
629 log.debug( "entered baseDistance()" );
630
631
632 token = LT(1);
633 match(INTEGER);
634
635 token2Integer(token);
636
637 }
638
639 public final void refinement() throws RecognitionException, TokenStreamException {
640
641
642 log.debug( "entered refinement()" );
643
644
645 switch ( LA(1)) {
646 case ID_item:
647 {
648 item();
649 break;
650 }
651 case ID_and:
652 {
653 and();
654 break;
655 }
656 case ID_or:
657 {
658 or();
659 break;
660 }
661 case ID_not:
662 {
663 not();
664 break;
665 }
666 default:
667 {
668 throw new NoViableAltException(LT(1), getFilename());
669 }
670 }
671 }
672
673 public final void filter() throws RecognitionException, TokenStreamException {
674
675 Token filterToken = null;
676
677 log.debug( "entered filter()" );
678
679
680 try { // for error handling
681 {
682 filterToken = LT(1);
683 match(FILTER);
684 FilterParser.parse( filterToken.getText() );
685 }
686 }
687 catch (Exception e) {
688
689 throw new RecognitionException( "filterParser failed. " + e.getMessage() );
690
691 }
692 }
693
694 public final void oid() throws RecognitionException, TokenStreamException {
695
696
697 log.debug( "entered oid()" );
698 Token token = null;
699
700
701 token = LT( 1 );
702 {
703 switch ( LA(1)) {
704 case DESCR:
705 {
706 match(DESCR);
707 break;
708 }
709 case NUMERICOID:
710 {
711 match(NUMERICOID);
712 break;
713 }
714 default:
715 {
716 throw new NoViableAltException(LT(1), getFilename());
717 }
718 }
719 }
720
721 log.debug( "recognized an oid: " + token.getText() );
722
723 }
724
725 public final void item() throws RecognitionException, TokenStreamException {
726
727
728 log.debug( "entered item()" );
729
730
731 match(ID_item);
732 {
733 _loop1622:
734 do {
735 if ((LA(1)==SP)) {
736 match(SP);
737 }
738 else {
739 break _loop1622;
740 }
741
742 } while (true);
743 }
744 match(COLON);
745 {
746 _loop1624:
747 do {
748 if ((LA(1)==SP)) {
749 match(SP);
750 }
751 else {
752 break _loop1624;
753 }
754
755 } while (true);
756 }
757 oid();
758 }
759
760 public final void and() throws RecognitionException, TokenStreamException {
761
762
763 log.debug( "entered and()" );
764
765
766 match(ID_and);
767 {
768 _loop1627:
769 do {
770 if ((LA(1)==SP)) {
771 match(SP);
772 }
773 else {
774 break _loop1627;
775 }
776
777 } while (true);
778 }
779 match(COLON);
780 {
781 _loop1629:
782 do {
783 if ((LA(1)==SP)) {
784 match(SP);
785 }
786 else {
787 break _loop1629;
788 }
789
790 } while (true);
791 }
792 refinements();
793 }
794
795 public final void or() throws RecognitionException, TokenStreamException {
796
797
798 log.debug( "entered or()" );
799
800
801 match(ID_or);
802 {
803 _loop1632:
804 do {
805 if ((LA(1)==SP)) {
806 match(SP);
807 }
808 else {
809 break _loop1632;
810 }
811
812 } while (true);
813 }
814 match(COLON);
815 {
816 _loop1634:
817 do {
818 if ((LA(1)==SP)) {
819 match(SP);
820 }
821 else {
822 break _loop1634;
823 }
824
825 } while (true);
826 }
827 refinements();
828 }
829
830 public final void not() throws RecognitionException, TokenStreamException {
831
832
833 log.debug( "entered not()" );
834
835
836 match(ID_not);
837 {
838 _loop1637:
839 do {
840 if ((LA(1)==SP)) {
841 match(SP);
842 }
843 else {
844 break _loop1637;
845 }
846
847 } while (true);
848 }
849 match(COLON);
850 {
851 _loop1639:
852 do {
853 if ((LA(1)==SP)) {
854 match(SP);
855 }
856 else {
857 break _loop1639;
858 }
859
860 } while (true);
861 }
862 refinements();
863 }
864
865 public final void refinements() throws RecognitionException, TokenStreamException {
866
867
868 log.debug( "entered refinements()" );
869
870
871 match(OPEN_CURLY);
872 {
873 _loop1642:
874 do {
875 if ((LA(1)==SP)) {
876 match(SP);
877 }
878 else {
879 break _loop1642;
880 }
881
882 } while (true);
883 }
884 {
885 switch ( LA(1)) {
886 case ID_item:
887 case ID_and:
888 case ID_or:
889 case ID_not:
890 {
891 refinement();
892 {
893 _loop1645:
894 do {
895 if ((LA(1)==SP)) {
896 match(SP);
897 }
898 else {
899 break _loop1645;
900 }
901
902 } while (true);
903 }
904 {
905 _loop1651:
906 do {
907 if ((LA(1)==SEP)) {
908 match(SEP);
909 {
910 _loop1648:
911 do {
912 if ((LA(1)==SP)) {
913 match(SP);
914 }
915 else {
916 break _loop1648;
917 }
918
919 } while (true);
920 }
921 refinement();
922 {
923 _loop1650:
924 do {
925 if ((LA(1)==SP)) {
926 match(SP);
927 }
928 else {
929 break _loop1650;
930 }
931
932 } while (true);
933 }
934 }
935 else {
936 break _loop1651;
937 }
938
939 } while (true);
940 }
941 break;
942 }
943 case CLOSE_CURLY:
944 {
945 break;
946 }
947 default:
948 {
949 throw new NoViableAltException(LT(1), getFilename());
950 }
951 }
952 }
953 match(CLOSE_CURLY);
954 }
955
956
957 public static final String[] _tokenNames = {
958 "<0>",
959 "EOF",
960 "<2>",
961 "NULL_TREE_LOOKAHEAD",
962 "\"end\"",
963 "OPEN_CURLY",
964 "SP",
965 "SEP",
966 "CLOSE_CURLY",
967 "\"base\"",
968 "\"specificExclusions\"",
969 "\"chopBefore\"",
970 "COLON",
971 "\"chopAfter\"",
972 "\"minimum\"",
973 "\"maximum\"",
974 "\"specificationFilter\"",
975 "FILTER",
976 "SAFEUTF8STRING",
977 "INTEGER",
978 "DESCR",
979 "NUMERICOID",
980 "\"item\"",
981 "\"and\"",
982 "\"or\"",
983 "\"not\"",
984 "INTEGER_OR_NUMERICOID",
985 "DOT",
986 "DIGIT",
987 "LDIGIT",
988 "ALPHA",
989 "SAFEUTF8CHAR",
990 "FILTER_VALUE"
991 };
992
993
994 }