0001: // $ANTLR 2.7.2: "src/com/hp/hpl/jena/n3/n3.g" -> "N3AntlrParser.java"$
0002:
0003: package com.hp.hpl.jena.n3;
0004:
0005: import antlr.TokenStreamRecognitionException;
0006:
0007: import antlr.TokenBuffer;
0008: import antlr.TokenStreamException;
0009: import antlr.Token;
0010: import antlr.TokenStream;
0011: import antlr.RecognitionException;
0012: import antlr.NoViableAltException;
0013: import antlr.SemanticException;
0014: import antlr.ParserSharedInputState;
0015: import antlr.collections.impl.BitSet;
0016: import antlr.collections.AST;
0017: import antlr.ASTFactory;
0018: import antlr.ASTPair;
0019: import antlr.collections.impl.ASTArray;
0020:
0021: public class N3AntlrParser extends antlr.LLkParser implements
0022: N3AntlrParserTokenTypes {
0023:
0024: // Extra code for the parser.
0025:
0026: boolean emitListTypeQuad = false;
0027:
0028: N3AntlrLexer lexer = null;
0029:
0030: void setLexer(N3AntlrLexer _lexer) {
0031: lexer = _lexer;
0032: }
0033:
0034: // Internallly generated anon id. Avoid clash with _:xxx
0035: private int anonId = 0;
0036:
0037: private String genAnonId() {
0038: return "=:" + (anonId++);
0039: }
0040:
0041: // Forumla zero is the outer context. Avoid clash with other labels.
0042: private int formulaId = 1;
0043:
0044: private String genFormulaId() {
0045: return "{}:" + (formulaId++);
0046: }
0047:
0048: private N3ParserEventHandler handler = null;
0049:
0050: public void setEventHandler(N3ParserEventHandler h) {
0051: this .handler = h;
0052: }
0053:
0054: private void startDocument() {
0055: if (handler == null)
0056: throw new RuntimeException(
0057: "N3AntlrParser: No sink specified");
0058: handler.startDocument();
0059: }
0060:
0061: private void endDocument() {
0062: handler.endDocument();
0063: }
0064:
0065: private void startFormula(String context) {
0066: handler.startFormula(lexer.getLine(), context);
0067: }
0068:
0069: private void endFormula(String context) {
0070: handler.endFormula(lexer.getLine(), context);
0071: }
0072:
0073: private String currentFormula = null;
0074:
0075: private void emitQuad(AST subj, AST prop, AST obj) {
0076: handler.quad(lexer.getLine(), subj, prop, obj, currentFormula);
0077: }
0078:
0079: private void directive(AST directive, AST arg) {
0080: handler.directive(lexer.getLine(), directive,
0081: new AST[] { arg }, currentFormula);
0082: }
0083:
0084: private void directive(AST directive, AST arg1, AST arg2) {
0085: handler.directive(lexer.getLine(), directive, new AST[] { arg1,
0086: arg2 }, currentFormula);
0087: }
0088:
0089: public void reportError(RecognitionException ex) {
0090: handler.error(ex, "N3 error: [" + ex.line + ":" + ex.column
0091: + "] " + ex.getMessage());
0092: }
0093:
0094: /** Parser error-reporting function can be overridden in subclass */
0095: public void reportError(String s) {
0096: //System.err.println("N3AntlrParser(s): "+s);
0097: handler.error(null, "N3AntlrParser(s): [" + lexer.getLine()
0098: + ":" + lexer.getColumn() + "] " + s);
0099: }
0100:
0101: protected N3AntlrParser(TokenBuffer tokenBuf, int k) {
0102: super (tokenBuf, k);
0103: tokenNames = _tokenNames;
0104: buildTokenTypeASTClassMap();
0105: astFactory = new ASTFactory(getTokenTypeToASTClassMap());
0106: }
0107:
0108: public N3AntlrParser(TokenBuffer tokenBuf) {
0109: this (tokenBuf, 1);
0110: }
0111:
0112: protected N3AntlrParser(TokenStream lexer, int k) {
0113: super (lexer, k);
0114: tokenNames = _tokenNames;
0115: buildTokenTypeASTClassMap();
0116: astFactory = new ASTFactory(getTokenTypeToASTClassMap());
0117: }
0118:
0119: public N3AntlrParser(TokenStream lexer) {
0120: this (lexer, 1);
0121: }
0122:
0123: public N3AntlrParser(ParserSharedInputState state) {
0124: super (state, 1);
0125: tokenNames = _tokenNames;
0126: buildTokenTypeASTClassMap();
0127: astFactory = new ASTFactory(getTokenTypeToASTClassMap());
0128: }
0129:
0130: public final void document() throws RecognitionException,
0131: TokenStreamException {
0132:
0133: returnAST = null;
0134: ASTPair currentAST = new ASTPair();
0135: AST document_AST = null;
0136:
0137: try { // for error handling
0138: if (inputState.guessing == 0) {
0139: startDocument();
0140: }
0141: {
0142: _loop3: do {
0143: switch (LA(1)) {
0144: case AT_PREFIX: {
0145: n3Directive();
0146: break;
0147: }
0148: case QNAME:
0149: case KW_THIS:
0150: case STRING:
0151: case LBRACK:
0152: case LCURLY:
0153: case LPAREN:
0154: case NUMBER:
0155: case URIREF:
0156: case UVAR: {
0157: statement();
0158: break;
0159: }
0160: default: {
0161: break _loop3;
0162: }
0163: }
0164: } while (true);
0165: }
0166: if (inputState.guessing == 0) {
0167: endDocument();
0168: }
0169: AST tmp1_AST = null;
0170: tmp1_AST = astFactory.create(LT(1));
0171: match(Token.EOF_TYPE);
0172: } catch (RecognitionException ex) {
0173: if (inputState.guessing == 0) {
0174: reportError(ex);
0175: throw ex;
0176: } else {
0177: throw ex;
0178: }
0179: } catch (TokenStreamRecognitionException ex) {
0180: if (inputState.guessing == 0) {
0181: reportError(ex.recog);
0182: throw ex.recog;
0183: } else {
0184: throw ex;
0185: }
0186: }
0187: returnAST = document_AST;
0188: }
0189:
0190: public final void n3Directive() throws RecognitionException,
0191: TokenStreamException {
0192:
0193: returnAST = null;
0194: ASTPair currentAST = new ASTPair();
0195: AST n3Directive_AST = null;
0196:
0197: n3Directive0();
0198: match(SEP);
0199: returnAST = n3Directive_AST;
0200: }
0201:
0202: public final void statement() throws RecognitionException,
0203: TokenStreamException {
0204:
0205: returnAST = null;
0206: ASTPair currentAST = new ASTPair();
0207: AST statement_AST = null;
0208:
0209: statement0();
0210: match(SEP);
0211: returnAST = statement_AST;
0212: }
0213:
0214: public final void n3Directive0() throws RecognitionException,
0215: TokenStreamException {
0216:
0217: returnAST = null;
0218: ASTPair currentAST = new ASTPair();
0219: AST n3Directive0_AST = null;
0220: Token d = null;
0221: AST d_AST = null;
0222: AST ns_AST = null;
0223: AST u_AST = null;
0224:
0225: d = LT(1);
0226: d_AST = astFactory.create(d);
0227: match(AT_PREFIX);
0228: nsprefix();
0229: ns_AST = (AST) returnAST;
0230: uriref();
0231: u_AST = (AST) returnAST;
0232: if (inputState.guessing == 0) {
0233: directive(d_AST, ns_AST, u_AST);
0234: }
0235: returnAST = n3Directive0_AST;
0236: }
0237:
0238: public final void nsprefix() throws RecognitionException,
0239: TokenStreamException {
0240:
0241: returnAST = null;
0242: ASTPair currentAST = new ASTPair();
0243: AST nsprefix_AST = null;
0244: Token ns = null;
0245: AST ns_AST = null;
0246:
0247: try { // for error handling
0248: ns = LT(1);
0249: ns_AST = astFactory.create(ns);
0250: astFactory.addASTChild(currentAST, ns_AST);
0251: match(QNAME);
0252: if (!(ns.getText().endsWith(":")))
0253: throw new SemanticException(
0254: " ns.getText().endsWith(\":\") ");
0255: nsprefix_AST = (AST) currentAST.root;
0256: } catch (SemanticException ex) {
0257: if (inputState.guessing == 0) {
0258:
0259: RecognitionException rEx = new RecognitionException(
0260: "Illegal prefix: '" + ns.getText() + "'");
0261: rEx.line = lexer.getLine();
0262: rEx.column = lexer.getColumn();
0263: throw rEx;
0264:
0265: } else {
0266: throw ex;
0267: }
0268: }
0269: returnAST = nsprefix_AST;
0270: }
0271:
0272: public final void uriref() throws RecognitionException,
0273: TokenStreamException {
0274:
0275: returnAST = null;
0276: ASTPair currentAST = new ASTPair();
0277: AST uriref_AST = null;
0278:
0279: AST tmp4_AST = null;
0280: tmp4_AST = astFactory.create(LT(1));
0281: astFactory.addASTChild(currentAST, tmp4_AST);
0282: match(URIREF);
0283: uriref_AST = (AST) currentAST.root;
0284: returnAST = uriref_AST;
0285: }
0286:
0287: public final void statement0() throws RecognitionException,
0288: TokenStreamException {
0289:
0290: returnAST = null;
0291: ASTPair currentAST = new ASTPair();
0292: AST statement0_AST = null;
0293: AST subj_AST = null;
0294:
0295: subject();
0296: subj_AST = (AST) returnAST;
0297: propertyList(subj_AST);
0298: returnAST = statement0_AST;
0299: }
0300:
0301: public final void subject() throws RecognitionException,
0302: TokenStreamException {
0303:
0304: returnAST = null;
0305: ASTPair currentAST = new ASTPair();
0306: AST subject_AST = null;
0307:
0308: item();
0309: astFactory.addASTChild(currentAST, returnAST);
0310: subject_AST = (AST) currentAST.root;
0311: returnAST = subject_AST;
0312: }
0313:
0314: public final void propertyList(AST subj)
0315: throws RecognitionException, TokenStreamException {
0316:
0317: returnAST = null;
0318: ASTPair currentAST = new ASTPair();
0319: AST propertyList_AST = null;
0320:
0321: switch (LA(1)) {
0322: case NAME_OP: {
0323: match(NAME_OP);
0324: anonnode(subj);
0325: propertyList(subj);
0326: break;
0327: }
0328: case QNAME:
0329: case KW_THIS:
0330: case KW_HAS:
0331: case KW_A:
0332: case KW_IS:
0333: case STRING:
0334: case EQUAL:
0335: case ARROW_R:
0336: case ARROW_L:
0337: case ARROW_PATH_L:
0338: case LBRACK:
0339: case LCURLY:
0340: case LPAREN:
0341: case NUMBER:
0342: case URIREF:
0343: case UVAR: {
0344: propValue(subj);
0345: {
0346: switch (LA(1)) {
0347: case SEMI: {
0348: AST tmp6_AST = null;
0349: tmp6_AST = astFactory.create(LT(1));
0350: match(SEMI);
0351: propertyList(subj);
0352: break;
0353: }
0354: case SEP:
0355: case RBRACK:
0356: case RCURLY: {
0357: break;
0358: }
0359: default: {
0360: throw new NoViableAltException(LT(1), getFilename());
0361: }
0362: }
0363: }
0364: break;
0365: }
0366: case SEP:
0367: case RBRACK:
0368: case RCURLY: {
0369: break;
0370: }
0371: default: {
0372: throw new NoViableAltException(LT(1), getFilename());
0373: }
0374: }
0375: returnAST = propertyList_AST;
0376: }
0377:
0378: public final void formulaList() throws RecognitionException,
0379: TokenStreamException {
0380:
0381: returnAST = null;
0382: ASTPair currentAST = new ASTPair();
0383: AST formulaList_AST = null;
0384:
0385: switch (LA(1)) {
0386: case QNAME:
0387: case KW_THIS:
0388: case AT_PREFIX:
0389: case STRING:
0390: case LBRACK:
0391: case LCURLY:
0392: case LPAREN:
0393: case NUMBER:
0394: case URIREF:
0395: case UVAR: {
0396: {
0397: switch (LA(1)) {
0398: case QNAME:
0399: case KW_THIS:
0400: case STRING:
0401: case LBRACK:
0402: case LCURLY:
0403: case LPAREN:
0404: case NUMBER:
0405: case URIREF:
0406: case UVAR: {
0407: statement0();
0408: break;
0409: }
0410: case AT_PREFIX: {
0411: n3Directive0();
0412: break;
0413: }
0414: default: {
0415: throw new NoViableAltException(LT(1), getFilename());
0416: }
0417: }
0418: }
0419: {
0420: switch (LA(1)) {
0421: case SEP: {
0422: AST tmp7_AST = null;
0423: tmp7_AST = astFactory.create(LT(1));
0424: match(SEP);
0425: formulaList();
0426: break;
0427: }
0428: case RCURLY: {
0429: break;
0430: }
0431: default: {
0432: throw new NoViableAltException(LT(1), getFilename());
0433: }
0434: }
0435: }
0436: break;
0437: }
0438: case RCURLY: {
0439: break;
0440: }
0441: default: {
0442: throw new NoViableAltException(LT(1), getFilename());
0443: }
0444: }
0445: returnAST = formulaList_AST;
0446: }
0447:
0448: public final void item() throws RecognitionException,
0449: TokenStreamException {
0450:
0451: returnAST = null;
0452: ASTPair currentAST = new ASTPair();
0453: AST item_AST = null;
0454: AST n_AST = null;
0455: AST n1_AST = null;
0456: AST n2_AST = null;
0457:
0458: node();
0459: n_AST = (AST) returnAST;
0460: astFactory.addASTChild(currentAST, returnAST);
0461: {
0462: _loop21: do {
0463: switch (LA(1)) {
0464: case PATH: {
0465: match(PATH);
0466: node();
0467: n1_AST = (AST) returnAST;
0468: astFactory.addASTChild(currentAST, returnAST);
0469: if (inputState.guessing == 0) {
0470:
0471: AST a1 = (AST) astFactory
0472: .make((new ASTArray(1)).add(astFactory
0473: .create(ANON, genAnonId())));
0474: emitQuad(n_AST, n1_AST, a1);
0475: n_AST = a1;
0476:
0477: }
0478: break;
0479: }
0480: case RPATH: {
0481: match(RPATH);
0482: node();
0483: n2_AST = (AST) returnAST;
0484: astFactory.addASTChild(currentAST, returnAST);
0485: if (inputState.guessing == 0) {
0486:
0487: AST a2 = (AST) astFactory
0488: .make((new ASTArray(1)).add(astFactory
0489: .create(ANON, genAnonId())));
0490: emitQuad(a2, n2_AST, n_AST);
0491: n_AST = a2;
0492:
0493: }
0494: break;
0495: }
0496: default: {
0497: break _loop21;
0498: }
0499: }
0500: } while (true);
0501: }
0502: if (inputState.guessing == 0) {
0503: item_AST = (AST) currentAST.root;
0504: item_AST = n_AST;
0505: currentAST.root = item_AST;
0506: currentAST.child = item_AST != null
0507: && item_AST.getFirstChild() != null ? item_AST
0508: .getFirstChild() : item_AST;
0509: currentAST.advanceChildToEnd();
0510: }
0511: item_AST = (AST) currentAST.root;
0512: returnAST = item_AST;
0513: }
0514:
0515: public final void anonnode(AST label) throws RecognitionException,
0516: TokenStreamException {
0517:
0518: returnAST = null;
0519: ASTPair currentAST = new ASTPair();
0520: AST anonnode_AST = null;
0521: String oldCxt = null;
0522: String cxt = null;
0523:
0524: switch (LA(1)) {
0525: case LBRACK: {
0526: match(LBRACK);
0527: if (inputState.guessing == 0) {
0528: anonnode_AST = (AST) currentAST.root;
0529: if (label == null)
0530: label = (AST) astFactory.make((new ASTArray(1))
0531: .add(astFactory.create(ANON, genAnonId())));
0532: anonnode_AST = label;
0533:
0534: currentAST.root = anonnode_AST;
0535: currentAST.child = anonnode_AST != null
0536: && anonnode_AST.getFirstChild() != null ? anonnode_AST
0537: .getFirstChild()
0538: : anonnode_AST;
0539: currentAST.advanceChildToEnd();
0540: }
0541: propertyList(label);
0542: astFactory.addASTChild(currentAST, returnAST);
0543: match(RBRACK);
0544: anonnode_AST = (AST) currentAST.root;
0545: break;
0546: }
0547: case LCURLY: {
0548: match(LCURLY);
0549: if (inputState.guessing == 0) {
0550: anonnode_AST = (AST) currentAST.root;
0551: oldCxt = currentFormula;
0552: if (label == null)
0553: label = (AST) astFactory.make((new ASTArray(1))
0554: .add(astFactory.create(FORMULA,
0555: genFormulaId())));
0556: cxt = label.getText();
0557: currentFormula = cxt;
0558: startFormula(cxt);
0559: anonnode_AST = label;
0560:
0561: currentAST.root = anonnode_AST;
0562: currentAST.child = anonnode_AST != null
0563: && anonnode_AST.getFirstChild() != null ? anonnode_AST
0564: .getFirstChild()
0565: : anonnode_AST;
0566: currentAST.advanceChildToEnd();
0567: }
0568: formulaList();
0569: astFactory.addASTChild(currentAST, returnAST);
0570: if (inputState.guessing == 0) {
0571: endFormula(cxt);
0572: currentFormula = oldCxt;
0573: }
0574: match(RCURLY);
0575: anonnode_AST = (AST) currentAST.root;
0576: break;
0577: }
0578: case LPAREN: {
0579: match(LPAREN);
0580: list(label);
0581: astFactory.addASTChild(currentAST, returnAST);
0582: match(RPAREN);
0583: anonnode_AST = (AST) currentAST.root;
0584: break;
0585: }
0586: default: {
0587: throw new NoViableAltException(LT(1), getFilename());
0588: }
0589: }
0590: returnAST = anonnode_AST;
0591: }
0592:
0593: public final void propValue(AST subj) throws RecognitionException,
0594: TokenStreamException {
0595:
0596: returnAST = null;
0597: ASTPair currentAST = new ASTPair();
0598: AST propValue_AST = null;
0599: AST v1_AST = null;
0600: AST v2_AST = null;
0601:
0602: switch (LA(1)) {
0603: case QNAME:
0604: case KW_THIS:
0605: case KW_HAS:
0606: case KW_A:
0607: case STRING:
0608: case EQUAL:
0609: case ARROW_R:
0610: case ARROW_L:
0611: case ARROW_PATH_L:
0612: case LBRACK:
0613: case LCURLY:
0614: case LPAREN:
0615: case NUMBER:
0616: case URIREF:
0617: case UVAR: {
0618: verb();
0619: v1_AST = (AST) returnAST;
0620: astFactory.addASTChild(currentAST, returnAST);
0621: objectList(subj, v1_AST);
0622: astFactory.addASTChild(currentAST, returnAST);
0623: propValue_AST = (AST) currentAST.root;
0624: break;
0625: }
0626: case KW_IS: {
0627: verbReverse();
0628: v2_AST = (AST) returnAST;
0629: astFactory.addASTChild(currentAST, returnAST);
0630: subjectList(subj, v2_AST);
0631: astFactory.addASTChild(currentAST, returnAST);
0632: propValue_AST = (AST) currentAST.root;
0633: break;
0634: }
0635: default: {
0636: throw new NoViableAltException(LT(1), getFilename());
0637: }
0638: }
0639: returnAST = propValue_AST;
0640: }
0641:
0642: public final void verb() throws RecognitionException,
0643: TokenStreamException {
0644:
0645: returnAST = null;
0646: ASTPair currentAST = new ASTPair();
0647: AST verb_AST = null;
0648:
0649: switch (LA(1)) {
0650: case QNAME:
0651: case KW_THIS:
0652: case STRING:
0653: case LBRACK:
0654: case LCURLY:
0655: case LPAREN:
0656: case NUMBER:
0657: case URIREF:
0658: case UVAR: {
0659: item();
0660: astFactory.addASTChild(currentAST, returnAST);
0661: verb_AST = (AST) currentAST.root;
0662: break;
0663: }
0664: case KW_A: {
0665: kwA();
0666: astFactory.addASTChild(currentAST, returnAST);
0667: verb_AST = (AST) currentAST.root;
0668: break;
0669: }
0670: case EQUAL: {
0671: AST tmp16_AST = null;
0672: tmp16_AST = astFactory.create(LT(1));
0673: astFactory.addASTChild(currentAST, tmp16_AST);
0674: match(EQUAL);
0675: verb_AST = (AST) currentAST.root;
0676: break;
0677: }
0678: case ARROW_R: {
0679: AST tmp17_AST = null;
0680: tmp17_AST = astFactory.create(LT(1));
0681: astFactory.addASTChild(currentAST, tmp17_AST);
0682: match(ARROW_R);
0683: verb_AST = (AST) currentAST.root;
0684: break;
0685: }
0686: case ARROW_L: {
0687: AST tmp18_AST = null;
0688: tmp18_AST = astFactory.create(LT(1));
0689: astFactory.addASTChild(currentAST, tmp18_AST);
0690: match(ARROW_L);
0691: verb_AST = (AST) currentAST.root;
0692: break;
0693: }
0694: case ARROW_PATH_L: {
0695: match(ARROW_PATH_L);
0696: node();
0697: astFactory.addASTChild(currentAST, returnAST);
0698: match(ARROW_PATH_R);
0699: verb_AST = (AST) currentAST.root;
0700: break;
0701: }
0702: case KW_HAS: {
0703: kwHAS();
0704: item();
0705: astFactory.addASTChild(currentAST, returnAST);
0706: verb_AST = (AST) currentAST.root;
0707: break;
0708: }
0709: default: {
0710: throw new NoViableAltException(LT(1), getFilename());
0711: }
0712: }
0713: returnAST = verb_AST;
0714: }
0715:
0716: public final void objectList(AST subj, AST prop)
0717: throws RecognitionException, TokenStreamException {
0718:
0719: returnAST = null;
0720: ASTPair currentAST = new ASTPair();
0721: AST objectList_AST = null;
0722: AST obj_AST = null;
0723:
0724: switch (LA(1)) {
0725: case QNAME:
0726: case KW_THIS:
0727: case STRING:
0728: case LBRACK:
0729: case LCURLY:
0730: case LPAREN:
0731: case NUMBER:
0732: case URIREF:
0733: case UVAR: {
0734: item();
0735: obj_AST = (AST) returnAST;
0736: if (inputState.guessing == 0) {
0737: emitQuad(subj, prop, obj_AST);
0738: }
0739: {
0740: switch (LA(1)) {
0741: case COMMA: {
0742: AST tmp21_AST = null;
0743: tmp21_AST = astFactory.create(LT(1));
0744: match(COMMA);
0745: objectList(subj, prop);
0746: break;
0747: }
0748: case SEP:
0749: case SEMI:
0750: case RBRACK:
0751: case RCURLY: {
0752: break;
0753: }
0754: default: {
0755: throw new NoViableAltException(LT(1), getFilename());
0756: }
0757: }
0758: }
0759: break;
0760: }
0761: case SEP:
0762: case SEMI:
0763: case RBRACK:
0764: case RCURLY: {
0765: break;
0766: }
0767: default: {
0768: throw new NoViableAltException(LT(1), getFilename());
0769: }
0770: }
0771: returnAST = objectList_AST;
0772: }
0773:
0774: public final void verbReverse() throws RecognitionException,
0775: TokenStreamException {
0776:
0777: returnAST = null;
0778: ASTPair currentAST = new ASTPair();
0779: AST verbReverse_AST = null;
0780: AST n_AST = null;
0781:
0782: kwIS();
0783: node();
0784: n_AST = (AST) returnAST;
0785: astFactory.addASTChild(currentAST, returnAST);
0786: kwOF();
0787: verbReverse_AST = (AST) currentAST.root;
0788: returnAST = verbReverse_AST;
0789: }
0790:
0791: public final void subjectList(AST oldSub, AST prop)
0792: throws RecognitionException, TokenStreamException {
0793:
0794: returnAST = null;
0795: ASTPair currentAST = new ASTPair();
0796: AST subjectList_AST = null;
0797: AST obj_AST = null;
0798:
0799: item();
0800: obj_AST = (AST) returnAST;
0801: if (inputState.guessing == 0) {
0802: emitQuad(obj_AST, prop, oldSub);
0803: }
0804: {
0805: switch (LA(1)) {
0806: case COMMA: {
0807: AST tmp22_AST = null;
0808: tmp22_AST = astFactory.create(LT(1));
0809: match(COMMA);
0810: subjectList(oldSub, prop);
0811: break;
0812: }
0813: case SEP:
0814: case SEMI:
0815: case RBRACK:
0816: case RCURLY: {
0817: break;
0818: }
0819: default: {
0820: throw new NoViableAltException(LT(1), getFilename());
0821: }
0822: }
0823: }
0824: returnAST = subjectList_AST;
0825: }
0826:
0827: public final void node() throws RecognitionException,
0828: TokenStreamException {
0829:
0830: returnAST = null;
0831: ASTPair currentAST = new ASTPair();
0832: AST node_AST = null;
0833:
0834: switch (LA(1)) {
0835: case QNAME: {
0836: qname();
0837: astFactory.addASTChild(currentAST, returnAST);
0838: node_AST = (AST) currentAST.root;
0839: break;
0840: }
0841: case URIREF: {
0842: uriref();
0843: astFactory.addASTChild(currentAST, returnAST);
0844: node_AST = (AST) currentAST.root;
0845: break;
0846: }
0847: case LBRACK:
0848: case LCURLY:
0849: case LPAREN: {
0850: anonnode(null);
0851: astFactory.addASTChild(currentAST, returnAST);
0852: node_AST = (AST) currentAST.root;
0853: break;
0854: }
0855: case STRING:
0856: case NUMBER: {
0857: literal();
0858: astFactory.addASTChild(currentAST, returnAST);
0859: node_AST = (AST) currentAST.root;
0860: break;
0861: }
0862: case KW_THIS: {
0863: kwTHIS();
0864: astFactory.addASTChild(currentAST, returnAST);
0865: node_AST = (AST) currentAST.root;
0866: break;
0867: }
0868: case UVAR: {
0869: variableDT();
0870: astFactory.addASTChild(currentAST, returnAST);
0871: node_AST = (AST) currentAST.root;
0872: break;
0873: }
0874: default: {
0875: throw new NoViableAltException(LT(1), getFilename());
0876: }
0877: }
0878: returnAST = node_AST;
0879: }
0880:
0881: public final void testPoint() throws RecognitionException,
0882: TokenStreamException {
0883:
0884: returnAST = null;
0885: ASTPair currentAST = new ASTPair();
0886: AST testPoint_AST = null;
0887: AST v_AST = null;
0888:
0889: verb();
0890: v_AST = (AST) returnAST;
0891: if (inputState.guessing == 0) {
0892: AntlrUtils.ast(System.out, v_AST);
0893: }
0894: returnAST = testPoint_AST;
0895: }
0896:
0897: public final void qname() throws RecognitionException,
0898: TokenStreamException {
0899:
0900: returnAST = null;
0901: ASTPair currentAST = new ASTPair();
0902: AST qname_AST = null;
0903:
0904: AST tmp23_AST = null;
0905: tmp23_AST = astFactory.create(LT(1));
0906: astFactory.addASTChild(currentAST, tmp23_AST);
0907: match(QNAME);
0908: qname_AST = (AST) currentAST.root;
0909: returnAST = qname_AST;
0910: }
0911:
0912: public final void literal() throws RecognitionException,
0913: TokenStreamException {
0914:
0915: returnAST = null;
0916: ASTPair currentAST = new ASTPair();
0917: AST literal_AST = null;
0918: Token n = null;
0919: AST n_AST = null;
0920: Token s = null;
0921: AST s_AST = null;
0922:
0923: switch (LA(1)) {
0924: case NUMBER: {
0925: n = LT(1);
0926: n_AST = astFactory.create(n);
0927: astFactory.addASTChild(currentAST, n_AST);
0928: match(NUMBER);
0929: literal_AST = (AST) currentAST.root;
0930: break;
0931: }
0932: case STRING: {
0933: s = LT(1);
0934: s_AST = astFactory.create(s);
0935: astFactory.addASTChild(currentAST, s_AST);
0936: match(STRING);
0937: literalModifier();
0938: astFactory.addASTChild(currentAST, returnAST);
0939: if (inputState.guessing == 0) {
0940: literal_AST = (AST) currentAST.root;
0941: literal_AST.setType(LITERAL);
0942: }
0943: literal_AST = (AST) currentAST.root;
0944: break;
0945: }
0946: default: {
0947: throw new NoViableAltException(LT(1), getFilename());
0948: }
0949: }
0950: returnAST = literal_AST;
0951: }
0952:
0953: public final void kwTHIS() throws RecognitionException,
0954: TokenStreamException {
0955:
0956: returnAST = null;
0957: ASTPair currentAST = new ASTPair();
0958: AST kwTHIS_AST = null;
0959:
0960: AST tmp24_AST = null;
0961: tmp24_AST = astFactory.create(LT(1));
0962: astFactory.addASTChild(currentAST, tmp24_AST);
0963: match(KW_THIS);
0964: kwTHIS_AST = (AST) currentAST.root;
0965: returnAST = kwTHIS_AST;
0966: }
0967:
0968: public final void variableDT() throws RecognitionException,
0969: TokenStreamException {
0970:
0971: returnAST = null;
0972: ASTPair currentAST = new ASTPair();
0973: AST variableDT_AST = null;
0974: Token v = null;
0975: AST v_AST = null;
0976: AST dt_AST = null;
0977:
0978: v = LT(1);
0979: v_AST = astFactory.create(v);
0980: astFactory.addASTChild(currentAST, v_AST);
0981: match(UVAR);
0982: {
0983: switch (LA(1)) {
0984: case DATATYPE: {
0985: AST tmp25_AST = null;
0986: tmp25_AST = astFactory.create(LT(1));
0987: astFactory.addASTChild(currentAST, tmp25_AST);
0988: match(DATATYPE);
0989: datatype();
0990: dt_AST = (AST) returnAST;
0991: astFactory.addASTChild(currentAST, returnAST);
0992: break;
0993: }
0994: case EOF:
0995: case QNAME:
0996: case SEP:
0997: case NAME_OP:
0998: case KW_THIS:
0999: case KW_OF:
1000: case KW_HAS:
1001: case KW_A:
1002: case KW_IS:
1003: case STRING:
1004: case SEMI:
1005: case COMMA:
1006: case PATH:
1007: case RPATH:
1008: case EQUAL:
1009: case ARROW_R:
1010: case ARROW_L:
1011: case ARROW_PATH_L:
1012: case ARROW_PATH_R:
1013: case LBRACK:
1014: case RBRACK:
1015: case LCURLY:
1016: case RCURLY:
1017: case LPAREN:
1018: case RPAREN:
1019: case NUMBER:
1020: case URIREF:
1021: case UVAR: {
1022: break;
1023: }
1024: default: {
1025: throw new NoViableAltException(LT(1), getFilename());
1026: }
1027: }
1028: }
1029: if (inputState.guessing == 0) {
1030: variableDT_AST = (AST) currentAST.root;
1031: variableDT_AST = (AST) astFactory.make((new ASTArray(2))
1032: .add(astFactory.create(UVAR, v.getText())).add(
1033: dt_AST));
1034: currentAST.root = variableDT_AST;
1035: currentAST.child = variableDT_AST != null
1036: && variableDT_AST.getFirstChild() != null ? variableDT_AST
1037: .getFirstChild()
1038: : variableDT_AST;
1039: currentAST.advanceChildToEnd();
1040: }
1041: variableDT_AST = (AST) currentAST.root;
1042: returnAST = variableDT_AST;
1043: }
1044:
1045: public final void kwOF() throws RecognitionException,
1046: TokenStreamException {
1047:
1048: returnAST = null;
1049: ASTPair currentAST = new ASTPair();
1050: AST kwOF_AST = null;
1051:
1052: AST tmp26_AST = null;
1053: tmp26_AST = astFactory.create(LT(1));
1054: match(KW_OF);
1055: returnAST = kwOF_AST;
1056: }
1057:
1058: public final void kwHAS() throws RecognitionException,
1059: TokenStreamException {
1060:
1061: returnAST = null;
1062: ASTPair currentAST = new ASTPair();
1063: AST kwHAS_AST = null;
1064:
1065: AST tmp27_AST = null;
1066: tmp27_AST = astFactory.create(LT(1));
1067: match(KW_HAS);
1068: returnAST = kwHAS_AST;
1069: }
1070:
1071: public final void kwA() throws RecognitionException,
1072: TokenStreamException {
1073:
1074: returnAST = null;
1075: ASTPair currentAST = new ASTPair();
1076: AST kwA_AST = null;
1077:
1078: AST tmp28_AST = null;
1079: tmp28_AST = astFactory.create(LT(1));
1080: astFactory.addASTChild(currentAST, tmp28_AST);
1081: match(KW_A);
1082: kwA_AST = (AST) currentAST.root;
1083: returnAST = kwA_AST;
1084: }
1085:
1086: public final void kwIS() throws RecognitionException,
1087: TokenStreamException {
1088:
1089: returnAST = null;
1090: ASTPair currentAST = new ASTPair();
1091: AST kwIS_AST = null;
1092:
1093: AST tmp29_AST = null;
1094: tmp29_AST = astFactory.create(LT(1));
1095: match(KW_IS);
1096: returnAST = kwIS_AST;
1097: }
1098:
1099: public final void list(AST label) throws RecognitionException,
1100: TokenStreamException {
1101:
1102: returnAST = null;
1103: ASTPair currentAST = new ASTPair();
1104: AST list_AST = null;
1105: AST i_AST = null;
1106: AST n_AST = null;
1107:
1108: switch (LA(1)) {
1109: case QNAME:
1110: case KW_THIS:
1111: case STRING:
1112: case LBRACK:
1113: case LCURLY:
1114: case LPAREN:
1115: case NUMBER:
1116: case URIREF:
1117: case UVAR: {
1118: item();
1119: i_AST = (AST) returnAST;
1120: astFactory.addASTChild(currentAST, returnAST);
1121: if (inputState.guessing == 0) {
1122: list_AST = (AST) currentAST.root;
1123:
1124: if (label == null)
1125: label = (AST) astFactory.make((new ASTArray(1))
1126: .add(astFactory.create(ANON, genAnonId())));
1127: list_AST = label;
1128:
1129: currentAST.root = list_AST;
1130: currentAST.child = list_AST != null
1131: && list_AST.getFirstChild() != null ? list_AST
1132: .getFirstChild() : list_AST;
1133: currentAST.advanceChildToEnd();
1134: }
1135: list(null);
1136: n_AST = (AST) returnAST;
1137: astFactory.addASTChild(currentAST, returnAST);
1138: if (inputState.guessing == 0) {
1139:
1140: if (emitListTypeQuad)
1141: emitQuad(label, (AST) astFactory
1142: .make((new ASTArray(1)).add(astFactory
1143: .create(KW_A, "list"))),
1144: (AST) astFactory.make((new ASTArray(1))
1145: .add(astFactory.create(TK_LIST,
1146: "List"))));
1147: emitQuad(label, (AST) astFactory
1148: .make((new ASTArray(1)).add(astFactory.create(
1149: TK_LIST_FIRST, "first"))), i_AST);
1150: emitQuad(label, (AST) astFactory.make((new ASTArray(1))
1151: .add(astFactory.create(TK_LIST_REST, "rest"))),
1152: n_AST);
1153:
1154: }
1155: list_AST = (AST) currentAST.root;
1156: break;
1157: }
1158: case RPAREN: {
1159: if (inputState.guessing == 0) {
1160: list_AST = (AST) currentAST.root;
1161: list_AST = (AST) astFactory.make((new ASTArray(1))
1162: .add(astFactory.create(TK_LIST_NIL, "nil")));
1163: currentAST.root = list_AST;
1164: currentAST.child = list_AST != null
1165: && list_AST.getFirstChild() != null ? list_AST
1166: .getFirstChild() : list_AST;
1167: currentAST.advanceChildToEnd();
1168: }
1169: list_AST = (AST) currentAST.root;
1170: break;
1171: }
1172: default: {
1173: throw new NoViableAltException(LT(1), getFilename());
1174: }
1175: }
1176: returnAST = list_AST;
1177: }
1178:
1179: public final void literalModifier() throws RecognitionException,
1180: TokenStreamException {
1181:
1182: returnAST = null;
1183: ASTPair currentAST = new ASTPair();
1184: AST literalModifier_AST = null;
1185:
1186: literalModifier1();
1187: astFactory.addASTChild(currentAST, returnAST);
1188: literalModifier1();
1189: astFactory.addASTChild(currentAST, returnAST);
1190: literalModifier_AST = (AST) currentAST.root;
1191: returnAST = literalModifier_AST;
1192: }
1193:
1194: public final void literalModifier1() throws RecognitionException,
1195: TokenStreamException {
1196:
1197: returnAST = null;
1198: ASTPair currentAST = new ASTPair();
1199: AST literalModifier1_AST = null;
1200: AST dt_AST = null;
1201:
1202: boolean synPredMatched37 = false;
1203: if (((LA(1) == AT_LANG))) {
1204: int _m37 = mark();
1205: synPredMatched37 = true;
1206: inputState.guessing++;
1207: try {
1208: {
1209: match(AT_LANG);
1210: }
1211: } catch (RecognitionException pe) {
1212: synPredMatched37 = false;
1213: }
1214: rewind(_m37);
1215: inputState.guessing--;
1216: }
1217: if (synPredMatched37) {
1218: AST tmp30_AST = null;
1219: tmp30_AST = astFactory.create(LT(1));
1220: astFactory.addASTChild(currentAST, tmp30_AST);
1221: match(AT_LANG);
1222: literalModifier1_AST = (AST) currentAST.root;
1223: } else {
1224: boolean synPredMatched39 = false;
1225: if (((LA(1) == DATATYPE))) {
1226: int _m39 = mark();
1227: synPredMatched39 = true;
1228: inputState.guessing++;
1229: try {
1230: {
1231: match(DATATYPE);
1232: }
1233: } catch (RecognitionException pe) {
1234: synPredMatched39 = false;
1235: }
1236: rewind(_m39);
1237: inputState.guessing--;
1238: }
1239: if (synPredMatched39) {
1240: AST tmp31_AST = null;
1241: tmp31_AST = astFactory.create(LT(1));
1242: astFactory.addASTChild(currentAST, tmp31_AST);
1243: match(DATATYPE);
1244: datatype();
1245: dt_AST = (AST) returnAST;
1246: astFactory.addASTChild(currentAST, returnAST);
1247: if (inputState.guessing == 0) {
1248: literalModifier1_AST = (AST) currentAST.root;
1249: literalModifier1_AST = (AST) astFactory
1250: .make((new ASTArray(2)).add(
1251: astFactory.create(tmp31_AST)).add(
1252: dt_AST));
1253: currentAST.root = literalModifier1_AST;
1254: currentAST.child = literalModifier1_AST != null
1255: && literalModifier1_AST.getFirstChild() != null ? literalModifier1_AST
1256: .getFirstChild()
1257: : literalModifier1_AST;
1258: currentAST.advanceChildToEnd();
1259: }
1260: literalModifier1_AST = (AST) currentAST.root;
1261: } else if ((_tokenSet_0.member(LA(1)))) {
1262: literalModifier1_AST = (AST) currentAST.root;
1263: } else {
1264: throw new NoViableAltException(LT(1), getFilename());
1265: }
1266: }
1267: returnAST = literalModifier1_AST;
1268: }
1269:
1270: public final void datatype() throws RecognitionException,
1271: TokenStreamException {
1272:
1273: returnAST = null;
1274: ASTPair currentAST = new ASTPair();
1275: AST datatype_AST = null;
1276:
1277: switch (LA(1)) {
1278: case QNAME: {
1279: qname();
1280: astFactory.addASTChild(currentAST, returnAST);
1281: datatype_AST = (AST) currentAST.root;
1282: break;
1283: }
1284: case URIREF: {
1285: uriref();
1286: astFactory.addASTChild(currentAST, returnAST);
1287: datatype_AST = (AST) currentAST.root;
1288: break;
1289: }
1290: case UVAR: {
1291: variableNoDT();
1292: astFactory.addASTChild(currentAST, returnAST);
1293: datatype_AST = (AST) currentAST.root;
1294: break;
1295: }
1296: case STRING:
1297: case NUMBER: {
1298: literal();
1299: astFactory.addASTChild(currentAST, returnAST);
1300: datatype_AST = (AST) currentAST.root;
1301: break;
1302: }
1303: default: {
1304: throw new NoViableAltException(LT(1), getFilename());
1305: }
1306: }
1307: returnAST = datatype_AST;
1308: }
1309:
1310: public final void variableNoDT() throws RecognitionException,
1311: TokenStreamException {
1312:
1313: returnAST = null;
1314: ASTPair currentAST = new ASTPair();
1315: AST variableNoDT_AST = null;
1316: Token v = null;
1317: AST v_AST = null;
1318:
1319: v = LT(1);
1320: v_AST = astFactory.create(v);
1321: astFactory.addASTChild(currentAST, v_AST);
1322: match(UVAR);
1323: variableNoDT_AST = (AST) currentAST.root;
1324: returnAST = variableNoDT_AST;
1325: }
1326:
1327: public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
1328: "NULL_TREE_LOOKAHEAD", "ANON", "FORMULA", "QNAME", "SEP",
1329: "KEYWORD", "NAME_OP", "KW_THIS", "KW_OF", "KW_HAS", "KW_A",
1330: "KW_IS", "TK_LIST", "TK_LIST_FIRST", "TK_LIST_REST",
1331: "TK_LIST_NIL", "AT_PREFIX", "AT_LANG", "STRING", "LITERAL",
1332: "SEMI", "COMMA", "PATH", "RPATH", "EQUAL", "ARROW_R",
1333: "ARROW_L", "ARROW_PATH_L", "ARROW_PATH_R", "LBRACK",
1334: "RBRACK", "LCURLY", "RCURLY", "LPAREN", "RPAREN", "NUMBER",
1335: "DATATYPE", "URIREF", "UVAR", "THING", "URI_OR_IMPLIES",
1336: "URICHAR", "AT_WORD", "XNAMECHAR", "XNAME", "NSNAME",
1337: "LNAME", "SEP_OR_PATH", "DOT", "AT", "LANGLE", "RANGLE",
1338: "NAME_IT", "QUESTION", "ARROW_MEANS", "COLON",
1339: "SL_COMMENT", "NL1", "NL2", "NL3", "NL", "WS", "NWS",
1340: "ALPHA", "NUMERIC", "ALPHANUMERIC", "NON_ANC", "STRING1",
1341: "STRING2", "QUOTE3S", "QUOTE3D", "ESCAPE", "ESC_CHAR",
1342: "HEX_DIGIT", "HEX4" };
1343:
1344: protected void buildTokenTypeASTClassMap() {
1345: tokenTypeToASTClassMap = null;
1346: };
1347:
1348: private static final long[] mk_tokenSet_0() {
1349: long[] data = { 4398041300674L, 0L };
1350: return data;
1351: }
1352:
1353: public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
1354:
1355: }
|