KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > n3 > N3AntlrParser


1 // $ANTLR 2.7.2: "src/com/hp/hpl/jena/n3/n3.g" -> "N3AntlrParser.java"$
2

3 package com.hp.hpl.jena.n3 ;
4 import antlr.TokenStreamRecognitionException ;
5
6 import antlr.TokenBuffer;
7 import antlr.TokenStreamException;
8 import antlr.Token;
9 import antlr.TokenStream;
10 import antlr.RecognitionException;
11 import antlr.NoViableAltException;
12 import antlr.SemanticException;
13 import antlr.ParserSharedInputState;
14 import antlr.collections.impl.BitSet;
15 import antlr.collections.AST;
16 import antlr.ASTFactory;
17 import antlr.ASTPair;
18 import antlr.collections.impl.ASTArray;
19
20 public class N3AntlrParser extends antlr.LLkParser implements N3AntlrParserTokenTypes
21  {
22
23     // Extra code for the parser.
24

25     boolean emitListTypeQuad = false ;
26
27     N3AntlrLexer lexer = null ;
28     void setLexer(N3AntlrLexer _lexer) { lexer = _lexer ; }
29
30     // Internallly generated anon id. Avoid clash with _:xxx
31
private int anonId = 0 ;
32     private String JavaDoc genAnonId() { return "=:"+(anonId++) ; }
33
34     // Forumla zero is the outer context. Avoid clash with other labels.
35
private int formulaId = 1 ;
36     private String JavaDoc genFormulaId() { return "{}:"+(formulaId++) ; }
37
38     private N3ParserEventHandler handler = null ;
39
40     public void setEventHandler(N3ParserEventHandler h) { this.handler = h ; }
41
42     private void startDocument()
43     {
44         if ( handler == null )
45             throw new RuntimeException JavaDoc("N3AntlrParser: No sink specified") ;
46         handler.startDocument() ;
47     }
48
49     private void endDocument() { handler.endDocument() ; }
50
51
52     private void startFormula(String JavaDoc context)
53     {
54         handler.startFormula(lexer.getLine(), context) ;
55     }
56
57     private void endFormula(String JavaDoc context)
58     {
59         handler.endFormula(lexer.getLine(), context) ;
60     }
61
62     private String JavaDoc currentFormula = null ;
63
64     private void emitQuad(AST subj, AST prop, AST obj)
65     {
66         handler.quad(lexer.getLine(), subj, prop, obj, currentFormula ) ;
67     }
68
69     private void directive(AST directive, AST arg)
70     {
71         handler.directive(lexer.getLine(),
72                           directive, new AST[]{arg},
73                           currentFormula) ;
74     }
75
76     private void directive(AST directive, AST arg1, AST arg2)
77     {
78         handler.directive(lexer.getLine(),
79                           directive, new AST[]{arg1, arg2},
80                           currentFormula) ;
81     }
82
83     public void reportError(RecognitionException ex)
84     {
85         handler.error(ex, "N3 error: ["+ex.line+":"+ex.column+"] "+ex.getMessage());
86     }
87
88     /** Parser error-reporting function can be overridden in subclass */
89     public void reportError(String JavaDoc s)
90     {
91         //System.err.println("N3AntlrParser(s): "+s);
92
handler.error(null, "N3AntlrParser(s): ["+lexer.getLine()+":"+lexer.getColumn()+"] "+s) ;
93     }
94
95 protected N3AntlrParser(TokenBuffer tokenBuf, int k) {
96   super(tokenBuf,k);
97   tokenNames = _tokenNames;
98   buildTokenTypeASTClassMap();
99   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
100 }
101
102 public N3AntlrParser(TokenBuffer tokenBuf) {
103   this(tokenBuf,1);
104 }
105
106 protected N3AntlrParser(TokenStream lexer, int k) {
107   super(lexer,k);
108   tokenNames = _tokenNames;
109   buildTokenTypeASTClassMap();
110   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
111 }
112
113 public N3AntlrParser(TokenStream lexer) {
114   this(lexer,1);
115 }
116
117 public N3AntlrParser(ParserSharedInputState state) {
118   super(state,1);
119   tokenNames = _tokenNames;
120   buildTokenTypeASTClassMap();
121   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
122 }
123
124     public final void document() throws RecognitionException, TokenStreamException {
125         
126         returnAST = null;
127         ASTPair currentAST = new ASTPair();
128         AST document_AST = null;
129         
130         try { // for error handling
131
if ( inputState.guessing==0 ) {
132                 startDocument() ;
133             }
134             {
135             _loop3:
136             do {
137                 switch ( LA(1)) {
138                 case AT_PREFIX:
139                 {
140                     n3Directive();
141                     break;
142                 }
143                 case QNAME:
144                 case KW_THIS:
145                 case STRING:
146                 case LBRACK:
147                 case LCURLY:
148                 case LPAREN:
149                 case NUMBER:
150                 case URIREF:
151                 case UVAR:
152                 {
153                     statement();
154                     break;
155                 }
156                 default:
157                 {
158                     break _loop3;
159                 }
160                 }
161             } while (true);
162             }
163             if ( inputState.guessing==0 ) {
164                 endDocument() ;
165             }
166             AST tmp1_AST = null;
167             tmp1_AST = astFactory.create(LT(1));
168             match(Token.EOF_TYPE);
169         }
170         catch (RecognitionException ex) {
171             if (inputState.guessing==0) {
172                 reportError(ex) ; throw ex ;
173             } else {
174                 throw ex;
175             }
176         }
177         catch (TokenStreamRecognitionException ex) {
178             if (inputState.guessing==0) {
179                 reportError(ex.recog) ; throw ex.recog ;
180             } else {
181                 throw ex;
182             }
183         }
184         returnAST = document_AST;
185     }
186     
187     public final void n3Directive() throws RecognitionException, TokenStreamException {
188         
189         returnAST = null;
190         ASTPair currentAST = new ASTPair();
191         AST n3Directive_AST = null;
192         
193         n3Directive0();
194         match(SEP);
195         returnAST = n3Directive_AST;
196     }
197     
198     public final void statement() throws RecognitionException, TokenStreamException {
199         
200         returnAST = null;
201         ASTPair currentAST = new ASTPair();
202         AST statement_AST = null;
203         
204         statement0();
205         match(SEP);
206         returnAST = statement_AST;
207     }
208     
209     public final void n3Directive0() throws RecognitionException, TokenStreamException {
210         
211         returnAST = null;
212         ASTPair currentAST = new ASTPair();
213         AST n3Directive0_AST = null;
214         Token d = null;
215         AST d_AST = null;
216         AST ns_AST = null;
217         AST u_AST = null;
218         
219         d = LT(1);
220         d_AST = astFactory.create(d);
221         match(AT_PREFIX);
222         nsprefix();
223         ns_AST = (AST)returnAST;
224         uriref();
225         u_AST = (AST)returnAST;
226         if ( inputState.guessing==0 ) {
227             directive(d_AST, ns_AST, u_AST);
228         }
229         returnAST = n3Directive0_AST;
230     }
231     
232     public final void nsprefix() throws RecognitionException, TokenStreamException {
233         
234         returnAST = null;
235         ASTPair currentAST = new ASTPair();
236         AST nsprefix_AST = null;
237         Token ns = null;
238         AST ns_AST = null;
239         
240         try { // for error handling
241
ns = LT(1);
242             ns_AST = astFactory.create(ns);
243             astFactory.addASTChild(currentAST, ns_AST);
244             match(QNAME);
245             if (!( ns.getText().endsWith(":") ))
246               throw new SemanticException(" ns.getText().endsWith(\":\") ");
247             nsprefix_AST = (AST)currentAST.root;
248         }
249         catch (SemanticException ex) {
250             if (inputState.guessing==0) {
251                 
252                         RecognitionException rEx =
253                 new RecognitionException("Illegal prefix: '"+ns.getText()+"'") ;
254                         rEx.line = lexer.getLine() ; rEx.column = lexer.getColumn() ;
255                         throw rEx ;
256                     
257             } else {
258                 throw ex;
259             }
260         }
261         returnAST = nsprefix_AST;
262     }
263     
264     public final void uriref() throws RecognitionException, TokenStreamException {
265         
266         returnAST = null;
267         ASTPair currentAST = new ASTPair();
268         AST uriref_AST = null;
269         
270         AST tmp4_AST = null;
271         tmp4_AST = astFactory.create(LT(1));
272         astFactory.addASTChild(currentAST, tmp4_AST);
273         match(URIREF);
274         uriref_AST = (AST)currentAST.root;
275         returnAST = uriref_AST;
276     }
277     
278     public final void statement0() throws RecognitionException, TokenStreamException {
279         
280         returnAST = null;
281         ASTPair currentAST = new ASTPair();
282         AST statement0_AST = null;
283         AST subj_AST = null;
284         
285         subject();
286         subj_AST = (AST)returnAST;
287         propertyList(subj_AST);
288         returnAST = statement0_AST;
289     }
290     
291     public final void subject() throws RecognitionException, TokenStreamException {
292         
293         returnAST = null;
294         ASTPair currentAST = new ASTPair();
295         AST subject_AST = null;
296         
297         item();
298         astFactory.addASTChild(currentAST, returnAST);
299         subject_AST = (AST)currentAST.root;
300         returnAST = subject_AST;
301     }
302     
303     public final void propertyList(
304         AST subj
305     ) throws RecognitionException, TokenStreamException {
306         
307         returnAST = null;
308         ASTPair currentAST = new ASTPair();
309         AST propertyList_AST = null;
310         
311         switch ( LA(1)) {
312         case NAME_OP:
313         {
314             match(NAME_OP);
315             anonnode(subj);
316             propertyList(subj);
317             break;
318         }
319         case QNAME:
320         case KW_THIS:
321         case KW_HAS:
322         case KW_A:
323         case KW_IS:
324         case STRING:
325         case EQUAL:
326         case ARROW_R:
327         case ARROW_L:
328         case ARROW_PATH_L:
329         case LBRACK:
330         case LCURLY:
331         case LPAREN:
332         case NUMBER:
333         case URIREF:
334         case UVAR:
335         {
336             propValue(subj);
337             {
338             switch ( LA(1)) {
339             case SEMI:
340             {
341                 AST tmp6_AST = null;
342                 tmp6_AST = astFactory.create(LT(1));
343                 match(SEMI);
344                 propertyList(subj);
345                 break;
346             }
347             case SEP:
348             case RBRACK:
349             case RCURLY:
350             {
351                 break;
352             }
353             default:
354             {
355                 throw new NoViableAltException(LT(1), getFilename());
356             }
357             }
358             }
359             break;
360         }
361         case SEP:
362         case RBRACK:
363         case RCURLY:
364         {
365             break;
366         }
367         default:
368         {
369             throw new NoViableAltException(LT(1), getFilename());
370         }
371         }
372         returnAST = propertyList_AST;
373     }
374     
375     public final void formulaList() throws RecognitionException, TokenStreamException {
376         
377         returnAST = null;
378         ASTPair currentAST = new ASTPair();
379         AST formulaList_AST = null;
380         
381         switch ( LA(1)) {
382         case QNAME:
383         case KW_THIS:
384         case AT_PREFIX:
385         case STRING:
386         case LBRACK:
387         case LCURLY:
388         case LPAREN:
389         case NUMBER:
390         case URIREF:
391         case UVAR:
392         {
393             {
394             switch ( LA(1)) {
395             case QNAME:
396             case KW_THIS:
397             case STRING:
398             case LBRACK:
399             case LCURLY:
400             case LPAREN:
401             case NUMBER:
402             case URIREF:
403             case UVAR:
404             {
405                 statement0();
406                 break;
407             }
408             case AT_PREFIX:
409             {
410                 n3Directive0();
411                 break;
412             }
413             default:
414             {
415                 throw new NoViableAltException(LT(1), getFilename());
416             }
417             }
418             }
419             {
420             switch ( LA(1)) {
421             case SEP:
422             {
423                 AST tmp7_AST = null;
424                 tmp7_AST = astFactory.create(LT(1));
425                 match(SEP);
426                 formulaList();
427                 break;
428             }
429             case RCURLY:
430             {
431                 break;
432             }
433             default:
434             {
435                 throw new NoViableAltException(LT(1), getFilename());
436             }
437             }
438             }
439             break;
440         }
441         case RCURLY:
442         {
443             break;
444         }
445         default:
446         {
447             throw new NoViableAltException(LT(1), getFilename());
448         }
449         }
450         returnAST = formulaList_AST;
451     }
452     
453     public final void item() throws RecognitionException, TokenStreamException {
454         
455         returnAST = null;
456         ASTPair currentAST = new ASTPair();
457         AST item_AST = null;
458         AST n_AST = null;
459         AST n1_AST = null;
460         AST n2_AST = null;
461         
462         node();
463         n_AST = (AST)returnAST;
464         astFactory.addASTChild(currentAST, returnAST);
465         {
466         _loop21:
467         do {
468             switch ( LA(1)) {
469             case PATH:
470             {
471                 match(PATH);
472                 node();
473                 n1_AST = (AST)returnAST;
474                 astFactory.addASTChild(currentAST, returnAST);
475                 if ( inputState.guessing==0 ) {
476                     
477                                 AST a1 = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(ANON,genAnonId()))) ;
478                                 emitQuad(n_AST, n1_AST, a1) ;
479                                 n_AST = a1 ;
480                             
481                 }
482                 break;
483             }
484             case RPATH:
485             {
486                 match(RPATH);
487                 node();
488                 n2_AST = (AST)returnAST;
489                 astFactory.addASTChild(currentAST, returnAST);
490                 if ( inputState.guessing==0 ) {
491                     
492                                 AST a2 = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(ANON,genAnonId()))) ;
493                                 emitQuad(a2, n2_AST, n_AST) ;
494                                 n_AST = a2 ;
495                             
496                 }
497                 break;
498             }
499             default:
500             {
501                 break _loop21;
502             }
503             }
504         } while (true);
505         }
506         if ( inputState.guessing==0 ) {
507             item_AST = (AST)currentAST.root;
508             item_AST = n_AST ;
509             currentAST.root = item_AST;
510             currentAST.child = item_AST!=null &&item_AST.getFirstChild()!=null ?
511                 item_AST.getFirstChild() : item_AST;
512             currentAST.advanceChildToEnd();
513         }
514         item_AST = (AST)currentAST.root;
515         returnAST = item_AST;
516     }
517     
518     public final void anonnode(
519         AST label
520     ) throws RecognitionException, TokenStreamException {
521         
522         returnAST = null;
523         ASTPair currentAST = new ASTPair();
524         AST anonnode_AST = null;
525         String JavaDoc oldCxt = null ; String JavaDoc cxt = null ;
526         
527         switch ( LA(1)) {
528         case LBRACK:
529         {
530             match(LBRACK);
531             if ( inputState.guessing==0 ) {
532                 anonnode_AST = (AST)currentAST.root;
533                 if ( label == null )
534                               label = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(ANON,genAnonId()))) ;
535                           anonnode_AST = label ;
536                         
537                 currentAST.root = anonnode_AST;
538                 currentAST.child = anonnode_AST!=null &&anonnode_AST.getFirstChild()!=null ?
539                     anonnode_AST.getFirstChild() : anonnode_AST;
540                 currentAST.advanceChildToEnd();
541             }
542             propertyList(label);
543             astFactory.addASTChild(currentAST, returnAST);
544             match(RBRACK);
545             anonnode_AST = (AST)currentAST.root;
546             break;
547         }
548         case LCURLY:
549         {
550             match(LCURLY);
551             if ( inputState.guessing==0 ) {
552                 anonnode_AST = (AST)currentAST.root;
553                 oldCxt = currentFormula ;
554                           if ( label == null )
555                               label = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(FORMULA,genFormulaId()))) ;
556                           cxt = label.getText() ;
557                           currentFormula = cxt ;
558                           startFormula(cxt) ;
559                           anonnode_AST = label ;
560                         
561                 currentAST.root = anonnode_AST;
562                 currentAST.child = anonnode_AST!=null &&anonnode_AST.getFirstChild()!=null ?
563                     anonnode_AST.getFirstChild() : anonnode_AST;
564                 currentAST.advanceChildToEnd();
565             }
566             formulaList();
567             astFactory.addASTChild(currentAST, returnAST);
568             if ( inputState.guessing==0 ) {
569                 endFormula(cxt) ; currentFormula = oldCxt ;
570             }
571             match(RCURLY);
572             anonnode_AST = (AST)currentAST.root;
573             break;
574         }
575         case LPAREN:
576         {
577             match(LPAREN);
578             list(label);
579             astFactory.addASTChild(currentAST, returnAST);
580             match(RPAREN);
581             anonnode_AST = (AST)currentAST.root;
582             break;
583         }
584         default:
585         {
586             throw new NoViableAltException(LT(1), getFilename());
587         }
588         }
589         returnAST = anonnode_AST;
590     }
591     
592     public final void propValue(
593         AST subj
594     ) throws RecognitionException, TokenStreamException {
595         
596         returnAST = null;
597         ASTPair currentAST = new ASTPair();
598         AST propValue_AST = null;
599         AST v1_AST = null;
600         AST v2_AST = null;
601         
602         switch ( LA(1)) {
603         case QNAME:
604         case KW_THIS:
605         case KW_HAS:
606         case KW_A:
607         case STRING:
608         case EQUAL:
609         case ARROW_R:
610         case ARROW_L:
611         case ARROW_PATH_L:
612         case LBRACK:
613         case LCURLY:
614         case LPAREN:
615         case NUMBER:
616         case URIREF:
617         case UVAR:
618         {
619             verb();
620             v1_AST = (AST)returnAST;
621             astFactory.addASTChild(currentAST, returnAST);
622             objectList(subj, v1_AST);
623             astFactory.addASTChild(currentAST, returnAST);
624             propValue_AST = (AST)currentAST.root;
625             break;
626         }
627         case KW_IS:
628         {
629             verbReverse();
630             v2_AST = (AST)returnAST;
631             astFactory.addASTChild(currentAST, returnAST);
632             subjectList(subj, v2_AST);
633             astFactory.addASTChild(currentAST, returnAST);
634             propValue_AST = (AST)currentAST.root;
635             break;
636         }
637         default:
638         {
639             throw new NoViableAltException(LT(1), getFilename());
640         }
641         }
642         returnAST = propValue_AST;
643     }
644     
645     public final void verb() throws RecognitionException, TokenStreamException {
646         
647         returnAST = null;
648         ASTPair currentAST = new ASTPair();
649         AST verb_AST = null;
650         
651         switch ( LA(1)) {
652         case QNAME:
653         case KW_THIS:
654         case STRING:
655         case LBRACK:
656         case LCURLY:
657         case LPAREN:
658         case NUMBER:
659         case URIREF:
660         case UVAR:
661         {
662             item();
663             astFactory.addASTChild(currentAST, returnAST);
664             verb_AST = (AST)currentAST.root;
665             break;
666         }
667         case KW_A:
668         {
669             kwA();
670             astFactory.addASTChild(currentAST, returnAST);
671             verb_AST = (AST)currentAST.root;
672             break;
673         }
674         case EQUAL:
675         {
676             AST tmp16_AST = null;
677             tmp16_AST = astFactory.create(LT(1));
678             astFactory.addASTChild(currentAST, tmp16_AST);
679             match(EQUAL);
680             verb_AST = (AST)currentAST.root;
681             break;
682         }
683         case ARROW_R:
684         {
685             AST tmp17_AST = null;
686             tmp17_AST = astFactory.create(LT(1));
687             astFactory.addASTChild(currentAST, tmp17_AST);
688             match(ARROW_R);
689             verb_AST = (AST)currentAST.root;
690             break;
691         }
692         case ARROW_L:
693         {
694             AST tmp18_AST = null;
695             tmp18_AST = astFactory.create(LT(1));
696             astFactory.addASTChild(currentAST, tmp18_AST);
697             match(ARROW_L);
698             verb_AST = (AST)currentAST.root;
699             break;
700         }
701         case ARROW_PATH_L:
702         {
703             match(ARROW_PATH_L);
704             node();
705             astFactory.addASTChild(currentAST, returnAST);
706             match(ARROW_PATH_R);
707             verb_AST = (AST)currentAST.root;
708             break;
709         }
710         case KW_HAS:
711         {
712             kwHAS();
713             item();
714             astFactory.addASTChild(currentAST, returnAST);
715             verb_AST = (AST)currentAST.root;
716             break;
717         }
718         default:
719         {
720             throw new NoViableAltException(LT(1), getFilename());
721         }
722         }
723         returnAST = verb_AST;
724     }
725     
726     public final void objectList(
727         AST subj, AST prop
728     ) throws RecognitionException, TokenStreamException {
729         
730         returnAST = null;
731         ASTPair currentAST = new ASTPair();
732         AST objectList_AST = null;
733         AST obj_AST = null;
734         
735         switch ( LA(1)) {
736         case QNAME:
737         case KW_THIS:
738         case STRING:
739         case LBRACK:
740         case LCURLY:
741         case LPAREN:
742         case NUMBER:
743         case URIREF:
744         case UVAR:
745         {
746             item();
747             obj_AST = (AST)returnAST;
748             if ( inputState.guessing==0 ) {
749                 emitQuad(subj,prop,obj_AST) ;
750             }
751             {
752             switch ( LA(1)) {
753             case COMMA:
754             {
755                 AST tmp21_AST = null;
756                 tmp21_AST = astFactory.create(LT(1));
757                 match(COMMA);
758                 objectList(subj, prop);
759                 break;
760             }
761             case SEP:
762             case SEMI:
763             case RBRACK:
764             case RCURLY:
765             {
766                 break;
767             }
768             default:
769             {
770                 throw new NoViableAltException(LT(1), getFilename());
771             }
772             }
773             }
774             break;
775         }
776         case SEP:
777         case SEMI:
778         case RBRACK:
779         case RCURLY:
780         {
781             break;
782         }
783         default:
784         {
785             throw new NoViableAltException(LT(1), getFilename());
786         }
787         }
788         returnAST = objectList_AST;
789     }
790     
791     public final void verbReverse() throws RecognitionException, TokenStreamException {
792         
793         returnAST = null;
794         ASTPair currentAST = new ASTPair();
795         AST verbReverse_AST = null;
796         AST n_AST = null;
797         
798         kwIS();
799         node();
800         n_AST = (AST)returnAST;
801         astFactory.addASTChild(currentAST, returnAST);
802         kwOF();
803         verbReverse_AST = (AST)currentAST.root;
804         returnAST = verbReverse_AST;
805     }
806     
807     public final void subjectList(
808         AST oldSub, AST prop
809     ) throws RecognitionException, TokenStreamException {
810         
811         returnAST = null;
812         ASTPair currentAST = new ASTPair();
813         AST subjectList_AST = null;
814         AST obj_AST = null;
815         
816         item();
817         obj_AST = (AST)returnAST;
818         if ( inputState.guessing==0 ) {
819             emitQuad(obj_AST, prop, oldSub) ;
820         }
821         {
822         switch ( LA(1)) {
823         case COMMA:
824         {
825             AST tmp22_AST = null;
826             tmp22_AST = astFactory.create(LT(1));
827             match(COMMA);
828             subjectList(oldSub, prop);
829             break;
830         }
831         case SEP:
832         case SEMI:
833         case RBRACK:
834         case RCURLY:
835         {
836             break;
837         }
838         default:
839         {
840             throw new NoViableAltException(LT(1), getFilename());
841         }
842         }
843         }
844         returnAST = subjectList_AST;
845     }
846     
847     public final void node() throws RecognitionException, TokenStreamException {
848         
849         returnAST = null;
850         ASTPair currentAST = new ASTPair();
851         AST node_AST = null;
852         
853         switch ( LA(1)) {
854         case QNAME:
855         {
856             qname();
857             astFactory.addASTChild(currentAST, returnAST);
858             node_AST = (AST)currentAST.root;
859             break;
860         }
861         case URIREF:
862         {
863             uriref();
864             astFactory.addASTChild(currentAST, returnAST);
865             node_AST = (AST)currentAST.root;
866             break;
867         }
868         case LBRACK:
869         case LCURLY:
870         case LPAREN:
871         {
872             anonnode(null);
873             astFactory.addASTChild(currentAST, returnAST);
874             node_AST = (AST)currentAST.root;
875             break;
876         }
877         case STRING:
878         case NUMBER:
879         {
880             literal();
881             astFactory.addASTChild(currentAST, returnAST);
882             node_AST = (AST)currentAST.root;
883             break;
884         }
885         case KW_THIS:
886         {
887             kwTHIS();
888             astFactory.addASTChild(currentAST, returnAST);
889             node_AST = (AST)currentAST.root;
890             break;
891         }
892         case UVAR:
893         {
894             variableDT();
895             astFactory.addASTChild(currentAST, returnAST);
896             node_AST = (AST)currentAST.root;
897             break;
898         }
899         default:
900         {
901             throw new NoViableAltException(LT(1), getFilename());
902         }
903         }
904         returnAST = node_AST;
905     }
906     
907     public final void testPoint() throws RecognitionException, TokenStreamException {
908         
909         returnAST = null;
910         ASTPair currentAST = new ASTPair();
911         AST testPoint_AST = null;
912         AST v_AST = null;
913         
914         verb();
915         v_AST = (AST)returnAST;
916         if ( inputState.guessing==0 ) {
917             AntlrUtils.ast(System.out, v_AST) ;
918         }
919         returnAST = testPoint_AST;
920     }
921     
922     public final void qname() throws RecognitionException, TokenStreamException {
923         
924         returnAST = null;
925         ASTPair currentAST = new ASTPair();
926         AST qname_AST = null;
927         
928         AST tmp23_AST = null;
929         tmp23_AST = astFactory.create(LT(1));
930         astFactory.addASTChild(currentAST, tmp23_AST);
931         match(QNAME);
932         qname_AST = (AST)currentAST.root;
933         returnAST = qname_AST;
934     }
935     
936     public final void literal() throws RecognitionException, TokenStreamException {
937         
938         returnAST = null;
939         ASTPair currentAST = new ASTPair();
940         AST literal_AST = null;
941         Token n = null;
942         AST n_AST = null;
943         Token s = null;
944         AST s_AST = null;
945         
946         switch ( LA(1)) {
947         case NUMBER:
948         {
949             n = LT(1);
950             n_AST = astFactory.create(n);
951             astFactory.addASTChild(currentAST, n_AST);
952             match(NUMBER);
953             literal_AST = (AST)currentAST.root;
954             break;
955         }
956         case STRING:
957         {
958             s = LT(1);
959             s_AST = astFactory.create(s);
960             astFactory.addASTChild(currentAST, s_AST);
961             match(STRING);
962             literalModifier();
963             astFactory.addASTChild(currentAST, returnAST);
964             if ( inputState.guessing==0 ) {
965                 literal_AST = (AST)currentAST.root;
966                 literal_AST.setType(LITERAL) ;
967             }
968             literal_AST = (AST)currentAST.root;
969             break;
970         }
971         default:
972         {
973             throw new NoViableAltException(LT(1), getFilename());
974         }
975         }
976         returnAST = literal_AST;
977     }
978     
979     public final void kwTHIS() throws RecognitionException, TokenStreamException {
980         
981         returnAST = null;
982         ASTPair currentAST = new ASTPair();
983         AST kwTHIS_AST = null;
984         
985         AST tmp24_AST = null;
986         tmp24_AST = astFactory.create(LT(1));
987         astFactory.addASTChild(currentAST, tmp24_AST);
988         match(KW_THIS);
989         kwTHIS_AST = (AST)currentAST.root;
990         returnAST = kwTHIS_AST;
991     }
992     
993     public final void variableDT() throws RecognitionException, TokenStreamException {
994         
995         returnAST = null;
996         ASTPair currentAST = new ASTPair();
997         AST variableDT_AST = null;
998         Token v = null;
999         AST v_AST = null;
1000        AST dt_AST = null;
1001        
1002        v = LT(1);
1003        v_AST = astFactory.create(v);
1004        astFactory.addASTChild(currentAST, v_AST);
1005        match(UVAR);
1006        {
1007        switch ( LA(1)) {
1008        case DATATYPE:
1009        {
1010            AST tmp25_AST = null;
1011            tmp25_AST = astFactory.create(LT(1));
1012            astFactory.addASTChild(currentAST, tmp25_AST);
1013            match(DATATYPE);
1014            datatype();
1015            dt_AST = (AST)returnAST;
1016            astFactory.addASTChild(currentAST, returnAST);
1017            break;
1018        }
1019        case EOF:
1020        case QNAME:
1021        case SEP:
1022        case NAME_OP:
1023        case KW_THIS:
1024        case KW_OF:
1025        case KW_HAS:
1026        case KW_A:
1027        case KW_IS:
1028        case STRING:
1029        case SEMI:
1030        case COMMA:
1031        case PATH:
1032        case RPATH:
1033        case EQUAL:
1034        case ARROW_R:
1035        case ARROW_L:
1036        case ARROW_PATH_L:
1037        case ARROW_PATH_R:
1038        case LBRACK:
1039        case RBRACK:
1040        case LCURLY:
1041        case RCURLY:
1042        case LPAREN:
1043        case RPAREN:
1044        case NUMBER:
1045        case URIREF:
1046        case UVAR:
1047        {
1048            break;
1049        }
1050        default:
1051        {
1052            throw new NoViableAltException(LT(1), getFilename());
1053        }
1054        }
1055        }
1056        if ( inputState.guessing==0 ) {
1057            variableDT_AST = (AST)currentAST.root;
1058            variableDT_AST = (AST)astFactory.make( (new ASTArray(2)).add(astFactory.create(UVAR,v.getText())).add(dt_AST)) ;
1059            currentAST.root = variableDT_AST;
1060            currentAST.child = variableDT_AST!=null &&variableDT_AST.getFirstChild()!=null ?
1061                variableDT_AST.getFirstChild() : variableDT_AST;
1062            currentAST.advanceChildToEnd();
1063        }
1064        variableDT_AST = (AST)currentAST.root;
1065        returnAST = variableDT_AST;
1066    }
1067    
1068    public final void kwOF() throws RecognitionException, TokenStreamException {
1069        
1070        returnAST = null;
1071        ASTPair currentAST = new ASTPair();
1072        AST kwOF_AST = null;
1073        
1074        AST tmp26_AST = null;
1075        tmp26_AST = astFactory.create(LT(1));
1076        match(KW_OF);
1077        returnAST = kwOF_AST;
1078    }
1079    
1080    public final void kwHAS() throws RecognitionException, TokenStreamException {
1081        
1082        returnAST = null;
1083        ASTPair currentAST = new ASTPair();
1084        AST kwHAS_AST = null;
1085        
1086        AST tmp27_AST = null;
1087        tmp27_AST = astFactory.create(LT(1));
1088        match(KW_HAS);
1089        returnAST = kwHAS_AST;
1090    }
1091    
1092    public final void kwA() throws RecognitionException, TokenStreamException {
1093        
1094        returnAST = null;
1095        ASTPair currentAST = new ASTPair();
1096        AST kwA_AST = null;
1097        
1098        AST tmp28_AST = null;
1099        tmp28_AST = astFactory.create(LT(1));
1100        astFactory.addASTChild(currentAST, tmp28_AST);
1101        match(KW_A);
1102        kwA_AST = (AST)currentAST.root;
1103        returnAST = kwA_AST;
1104    }
1105    
1106    public final void kwIS() throws RecognitionException, TokenStreamException {
1107        
1108        returnAST = null;
1109        ASTPair currentAST = new ASTPair();
1110        AST kwIS_AST = null;
1111        
1112        AST tmp29_AST = null;
1113        tmp29_AST = astFactory.create(LT(1));
1114        match(KW_IS);
1115        returnAST = kwIS_AST;
1116    }
1117    
1118    public final void list(
1119        AST label
1120    ) throws RecognitionException, TokenStreamException {
1121        
1122        returnAST = null;
1123        ASTPair currentAST = new ASTPair();
1124        AST list_AST = null;
1125        AST i_AST = null;
1126        AST n_AST = null;
1127        
1128        switch ( LA(1)) {
1129        case QNAME:
1130        case KW_THIS:
1131        case STRING:
1132        case LBRACK:
1133        case LCURLY:
1134        case LPAREN:
1135        case NUMBER:
1136        case URIREF:
1137        case UVAR:
1138        {
1139            item();
1140            i_AST = (AST)returnAST;
1141            astFactory.addASTChild(currentAST, returnAST);
1142            if ( inputState.guessing==0 ) {
1143                list_AST = (AST)currentAST.root;
1144                
1145                        if ( label == null )
1146                              label = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(ANON,genAnonId()))) ;
1147                        list_AST = label ;
1148                    
1149                currentAST.root = list_AST;
1150                currentAST.child = list_AST!=null &&list_AST.getFirstChild()!=null ?
1151                    list_AST.getFirstChild() : list_AST;
1152                currentAST.advanceChildToEnd();
1153            }
1154            list(null);
1155            n_AST = (AST)returnAST;
1156            astFactory.addASTChild(currentAST, returnAST);
1157            if ( inputState.guessing==0 ) {
1158                
1159                        if ( emitListTypeQuad )
1160                            emitQuad(label, (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(KW_A,"list"))), (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(TK_LIST,"List"))) );
1161                        emitQuad(label, (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(TK_LIST_FIRST,"first"))), i_AST);
1162                        emitQuad(label, (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(TK_LIST_REST,"rest"))), n_AST) ;
1163                    
1164            }
1165            list_AST = (AST)currentAST.root;
1166            break;
1167        }
1168        case RPAREN:
1169        {
1170            if ( inputState.guessing==0 ) {
1171                list_AST = (AST)currentAST.root;
1172                list_AST = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(TK_LIST_NIL,"nil")));
1173                currentAST.root = list_AST;
1174                currentAST.child = list_AST!=null &&list_AST.getFirstChild()!=null ?
1175                    list_AST.getFirstChild() : list_AST;
1176                currentAST.advanceChildToEnd();
1177            }
1178            list_AST = (AST)currentAST.root;
1179            break;
1180        }
1181        default:
1182        {
1183            throw new NoViableAltException(LT(1), getFilename());
1184        }
1185        }
1186        returnAST = list_AST;
1187    }
1188    
1189    public final void literalModifier() throws RecognitionException, TokenStreamException {
1190        
1191        returnAST = null;
1192        ASTPair currentAST = new ASTPair();
1193        AST literalModifier_AST = null;
1194        
1195        literalModifier1();
1196        astFactory.addASTChild(currentAST, returnAST);
1197        literalModifier1();
1198        astFactory.addASTChild(currentAST, returnAST);
1199        literalModifier_AST = (AST)currentAST.root;
1200        returnAST = literalModifier_AST;
1201    }
1202    
1203    public final void literalModifier1() throws RecognitionException, TokenStreamException {
1204        
1205        returnAST = null;
1206        ASTPair currentAST = new ASTPair();
1207        AST literalModifier1_AST = null;
1208        AST dt_AST = null;
1209        
1210        boolean synPredMatched37 = false;
1211        if (((LA(1)==AT_LANG))) {
1212            int _m37 = mark();
1213            synPredMatched37 = true;
1214            inputState.guessing++;
1215            try {
1216                {
1217                match(AT_LANG);
1218                }
1219            }
1220            catch (RecognitionException pe) {
1221                synPredMatched37 = false;
1222            }
1223            rewind(_m37);
1224            inputState.guessing--;
1225        }
1226        if ( synPredMatched37 ) {
1227            AST tmp30_AST = null;
1228            tmp30_AST = astFactory.create(LT(1));
1229            astFactory.addASTChild(currentAST, tmp30_AST);
1230            match(AT_LANG);
1231            literalModifier1_AST = (AST)currentAST.root;
1232        }
1233        else {
1234            boolean synPredMatched39 = false;
1235            if (((LA(1)==DATATYPE))) {
1236                int _m39 = mark();
1237                synPredMatched39 = true;
1238                inputState.guessing++;
1239                try {
1240                    {
1241                    match(DATATYPE);
1242                    }
1243                }
1244                catch (RecognitionException pe) {
1245                    synPredMatched39 = false;
1246                }
1247                rewind(_m39);
1248                inputState.guessing--;
1249            }
1250            if ( synPredMatched39 ) {
1251                AST tmp31_AST = null;
1252                tmp31_AST = astFactory.create(LT(1));
1253                astFactory.addASTChild(currentAST, tmp31_AST);
1254                match(DATATYPE);
1255                datatype();
1256                dt_AST = (AST)returnAST;
1257                astFactory.addASTChild(currentAST, returnAST);
1258                if ( inputState.guessing==0 ) {
1259                    literalModifier1_AST = (AST)currentAST.root;
1260                    literalModifier1_AST = (AST)astFactory.make( (new ASTArray(2)).add(astFactory.create(tmp31_AST)).add(dt_AST)) ;
1261                    currentAST.root = literalModifier1_AST;
1262                    currentAST.child = literalModifier1_AST!=null &&literalModifier1_AST.getFirstChild()!=null ?
1263                        literalModifier1_AST.getFirstChild() : literalModifier1_AST;
1264                    currentAST.advanceChildToEnd();
1265                }
1266                literalModifier1_AST = (AST)currentAST.root;
1267            }
1268            else if ((_tokenSet_0.member(LA(1)))) {
1269                literalModifier1_AST = (AST)currentAST.root;
1270            }
1271            else {
1272                throw new NoViableAltException(LT(1), getFilename());
1273            }
1274            }
1275            returnAST = literalModifier1_AST;
1276        }
1277        
1278    public final void datatype() throws RecognitionException, TokenStreamException {
1279        
1280        returnAST = null;
1281        ASTPair currentAST = new ASTPair();
1282        AST datatype_AST = null;
1283        
1284        switch ( LA(1)) {
1285        case QNAME:
1286        {
1287            qname();
1288            astFactory.addASTChild(currentAST, returnAST);
1289            datatype_AST = (AST)currentAST.root;
1290            break;
1291        }
1292        case URIREF:
1293        {
1294            uriref();
1295            astFactory.addASTChild(currentAST, returnAST);
1296            datatype_AST = (AST)currentAST.root;
1297            break;
1298        }
1299        case UVAR:
1300        {
1301            variableNoDT();
1302            astFactory.addASTChild(currentAST, returnAST);
1303            datatype_AST = (AST)currentAST.root;
1304            break;
1305        }
1306        case STRING:
1307        case NUMBER:
1308        {
1309            literal();
1310            astFactory.addASTChild(currentAST, returnAST);
1311            datatype_AST = (AST)currentAST.root;
1312            break;
1313        }
1314        default:
1315        {
1316            throw new NoViableAltException(LT(1), getFilename());
1317        }
1318        }
1319        returnAST = datatype_AST;
1320    }
1321    
1322    public final void variableNoDT() throws RecognitionException, TokenStreamException {
1323        
1324        returnAST = null;
1325        ASTPair currentAST = new ASTPair();
1326        AST variableNoDT_AST = null;
1327        Token v = null;
1328        AST v_AST = null;
1329        
1330        v = LT(1);
1331        v_AST = astFactory.create(v);
1332        astFactory.addASTChild(currentAST, v_AST);
1333        match(UVAR);
1334        variableNoDT_AST = (AST)currentAST.root;
1335        returnAST = variableNoDT_AST;
1336    }
1337    
1338    
1339    public static final String JavaDoc[] _tokenNames = {
1340        "<0>",
1341        "EOF",
1342        "<2>",
1343        "NULL_TREE_LOOKAHEAD",
1344        "ANON",
1345        "FORMULA",
1346        "QNAME",
1347        "SEP",
1348        "KEYWORD",
1349        "NAME_OP",
1350        "KW_THIS",
1351        "KW_OF",
1352        "KW_HAS",
1353        "KW_A",
1354        "KW_IS",
1355        "TK_LIST",
1356        "TK_LIST_FIRST",
1357        "TK_LIST_REST",
1358        "TK_LIST_NIL",
1359        "AT_PREFIX",
1360        "AT_LANG",
1361        "STRING",
1362        "LITERAL",
1363        "SEMI",
1364        "COMMA",
1365        "PATH",
1366        "RPATH",
1367        "EQUAL",
1368        "ARROW_R",
1369        "ARROW_L",
1370        "ARROW_PATH_L",
1371        "ARROW_PATH_R",
1372        "LBRACK",
1373        "RBRACK",
1374        "LCURLY",
1375        "RCURLY",
1376        "LPAREN",
1377        "RPAREN",
1378        "NUMBER",
1379        "DATATYPE",
1380        "URIREF",
1381        "UVAR",
1382        "THING",
1383        "URI_OR_IMPLIES",
1384        "URICHAR",
1385        "AT_WORD",
1386        "XNAMECHAR",
1387        "XNAME",
1388        "NSNAME",
1389        "LNAME",
1390        "SEP_OR_PATH",
1391        "DOT",
1392        "AT",
1393        "LANGLE",
1394        "RANGLE",
1395        "NAME_IT",
1396        "QUESTION",
1397        "ARROW_MEANS",
1398        "COLON",
1399        "SL_COMMENT",
1400        "NL1",
1401        "NL2",
1402        "NL3",
1403        "NL",
1404        "WS",
1405        "NWS",
1406        "ALPHA",
1407        "NUMERIC",
1408        "ALPHANUMERIC",
1409        "NON_ANC",
1410        "STRING1",
1411        "STRING2",
1412        "QUOTE3S",
1413        "QUOTE3D",
1414        "ESCAPE",
1415        "ESC_CHAR",
1416        "HEX_DIGIT",
1417        "HEX4"
1418    };
1419    
1420    protected void buildTokenTypeASTClassMap() {
1421        tokenTypeToASTClassMap=null;
1422    };
1423    
1424    private static final long[] mk_tokenSet_0() {
1425        long[] data = { 4398041300674L, 0L};
1426        return data;
1427    }
1428    public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
1429    
1430    }
1431
Popular Tags