1
// $ANTLR 2.7.5 (20050128): "mapping.g" -> "MappingParser.java"$
4
* JasperReports - Free Java Reporting Library.
5
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
6
* http://www.jaspersoft.com
8
* Unless you have purchased a commercial license agreement from Jaspersoft,
9
* the following license terms apply:
11
* This program is part of JasperReports.
13
* JasperReports is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU Lesser General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
18
* JasperReports is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU Lesser General Public License for more details.
23
* You should have received a copy of the GNU Lesser General Public License
24
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
26
package net.sf.jasperreports.olap.mapping;
28
import java.util.ArrayList;
29
import java.util.List;
30
import java.util.regex.Matcher;
31
import java.util.regex.Pattern;
33
import antlr.NoViableAltException;
34
import antlr.ParserSharedInputState;
35
import antlr.RecognitionException;
37
import antlr.TokenBuffer;
38
import antlr.TokenStream;
39
import antlr.TokenStreamException;
40
import antlr.collections.impl.BitSet;
43
* @author Lucian Chirita (lucianc@users.sourceforge.net)
44
* @version $Id: MappingParser.java 3740 2010-04-16 15:03:17Z lucianc $
46
public class MappingParser extends antlr.LLkParser implements MappingParserTokenTypes
49
private MappingMetadata mappingMeta;
51
public void setMappingMetadata(MappingMetadata mappingMeta)
53
this.mappingMeta = mappingMeta;
56
private String getMondrName (String text)
58
return text.substring(1, text.length() - 1).trim();
61
private static final Pattern IDX_PATTERN = Pattern.compile("#(\\d+)");
62
private static final int IDX_GROUP = 1;
64
private int getDimensionIndex(Axis axis, String dimensionName)
67
Matcher matcher = IDX_PATTERN.matcher(dimensionName);
68
if (matcher.matches())
70
String idxStr = matcher.group(IDX_GROUP);
71
idx = Integer.parseInt(idxStr);
75
idx = mappingMeta.getDimensionIndex(axis, dimensionName);
80
private int getLevelDepth(TuplePosition pos, String levelName)
83
Matcher matcher = IDX_PATTERN.matcher(levelName);
84
if (matcher.matches())
86
String depthStr = matcher.group(IDX_GROUP);
87
depth = Integer.parseInt(depthStr);
91
depth = mappingMeta.getLevelDepth(pos, levelName);
96
protected MappingParser(TokenBuffer tokenBuf, int k) {
98
tokenNames = _tokenNames;
101
public MappingParser(TokenBuffer tokenBuf) {
105
protected MappingParser(TokenStream lexer, int k) {
107
tokenNames = _tokenNames;
110
public MappingParser(TokenStream lexer) {
114
public MappingParser(ParserSharedInputState state) {
116
tokenNames = _tokenNames;
119
public final Mapping mapping() throws RecognitionException, TokenStreamException {
120
Mapping mapping = null;
123
try { // for error handling
127
case LITERAL_Columns:
130
case LITERAL_Chapters:
131
case LITERAL_Sections:
133
mapping=memberMapping();
137
case LITERAL_FormattedData:
139
mapping=dataMapping();
144
throw new NoViableAltException(LT(1), getFilename());
148
match(Token.EOF_TYPE);
150
catch (RecognitionException ex) {
152
recover(ex,_tokenSet_0);
157
public final MemberMapping memberMapping() throws RecognitionException, TokenStreamException {
158
MemberMapping mapping = null;
160
Member member; MemberProperty prop = null;
162
try { // for error handling
177
throw new NoViableAltException(LT(1), getFilename());
181
mapping = new MemberMapping(member, prop);
183
catch (RecognitionException ex) {
185
recover(ex,_tokenSet_0);
190
public final DataMapping dataMapping() throws RecognitionException, TokenStreamException {
191
DataMapping mapping = null;
193
boolean formatted = false; List filter = null; List positions = null;
195
try { // for error handling
204
case LITERAL_FormattedData:
206
match(LITERAL_FormattedData);
212
throw new NoViableAltException(LT(1), getFilename());
217
if ((LA(1)==LPAREN) && (_tokenSet_1.member(LA(2)))) {
218
filter=memberFilter();
220
else if ((LA(1)==EOF||LA(1)==LPAREN) && (_tokenSet_2.member(LA(2)))) { //NOPMD
223
throw new NoViableAltException(LT(1), getFilename());
231
positions=axisPositions();
240
throw new NoViableAltException(LT(1), getFilename());
245
mapping = new DataMapping(formatted, filter, positions);
247
catch (RecognitionException ex) {
249
recover(ex,_tokenSet_0);
254
public final Member member() throws RecognitionException, TokenStreamException {
255
Member member = null;
257
Axis axis; TuplePosition pos; MemberDepth depth = null;
259
try { // for error handling
261
pos=tuplePosition(axis);
266
depth=memberDepth(axis, pos);
276
throw new NoViableAltException(LT(1), getFilename());
280
member = new Member(pos, depth);
282
catch (RecognitionException ex) {
284
recover(ex,_tokenSet_3);
289
public final MemberProperty property() throws RecognitionException, TokenStreamException {
290
MemberProperty prop = null;
294
try { // for error handling
298
prop = new MemberProperty(name);
300
catch (RecognitionException ex) {
302
recover(ex,_tokenSet_0);
307
public final Axis axis() throws RecognitionException, TokenStreamException {
312
try { // for error handling
325
case LITERAL_Columns:
328
case LITERAL_Chapters:
329
case LITERAL_Sections:
338
throw new NoViableAltException(LT(1), getFilename());
342
axis = new Axis(idx);
344
catch (RecognitionException ex) {
346
recover(ex,_tokenSet_4);
351
public final TuplePosition tuplePosition(
353
) throws RecognitionException, TokenStreamException {
354
TuplePosition pos = null;
358
try { // for error handling
359
String dimensionName;
360
dimensionName=mondrName();
361
idx = getDimensionIndex(axis, dimensionName);
362
pos = new TuplePosition(axis, idx);
364
catch (RecognitionException ex) {
366
recover(ex,_tokenSet_5);
371
public final MemberDepth memberDepth(
372
Axis axis, TuplePosition pos
373
) throws RecognitionException, TokenStreamException {
374
MemberDepth memberDepth = null;
377
try { // for error handling
379
levelName=mondrName();
380
memberDepth = new MemberDepth(getLevelDepth(pos, levelName));
382
catch (RecognitionException ex) {
384
recover(ex,_tokenSet_6);
389
public final Member memberLevel() throws RecognitionException, TokenStreamException {
390
Member member = null;
392
Axis axis; TuplePosition pos; MemberDepth depth;
394
try { // for error handling
396
pos=tuplePosition(axis);
397
depth=memberDepth(axis, pos);
398
member = new Member(pos, depth);
400
catch (RecognitionException ex) {
402
recover(ex,_tokenSet_7);
407
public final int idx() throws RecognitionException, TokenStreamException {
412
try { // for error handling
415
i = Integer.parseInt(idx.getText());
417
catch (RecognitionException ex) {
419
recover(ex,_tokenSet_7);
424
public final int axisName() throws RecognitionException, TokenStreamException {
428
try { // for error handling
431
case LITERAL_Columns:
433
match(LITERAL_Columns);
445
match(LITERAL_Pages);
449
case LITERAL_Chapters:
451
match(LITERAL_Chapters);
455
case LITERAL_Sections:
457
match(LITERAL_Sections);
463
throw new NoViableAltException(LT(1), getFilename());
468
catch (RecognitionException ex) {
470
recover(ex,_tokenSet_4);
475
public final String mondrName() throws RecognitionException, TokenStreamException {
480
try { // for error handling
483
name = getMondrName(n.getText());
485
catch (RecognitionException ex) {
487
recover(ex,_tokenSet_8);
492
public final String name() throws RecognitionException, TokenStreamException {
497
try { // for error handling
502
catch (RecognitionException ex) {
504
recover(ex,_tokenSet_9);
509
public final List memberFilter() throws RecognitionException, TokenStreamException {
510
List filter = new ArrayList();
514
try { // for error handling
516
member=memberLevel();
521
if ((LA(1)==COMMA)) {
523
member=memberLevel();
534
catch (RecognitionException ex) {
536
recover(ex,_tokenSet_3);
541
public final List axisPositions() throws RecognitionException, TokenStreamException {
542
List positions = new ArrayList();
544
AxisPosition pos; int axis = 0;
546
try { // for error handling
548
pos=axisPosition(axis);
549
++axis; positions.add(pos);
553
if ((LA(1)==COMMA)) {
555
pos=axisPosition(axis);
556
++axis; positions.add(pos);
566
catch (RecognitionException ex) {
568
recover(ex,_tokenSet_0);
573
public final AxisPosition axisPosition(
575
) throws RecognitionException, TokenStreamException {
576
AxisPosition pos = null;
580
try { // for error handling
586
idx = AxisPosition.POSITION_UNSPECIFIED;
599
idx = mappingMeta.getTuplePosition(axis, tuple);
604
throw new NoViableAltException(LT(1), getFilename());
608
pos = new AxisPosition(idx);
610
catch (RecognitionException ex) {
612
recover(ex,_tokenSet_7);
617
public final Tuple tuple() throws RecognitionException, TokenStreamException {
622
try { // for error handling
629
member=tupleMember();
630
tuple.addMember(member);
634
if ((LA(1)==COMMA)) {
636
member=tupleMember();
637
tuple.addMember(member);
651
member=tupleMember();
652
tuple = new Tuple(member);
657
throw new NoViableAltException(LT(1), getFilename());
661
catch (RecognitionException ex) {
663
recover(ex,_tokenSet_7);
668
public final TupleMember tupleMember() throws RecognitionException, TokenStreamException {
669
TupleMember tuple = new TupleMember();
673
try { // for error handling
679
if ((LA(1)==POINT)) {
691
catch (RecognitionException ex) {
693
recover(ex,_tokenSet_7);
699
public static final String[] _tokenNames = {
703
"NULL_TREE_LOOKAHEAD",
728
private static final long[] mk_tokenSet_0() {
729
long[] data = { 2L, 0L};
732
public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
733
private static final long[] mk_tokenSet_1() {
734
long[] data = { 3984L, 0L};
737
public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
738
private static final long[] mk_tokenSet_2() {
739
long[] data = { 426018L, 0L};
742
public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
743
private static final long[] mk_tokenSet_3() {
744
long[] data = { 34L, 0L};
747
public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
748
private static final long[] mk_tokenSet_4() {
749
long[] data = { 262144L, 0L};
752
public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
753
private static final long[] mk_tokenSet_5() {
754
long[] data = { 262178L, 0L};
757
public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5());
758
private static final long[] mk_tokenSet_6() {
759
long[] data = { 16482L, 0L};
762
public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6());
763
private static final long[] mk_tokenSet_7() {
764
long[] data = { 16448L, 0L};
767
public static final BitSet _tokenSet_7 = new BitSet(mk_tokenSet_7());
768
private static final long[] mk_tokenSet_8() {
769
long[] data = { 344162L, 0L};
772
public static final BitSet _tokenSet_8 = new BitSet(mk_tokenSet_8());
773
private static final long[] mk_tokenSet_9() {
774
long[] data = { 64L, 0L};
777
public static final BitSet _tokenSet_9 = new BitSet(mk_tokenSet_9());