001: // $ANTLR 2.7.5 (20050128): "mapping.g" -> "MappingParser.java"$
002:
003: /*
004: * ============================================================================
005: * GNU Lesser General Public License
006: * ============================================================================
007: *
008: * JasperReports - Free Java report-generating library.
009: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public
022: * License along with this library; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
024: *
025: * JasperSoft Corporation
026: * 303 Second Street, Suite 450 North
027: * San Francisco, CA 94107
028: * http://www.jaspersoft.com
029: */
030: package net.sf.jasperreports.olap.mapping;
031:
032: import java.util.List;
033: import java.util.ArrayList;
034:
035: import net.sf.jasperreports.olap.mapping.*;
036:
037: import antlr.TokenBuffer;
038: import antlr.TokenStreamException;
039: import antlr.TokenStreamIOException;
040: import antlr.ANTLRException;
041: import antlr.LLkParser;
042: import antlr.Token;
043: import antlr.TokenStream;
044: import antlr.RecognitionException;
045: import antlr.NoViableAltException;
046: import antlr.MismatchedTokenException;
047: import antlr.SemanticException;
048: import antlr.ParserSharedInputState;
049: import antlr.collections.impl.BitSet;
050:
051: /**
052: * @author Lucian Chirita (lucianc@users.sourceforge.net)
053: * @version $Id: MappingParser.java 1797 2007-07-30 09:38:35Z teodord $
054: */
055: public class MappingParser extends antlr.LLkParser implements
056: MappingParserTokenTypes {
057:
058: private MappingMetadata mappingMeta;
059:
060: public void setMappingMetadata(MappingMetadata mappingMeta) {
061: this .mappingMeta = mappingMeta;
062: }
063:
064: private String getMondrName(String text) {
065: return text.substring(1, text.length() - 1).trim();
066: }
067:
068: private int getMondrIdx(String text) {
069: return Integer.parseInt(text.substring(2, text.length() - 1)
070: .trim());
071: }
072:
073: protected MappingParser(TokenBuffer tokenBuf, int k) {
074: super (tokenBuf, k);
075: tokenNames = _tokenNames;
076: }
077:
078: public MappingParser(TokenBuffer tokenBuf) {
079: this (tokenBuf, 2);
080: }
081:
082: protected MappingParser(TokenStream lexer, int k) {
083: super (lexer, k);
084: tokenNames = _tokenNames;
085: }
086:
087: public MappingParser(TokenStream lexer) {
088: this (lexer, 2);
089: }
090:
091: public MappingParser(ParserSharedInputState state) {
092: super (state, 2);
093: tokenNames = _tokenNames;
094: }
095:
096: public final Mapping mapping() throws RecognitionException,
097: TokenStreamException {
098: Mapping mapping = null;
099:
100: try { // for error handling
101: {
102: switch (LA(1)) {
103: case LITERAL_Axis:
104: case LITERAL_Columns:
105: case LITERAL_Rows:
106: case LITERAL_Pages:
107: case LITERAL_Chapters:
108: case LITERAL_Sections: {
109: mapping = memberMapping();
110: break;
111: }
112: case LITERAL_Data:
113: case LITERAL_FormattedData: {
114: mapping = dataMapping();
115: break;
116: }
117: default: {
118: throw new NoViableAltException(LT(1), getFilename());
119: }
120: }
121: }
122: match(Token.EOF_TYPE);
123: } catch (RecognitionException ex) {
124: reportError(ex);
125: recover(ex, _tokenSet_0);
126: }
127: return mapping;
128: }
129:
130: public final MemberMapping memberMapping()
131: throws RecognitionException, TokenStreamException {
132: MemberMapping mapping = null;
133:
134: Member member;
135: MemberProperty prop = null;
136:
137: try { // for error handling
138: member = member();
139: {
140: switch (LA(1)) {
141: case LPAREN: {
142: prop = property();
143: break;
144: }
145: case EOF: {
146: break;
147: }
148: default: {
149: throw new NoViableAltException(LT(1), getFilename());
150: }
151: }
152: }
153: mapping = new MemberMapping(member, prop);
154: } catch (RecognitionException ex) {
155: reportError(ex);
156: recover(ex, _tokenSet_0);
157: }
158: return mapping;
159: }
160:
161: public final DataMapping dataMapping() throws RecognitionException,
162: TokenStreamException {
163: DataMapping mapping = null;
164:
165: boolean formatted = false;
166: List filter = null;
167: List positions = null;
168:
169: try { // for error handling
170: {
171: {
172: switch (LA(1)) {
173: case LITERAL_Data: {
174: match(LITERAL_Data);
175: break;
176: }
177: case LITERAL_FormattedData: {
178: match(LITERAL_FormattedData);
179: formatted = true;
180: break;
181: }
182: default: {
183: throw new NoViableAltException(LT(1),
184: getFilename());
185: }
186: }
187: }
188: {
189: if ((LA(1) == LPAREN)
190: && (_tokenSet_1.member(LA(2)))) {
191: filter = memberFilter();
192: } else if ((LA(1) == EOF || LA(1) == LPAREN)
193: && (_tokenSet_2.member(LA(2)))) {
194: } else {
195: throw new NoViableAltException(LT(1),
196: getFilename());
197: }
198:
199: }
200: {
201: switch (LA(1)) {
202: case LPAREN: {
203: positions = axisPositions();
204: break;
205: }
206: case EOF: {
207: break;
208: }
209: default: {
210: throw new NoViableAltException(LT(1),
211: getFilename());
212: }
213: }
214: }
215: }
216: mapping = new DataMapping(formatted, filter, positions);
217: } catch (RecognitionException ex) {
218: reportError(ex);
219: recover(ex, _tokenSet_0);
220: }
221: return mapping;
222: }
223:
224: public final Member member() throws RecognitionException,
225: TokenStreamException {
226: Member member = null;
227:
228: Axis axis;
229: TuplePosition pos;
230: MemberDepth depth = null;
231:
232: try { // for error handling
233: axis = axis();
234: pos = tuplePosition(axis);
235: {
236: switch (LA(1)) {
237: case MONDRNAME:
238: case MONDRIDX: {
239: depth = memberDepth(axis, pos);
240: break;
241: }
242: case EOF:
243: case LPAREN: {
244: break;
245: }
246: default: {
247: throw new NoViableAltException(LT(1), getFilename());
248: }
249: }
250: }
251: member = new Member(pos, depth);
252: } catch (RecognitionException ex) {
253: reportError(ex);
254: recover(ex, _tokenSet_3);
255: }
256: return member;
257: }
258:
259: public final MemberProperty property() throws RecognitionException,
260: TokenStreamException {
261: MemberProperty prop = null;
262:
263: String name;
264:
265: try { // for error handling
266: match(LPAREN);
267: name = name();
268: match(RPAREN);
269: prop = new MemberProperty(name);
270: } catch (RecognitionException ex) {
271: reportError(ex);
272: recover(ex, _tokenSet_0);
273: }
274: return prop;
275: }
276:
277: public final Axis axis() throws RecognitionException,
278: TokenStreamException {
279: Axis axis = null;
280:
281: int idx;
282:
283: try { // for error handling
284: {
285: switch (LA(1)) {
286: case LITERAL_Axis: {
287: {
288: match(LITERAL_Axis);
289: match(LPAREN);
290: idx = idx();
291: match(RPAREN);
292: }
293: break;
294: }
295: case LITERAL_Columns:
296: case LITERAL_Rows:
297: case LITERAL_Pages:
298: case LITERAL_Chapters:
299: case LITERAL_Sections: {
300: {
301: idx = axisName();
302: }
303: break;
304: }
305: default: {
306: throw new NoViableAltException(LT(1), getFilename());
307: }
308: }
309: }
310: axis = new Axis(idx);
311: } catch (RecognitionException ex) {
312: reportError(ex);
313: recover(ex, _tokenSet_4);
314: }
315: return axis;
316: }
317:
318: public final TuplePosition tuplePosition(Axis axis)
319: throws RecognitionException, TokenStreamException {
320: TuplePosition pos = null;
321:
322: int idx;
323:
324: try { // for error handling
325: {
326: switch (LA(1)) {
327: case MONDRIDX: {
328: idx = mondrIdx();
329: break;
330: }
331: case MONDRNAME: {
332: String dimensionName;
333: dimensionName = mondrName();
334: idx = mappingMeta.getDimensionIndex(axis,
335: dimensionName);
336: break;
337: }
338: default: {
339: throw new NoViableAltException(LT(1), getFilename());
340: }
341: }
342: }
343: pos = new TuplePosition(axis, idx);
344: } catch (RecognitionException ex) {
345: reportError(ex);
346: recover(ex, _tokenSet_5);
347: }
348: return pos;
349: }
350:
351: public final MemberDepth memberDepth(Axis axis, TuplePosition pos)
352: throws RecognitionException, TokenStreamException {
353: MemberDepth memberDepth = null;
354:
355: try { // for error handling
356: {
357: switch (LA(1)) {
358: case MONDRIDX: {
359: int depth;
360: depth = mondrIdx();
361: memberDepth = new MemberDepth(depth);
362: break;
363: }
364: case MONDRNAME: {
365: String levelName;
366: levelName = mondrName();
367: memberDepth = new MemberDepth(mappingMeta
368: .getLevelDepth(pos, levelName));
369: break;
370: }
371: default: {
372: throw new NoViableAltException(LT(1), getFilename());
373: }
374: }
375: }
376: } catch (RecognitionException ex) {
377: reportError(ex);
378: recover(ex, _tokenSet_6);
379: }
380: return memberDepth;
381: }
382:
383: public final Member memberLevel() throws RecognitionException,
384: TokenStreamException {
385: Member member = null;
386:
387: Axis axis;
388: TuplePosition pos;
389: MemberDepth depth;
390:
391: try { // for error handling
392: axis = axis();
393: pos = tuplePosition(axis);
394: depth = memberDepth(axis, pos);
395: member = new Member(pos, depth);
396: } catch (RecognitionException ex) {
397: reportError(ex);
398: recover(ex, _tokenSet_7);
399: }
400: return member;
401: }
402:
403: public final int idx() throws RecognitionException,
404: TokenStreamException {
405: int i = -1;
406:
407: Token idx = null;
408:
409: try { // for error handling
410: idx = LT(1);
411: match(INT);
412: i = Integer.parseInt(idx.getText());
413: } catch (RecognitionException ex) {
414: reportError(ex);
415: recover(ex, _tokenSet_7);
416: }
417: return i;
418: }
419:
420: public final int axisName() throws RecognitionException,
421: TokenStreamException {
422: int idx = -1;
423:
424: try { // for error handling
425: {
426: switch (LA(1)) {
427: case LITERAL_Columns: {
428: match(LITERAL_Columns);
429: idx = 0;
430: break;
431: }
432: case LITERAL_Rows: {
433: match(LITERAL_Rows);
434: idx = 1;
435: break;
436: }
437: case LITERAL_Pages: {
438: match(LITERAL_Pages);
439: idx = 2;
440: break;
441: }
442: case LITERAL_Chapters: {
443: match(LITERAL_Chapters);
444: idx = 3;
445: break;
446: }
447: case LITERAL_Sections: {
448: match(LITERAL_Sections);
449: idx = 4;
450: break;
451: }
452: default: {
453: throw new NoViableAltException(LT(1), getFilename());
454: }
455: }
456: }
457: } catch (RecognitionException ex) {
458: reportError(ex);
459: recover(ex, _tokenSet_4);
460: }
461: return idx;
462: }
463:
464: public final int mondrIdx() throws RecognitionException,
465: TokenStreamException {
466: int i = -1;
467:
468: Token n = null;
469:
470: try { // for error handling
471: n = LT(1);
472: match(MONDRIDX);
473: i = getMondrIdx(n.getText());
474: } catch (RecognitionException ex) {
475: reportError(ex);
476: recover(ex, _tokenSet_8);
477: }
478: return i;
479: }
480:
481: public final String mondrName() throws RecognitionException,
482: TokenStreamException {
483: String name = null;
484:
485: Token n = null;
486:
487: try { // for error handling
488: n = LT(1);
489: match(MONDRNAME);
490: name = getMondrName(n.getText());
491: } catch (RecognitionException ex) {
492: reportError(ex);
493: recover(ex, _tokenSet_9);
494: }
495: return name;
496: }
497:
498: public final String name() throws RecognitionException,
499: TokenStreamException {
500: String name = null;
501:
502: Token n = null;
503:
504: try { // for error handling
505: n = LT(1);
506: match(NAME);
507: name = n.getText();
508: } catch (RecognitionException ex) {
509: reportError(ex);
510: recover(ex, _tokenSet_10);
511: }
512: return name;
513: }
514:
515: public final List memberFilter() throws RecognitionException,
516: TokenStreamException {
517: List filter = new ArrayList();
518: ;
519:
520: Member member;
521:
522: try { // for error handling
523: match(LPAREN);
524: member = memberLevel();
525: filter.add(member);
526: {
527: _loop26: do {
528: if ((LA(1) == COMMA)) {
529: match(COMMA);
530: member = memberLevel();
531: filter.add(member);
532: } else {
533: break _loop26;
534: }
535:
536: } while (true);
537: }
538: match(RPAREN);
539: } catch (RecognitionException ex) {
540: reportError(ex);
541: recover(ex, _tokenSet_3);
542: }
543: return filter;
544: }
545:
546: public final List axisPositions() throws RecognitionException,
547: TokenStreamException {
548: List positions = new ArrayList();
549: ;
550:
551: AxisPosition pos;
552: int axis = 0;
553:
554: try { // for error handling
555: match(LPAREN);
556: pos = axisPosition(axis);
557: ++axis;
558: positions.add(pos);
559: {
560: _loop29: do {
561: if ((LA(1) == COMMA)) {
562: match(COMMA);
563: pos = axisPosition(axis);
564: ++axis;
565: positions.add(pos);
566: } else {
567: break _loop29;
568: }
569:
570: } while (true);
571: }
572: match(RPAREN);
573: } catch (RecognitionException ex) {
574: reportError(ex);
575: recover(ex, _tokenSet_0);
576: }
577: return positions;
578: }
579:
580: public final AxisPosition axisPosition(int axis)
581: throws RecognitionException, TokenStreamException {
582: AxisPosition pos = null;
583:
584: int idx;
585:
586: try { // for error handling
587: {
588: switch (LA(1)) {
589: case QMARK: {
590: match(QMARK);
591: idx = AxisPosition.POSITION_UNSPECIFIED;
592: break;
593: }
594: case INT: {
595: idx = idx();
596: break;
597: }
598: case LPAREN:
599: case MONDRNAME: {
600: Tuple tuple;
601: tuple = tuple();
602: idx = mappingMeta.getTuplePosition(axis, tuple);
603: break;
604: }
605: default: {
606: throw new NoViableAltException(LT(1), getFilename());
607: }
608: }
609: }
610: pos = new AxisPosition(idx);
611: } catch (RecognitionException ex) {
612: reportError(ex);
613: recover(ex, _tokenSet_7);
614: }
615: return pos;
616: }
617:
618: public final Tuple tuple() throws RecognitionException,
619: TokenStreamException {
620: Tuple tuple = null;
621:
622: TupleMember member;
623:
624: try { // for error handling
625: switch (LA(1)) {
626: case LPAREN: {
627: {
628: match(LPAREN);
629: tuple = new Tuple();
630: member = tupleMember();
631: tuple.addMember(member);
632: {
633: _loop35: do {
634: if ((LA(1) == COMMA)) {
635: match(COMMA);
636: member = tupleMember();
637: tuple.addMember(member);
638: } else {
639: break _loop35;
640: }
641:
642: } while (true);
643: }
644: match(RPAREN);
645: }
646: break;
647: }
648: case MONDRNAME: {
649: member = tupleMember();
650: tuple = new Tuple(member);
651: break;
652: }
653: default: {
654: throw new NoViableAltException(LT(1), getFilename());
655: }
656: }
657: } catch (RecognitionException ex) {
658: reportError(ex);
659: recover(ex, _tokenSet_7);
660: }
661: return tuple;
662: }
663:
664: public final TupleMember tupleMember() throws RecognitionException,
665: TokenStreamException {
666: TupleMember tuple = new TupleMember();
667:
668: String name;
669:
670: try { // for error handling
671: name = mondrName();
672: tuple.addName(name);
673: {
674: _loop38: do {
675: if ((LA(1) == POINT)) {
676: match(POINT);
677: name = mondrName();
678: tuple.addName(name);
679: } else {
680: break _loop38;
681: }
682:
683: } while (true);
684: }
685: } catch (RecognitionException ex) {
686: reportError(ex);
687: recover(ex, _tokenSet_7);
688: }
689: return tuple;
690: }
691:
692: public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
693: "NULL_TREE_LOOKAHEAD", "\"Axis\"", "LPAREN", "RPAREN",
694: "\"Columns\"", "\"Rows\"", "\"Pages\"", "\"Chapters\"",
695: "\"Sections\"", "\"Data\"", "\"FormattedData\"", "COMMA",
696: "QMARK", "POINT", "INT", "MONDRNAME", "MONDRIDX", "NAME",
697: "PLUS", "MINUS", "STAR", "WS", "MONDRCH", "DIGIT", "LETTER" };
698:
699: private static final long[] mk_tokenSet_0() {
700: long[] data = { 2L, 0L };
701: return data;
702: }
703:
704: public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
705:
706: private static final long[] mk_tokenSet_1() {
707: long[] data = { 3984L, 0L };
708: return data;
709: }
710:
711: public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
712:
713: private static final long[] mk_tokenSet_2() {
714: long[] data = { 426018L, 0L };
715: return data;
716: }
717:
718: public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
719:
720: private static final long[] mk_tokenSet_3() {
721: long[] data = { 34L, 0L };
722: return data;
723: }
724:
725: public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
726:
727: private static final long[] mk_tokenSet_4() {
728: long[] data = { 786432L, 0L };
729: return data;
730: }
731:
732: public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
733:
734: private static final long[] mk_tokenSet_5() {
735: long[] data = { 786466L, 0L };
736: return data;
737: }
738:
739: public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5());
740:
741: private static final long[] mk_tokenSet_6() {
742: long[] data = { 16482L, 0L };
743: return data;
744: }
745:
746: public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6());
747:
748: private static final long[] mk_tokenSet_7() {
749: long[] data = { 16448L, 0L };
750: return data;
751: }
752:
753: public static final BitSet _tokenSet_7 = new BitSet(mk_tokenSet_7());
754:
755: private static final long[] mk_tokenSet_8() {
756: long[] data = { 802914L, 0L };
757: return data;
758: }
759:
760: public static final BitSet _tokenSet_8 = new BitSet(mk_tokenSet_8());
761:
762: private static final long[] mk_tokenSet_9() {
763: long[] data = { 868450L, 0L };
764: return data;
765: }
766:
767: public static final BitSet _tokenSet_9 = new BitSet(mk_tokenSet_9());
768:
769: private static final long[] mk_tokenSet_10() {
770: long[] data = { 64L, 0L };
771: return data;
772: }
773:
774: public static final BitSet _tokenSet_10 = new BitSet(
775: mk_tokenSet_10());
776:
777: }
|