001: /* Generated By:JavaCC: Do not edit this line. SqlGrammar.java */
002: package org.apache.beehive.controls.system.jdbc.parser;
003:
004: import java.io.StringReader;
005:
006: public class SqlGrammar implements SqlGrammarConstants {
007: private StringBuilder buffer = new StringBuilder();
008:
009: public static void main(String[] args) throws Exception {
010: SqlGrammar parser = new SqlGrammar(new StringReader(args[0]));
011: SqlStatement statement = parser.parse();
012: System.out.println(statement.toString());
013: }
014:
015: //
016: // Parse methods
017: //
018:
019: //
020: // Main parse method
021: //
022: final public SqlStatement parse() throws ParseException {
023: SqlStatement statement = new SqlStatement();
024: SqlFragment frag;
025: Token t, sq;
026: label_1: while (true) {
027: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
028: case NON_EXPRESSION_TEXT:
029: case START_EXPRESSION:
030: case SQUOTE:
031: ;
032: break;
033: default:
034: jj_la1[0] = jj_gen;
035: break label_1;
036: }
037: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
038: case NON_EXPRESSION_TEXT:
039: t = jj_consume_token(NON_EXPRESSION_TEXT);
040: statement.addChild(new LiteralFragment(t.image));
041: break;
042: case SQUOTE:
043: sq = jj_consume_token(SQUOTE);
044: t = jj_consume_token(STRING_LITERAL);
045: statement.addChild(new LiteralFragment(sq.image
046: + t.image));
047: break;
048: case START_EXPRESSION:
049: frag = parseExpression();
050: statement.addChild(frag);
051: break;
052: default:
053: jj_la1[1] = jj_gen;
054: jj_consume_token(-1);
055: throw new ParseException();
056: }
057: }
058: jj_consume_token(0);
059: {
060: if (true)
061: return statement;
062: }
063: throw new Error("Missing return statement in function");
064: }
065:
066: //
067: // Parse an expression delimited by '{}'
068: //
069: final public SqlFragment parseExpression() throws ParseException {
070: Token t, tt = null;
071: SqlFragment frag = null;
072: jj_consume_token(START_EXPRESSION);
073: label_2: while (true) {
074: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
075: case WHITESPACE:
076: ;
077: break;
078: default:
079: jj_la1[2] = jj_gen;
080: break label_2;
081: }
082: jj_consume_token(WHITESPACE);
083: }
084: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
085: case SQL_ESCAPE:
086: case SQL_SUBST:
087: case SQL_FN:
088: frag = parseSqlEscape();
089: break;
090: case JDBC_CALL:
091: case JDBC_RET:
092: case JDBC_DATE:
093: case JDBC_TIME:
094: case JDBC_TIMESTAMP:
095: case JDBC_FUNCTION:
096: case JDBC_ESCAPE:
097: case JDBC_OUTERJOIN:
098: frag = parseJdbcEscape();
099: break;
100: case IDENTIFIER:
101: t = jj_consume_token(IDENTIFIER);
102: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
103: case REFLECT_SEP:
104: jj_consume_token(REFLECT_SEP);
105: tt = jj_consume_token(IDENTIFIER);
106: break;
107: default:
108: jj_la1[3] = jj_gen;
109: ;
110: }
111: jj_consume_token(END_EXPRESSION);
112: frag = new ReflectionFragment(t.image, (tt == null) ? null
113: : tt.image);
114: break;
115: default:
116: jj_la1[4] = jj_gen;
117: jj_consume_token(-1);
118: throw new ParseException();
119: }
120: label_3: while (true) {
121: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
122: case WHITESPACE:
123: ;
124: break;
125: default:
126: jj_la1[5] = jj_gen;
127: break label_3;
128: }
129: jj_consume_token(WHITESPACE);
130: }
131: {
132: if (true)
133: return frag;
134: }
135: throw new Error("Missing return statement in function");
136: }
137:
138: //
139: // parse an sql: escape sequence
140: //
141: final public SqlSubstitutionFragment parseSqlEscape()
142: throws ParseException {
143: Token id1, id2;
144: Token t = null;
145: SqlSubstitutionFragment frag;
146: String func = null;
147: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
148: case SQL_ESCAPE:
149: case SQL_SUBST:
150: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
151: case SQL_ESCAPE:
152: jj_consume_token(SQL_ESCAPE);
153: break;
154: case SQL_SUBST:
155: jj_consume_token(SQL_SUBST);
156: break;
157: default:
158: jj_la1[6] = jj_gen;
159: jj_consume_token(-1);
160: throw new ParseException();
161: }
162: t = jj_consume_token(IDENTIFIER);
163: if (t != null) {
164: frag = new SqlSubstitutionFragment(
165: new ReflectionFragment(t.image));
166: } else {
167: frag = new SqlSubstitutionFragment(new LiteralFragment(
168: func));
169: }
170: break;
171: case SQL_FN:
172: jj_consume_token(SQL_FN);
173: label_4: while (true) {
174: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
175: case SQL_FN_WHITESPACE:
176: ;
177: break;
178: default:
179: jj_la1[7] = jj_gen;
180: break label_4;
181: }
182: jj_consume_token(SQL_FN_WHITESPACE);
183: }
184: jj_consume_token(SQL_FN_NM);
185: label_5: while (true) {
186: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
187: case SQL_FN_WHITESPACE:
188: ;
189: break;
190: default:
191: jj_la1[8] = jj_gen;
192: break label_5;
193: }
194: jj_consume_token(SQL_FN_WHITESPACE);
195: }
196: jj_consume_token(SQL_FN_PAREN);
197: label_6: while (true) {
198: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
199: case SQL_FN_WHITESPACE:
200: ;
201: break;
202: default:
203: jj_la1[9] = jj_gen;
204: break label_6;
205: }
206: jj_consume_token(SQL_FN_WHITESPACE);
207: }
208: id1 = jj_consume_token(SQL_FN_IDENTIFIER);
209: label_7: while (true) {
210: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
211: case SQL_FN_WHITESPACE:
212: ;
213: break;
214: default:
215: jj_la1[10] = jj_gen;
216: break label_7;
217: }
218: jj_consume_token(SQL_FN_WHITESPACE);
219: }
220: jj_consume_token(SQL_FN_COMMA);
221: label_8: while (true) {
222: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
223: case SQL_FN_WHITESPACE:
224: ;
225: break;
226: default:
227: jj_la1[11] = jj_gen;
228: break label_8;
229: }
230: jj_consume_token(SQL_FN_WHITESPACE);
231: }
232: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
233: case SQL_FN_PSTART:
234: t = jj_consume_token(SQL_FN_PSTART);
235: break;
236: default:
237: jj_la1[12] = jj_gen;
238: ;
239: }
240: id2 = jj_consume_token(SQL_FN_IDENTIFIER);
241: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
242: case SQL_FN_PEND:
243: jj_consume_token(SQL_FN_PEND);
244: break;
245: default:
246: jj_la1[13] = jj_gen;
247: ;
248: }
249: label_9: while (true) {
250: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
251: case SQL_FN_WHITESPACE:
252: ;
253: break;
254: default:
255: jj_la1[14] = jj_gen;
256: break label_9;
257: }
258: jj_consume_token(SQL_FN_WHITESPACE);
259: }
260: jj_consume_token(SQL_FN_END);
261: if (t == null) {
262: frag = new SqlSubstitutionFragment(new LiteralFragment(
263: "(" + id1.image + " IN (" + id2.image + ")"));
264: } else {
265: frag = new SqlSubstitutionFragment(new LiteralFragment(
266: "(" + id1.image + " IN ("),
267: new ReflectionFragment(id2.image),
268: new LiteralFragment("))"));
269: }
270: break;
271: default:
272: jj_la1[15] = jj_gen;
273: jj_consume_token(-1);
274: throw new ParseException();
275: }
276: jj_consume_token(END_EXPRESSION);
277: {
278: if (true)
279: return frag;
280: }
281: throw new Error("Missing return statement in function");
282: }
283:
284: //
285: // parse a param sub inside of a jdbc escape
286: //
287: final public SqlFragment parseReflect() throws ParseException {
288: Token t, tt = null;
289: SqlFragment frag;
290: jj_consume_token(JDBC_PARAM);
291: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
292: case PARAM_IDENTIFIER:
293: t = jj_consume_token(PARAM_IDENTIFIER);
294: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
295: case PARAM_REFLECT_SEP:
296: jj_consume_token(PARAM_REFLECT_SEP);
297: tt = jj_consume_token(IDENTIFIER);
298: break;
299: default:
300: jj_la1[16] = jj_gen;
301: ;
302: }
303: frag = new ReflectionFragment(t.image, (tt == null) ? null
304: : tt.image);
305: break;
306: case PARAM_LITERAL:
307: t = jj_consume_token(PARAM_LITERAL);
308: frag = new LiteralFragment(t.image);
309: break;
310: default:
311: jj_la1[17] = jj_gen;
312: jj_consume_token(-1);
313: throw new ParseException();
314: }
315: jj_consume_token(PARAM_END);
316: {
317: if (true)
318: return frag;
319: }
320: throw new Error("Missing return statement in function");
321: }
322:
323: //
324: // parse a jdbc escape sequence
325: //
326: final public JdbcFragment parseJdbcEscape() throws ParseException {
327: Token lit, c;
328: JdbcFragment jfrag = new JdbcFragment();
329: jfrag.addChild(new LiteralFragment("{"));
330: SqlFragment frag = null;
331: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
332: case JDBC_CALL:
333: c = jj_consume_token(JDBC_CALL);
334: break;
335: case JDBC_RET:
336: c = jj_consume_token(JDBC_RET);
337: break;
338: case JDBC_DATE:
339: c = jj_consume_token(JDBC_DATE);
340: break;
341: case JDBC_ESCAPE:
342: c = jj_consume_token(JDBC_ESCAPE);
343: break;
344: case JDBC_FUNCTION:
345: c = jj_consume_token(JDBC_FUNCTION);
346: break;
347: case JDBC_TIME:
348: c = jj_consume_token(JDBC_TIME);
349: break;
350: case JDBC_TIMESTAMP:
351: c = jj_consume_token(JDBC_TIMESTAMP);
352: break;
353: case JDBC_OUTERJOIN:
354: c = jj_consume_token(JDBC_OUTERJOIN);
355: break;
356: default:
357: jj_la1[18] = jj_gen;
358: jj_consume_token(-1);
359: throw new ParseException();
360: }
361: jfrag.addChild(new LiteralFragment(c.image));
362: label_10: while (true) {
363: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
364: case JDBC_LIT:
365: lit = jj_consume_token(JDBC_LIT);
366: jfrag.addChild(new LiteralFragment(lit.image));
367: break;
368: case JDBC_PARAM:
369: frag = parseReflect();
370: jfrag.addChild(frag);
371: break;
372: default:
373: jj_la1[19] = jj_gen;
374: jj_consume_token(-1);
375: throw new ParseException();
376: }
377: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
378: case JDBC_LIT:
379: case JDBC_PARAM:
380: ;
381: break;
382: default:
383: jj_la1[20] = jj_gen;
384: break label_10;
385: }
386: }
387: jj_consume_token(JDBC_END);
388: jfrag.addChild(new LiteralFragment("}"));
389: {
390: if (true)
391: return jfrag;
392: }
393: throw new Error("Missing return statement in function");
394: }
395:
396: public SqlGrammarTokenManager token_source;
397: SimpleCharStream jj_input_stream;
398: public Token token, jj_nt;
399: private int jj_ntk;
400: private int jj_gen;
401: final private int[] jj_la1 = new int[21];
402: static private int[] jj_la1_0;
403: static private int[] jj_la1_1;
404: static {
405: jj_la1_0();
406: jj_la1_1();
407: }
408:
409: private static void jj_la1_0() {
410: jj_la1_0 = new int[] { 0xe, 0xe, 0x100000, 0x100, 0x2ffe00,
411: 0x100000, 0x600, 0x40000000, 0x40000000, 0x40000000,
412: 0x40000000, 0x40000000, 0x10000000, 0x20000000,
413: 0x40000000, 0xe00, 0x0, 0x0, 0xff000, 0x0, 0x0, };
414: }
415:
416: private static void jj_la1_1() {
417: jj_la1_1 = new int[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
418: 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x28,
419: 0x0, 0x6, 0x6, };
420: }
421:
422: public SqlGrammar(java.io.InputStream stream) {
423: jj_input_stream = new SimpleCharStream(stream, 1, 1);
424: token_source = new SqlGrammarTokenManager(jj_input_stream);
425: token = new Token();
426: jj_ntk = -1;
427: jj_gen = 0;
428: for (int i = 0; i < 21; i++)
429: jj_la1[i] = -1;
430: }
431:
432: public void ReInit(java.io.InputStream stream) {
433: jj_input_stream.ReInit(stream, 1, 1);
434: token_source.ReInit(jj_input_stream);
435: token = new Token();
436: jj_ntk = -1;
437: jj_gen = 0;
438: for (int i = 0; i < 21; i++)
439: jj_la1[i] = -1;
440: }
441:
442: public SqlGrammar(java.io.Reader stream) {
443: jj_input_stream = new SimpleCharStream(stream, 1, 1);
444: token_source = new SqlGrammarTokenManager(jj_input_stream);
445: token = new Token();
446: jj_ntk = -1;
447: jj_gen = 0;
448: for (int i = 0; i < 21; i++)
449: jj_la1[i] = -1;
450: }
451:
452: public void ReInit(java.io.Reader stream) {
453: jj_input_stream.ReInit(stream, 1, 1);
454: token_source.ReInit(jj_input_stream);
455: token = new Token();
456: jj_ntk = -1;
457: jj_gen = 0;
458: for (int i = 0; i < 21; i++)
459: jj_la1[i] = -1;
460: }
461:
462: public SqlGrammar(SqlGrammarTokenManager tm) {
463: token_source = tm;
464: token = new Token();
465: jj_ntk = -1;
466: jj_gen = 0;
467: for (int i = 0; i < 21; i++)
468: jj_la1[i] = -1;
469: }
470:
471: public void ReInit(SqlGrammarTokenManager tm) {
472: token_source = tm;
473: token = new Token();
474: jj_ntk = -1;
475: jj_gen = 0;
476: for (int i = 0; i < 21; i++)
477: jj_la1[i] = -1;
478: }
479:
480: final private Token jj_consume_token(int kind)
481: throws ParseException {
482: Token oldToken;
483: if ((oldToken = token).next != null)
484: token = token.next;
485: else
486: token = token.next = token_source.getNextToken();
487: jj_ntk = -1;
488: if (token.kind == kind) {
489: jj_gen++;
490: return token;
491: }
492: token = oldToken;
493: jj_kind = kind;
494: throw generateParseException();
495: }
496:
497: final public Token getNextToken() {
498: if (token.next != null)
499: token = token.next;
500: else
501: token = token.next = token_source.getNextToken();
502: jj_ntk = -1;
503: jj_gen++;
504: return token;
505: }
506:
507: final public Token getToken(int index) {
508: Token t = token;
509: for (int i = 0; i < index; i++) {
510: if (t.next != null)
511: t = t.next;
512: else
513: t = t.next = token_source.getNextToken();
514: }
515: return t;
516: }
517:
518: final private int jj_ntk() {
519: if ((jj_nt = token.next) == null)
520: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
521: else
522: return (jj_ntk = jj_nt.kind);
523: }
524:
525: private java.util.Vector jj_expentries = new java.util.Vector();
526: private int[] jj_expentry;
527: private int jj_kind = -1;
528:
529: public ParseException generateParseException() {
530: jj_expentries.removeAllElements();
531: boolean[] la1tokens = new boolean[39];
532: for (int i = 0; i < 39; i++) {
533: la1tokens[i] = false;
534: }
535: if (jj_kind >= 0) {
536: la1tokens[jj_kind] = true;
537: jj_kind = -1;
538: }
539: for (int i = 0; i < 21; i++) {
540: if (jj_la1[i] == jj_gen) {
541: for (int j = 0; j < 32; j++) {
542: if ((jj_la1_0[i] & (1 << j)) != 0) {
543: la1tokens[j] = true;
544: }
545: if ((jj_la1_1[i] & (1 << j)) != 0) {
546: la1tokens[32 + j] = true;
547: }
548: }
549: }
550: }
551: for (int i = 0; i < 39; i++) {
552: if (la1tokens[i]) {
553: jj_expentry = new int[1];
554: jj_expentry[0] = i;
555: jj_expentries.addElement(jj_expentry);
556: }
557: }
558: int[][] exptokseq = new int[jj_expentries.size()][];
559: for (int i = 0; i < jj_expentries.size(); i++) {
560: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
561: }
562: return new ParseException(token, exptokseq, tokenImage);
563: }
564:
565: final public void enable_tracing() {
566: }
567:
568: final public void disable_tracing() {
569: }
570:
571: }
|