blob: 9080f9c7dac20b7421657b8110352ff2460b8f36 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(AQLParser)
10
11package edu.uci.ics.asterix.aql.parser;
12
13import java.io.*;
14import java.util.List;
15import java.util.ArrayList;
vinayakb38b7ca42012-03-05 05:44:15 +000016import java.util.Map;
17import java.util.HashMap;
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +000018import java.util.LinkedHashMap;
Till Westmann96c1f172013-08-01 02:05:48 -070019
20import org.apache.xerces.util.IntStack;
21
vinayakb38b7ca42012-03-05 05:44:15 +000022import edu.uci.ics.asterix.aql.literal.FloatLiteral;
23import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
24import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000025import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000026import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000027import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000028import edu.uci.ics.asterix.aql.literal.NullLiteral;
29import edu.uci.ics.asterix.aql.literal.StringLiteral;
30import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000031import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000032
33import edu.uci.ics.asterix.aql.base.*;
34import edu.uci.ics.asterix.aql.expression.*;
35import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
36import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
37import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
38import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
39import edu.uci.ics.asterix.aql.base.Statement.Kind;
40import edu.uci.ics.asterix.aql.context.Scope;
41import edu.uci.ics.asterix.aql.context.RootScopeFactory;
42import edu.uci.ics.asterix.common.annotations.*;
43import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000044import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000045import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000046import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
47import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000048import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
49import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
50import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
51
52
vinayakb38b7ca42012-03-05 05:44:15 +000053
54
55public class AQLParser extends ScopeChecker {
56
vinayakb38b7ca42012-03-05 05:44:15 +000057 // optimizer hints
58 private static final String HASH_GROUP_BY_HINT = "hash";
59 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000060 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000061 private static final String INMEMORY_HINT = "inmem";
62 private static final String VAL_FILE_HINT = "val-files";
63 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
64 private static final String INTERVAL_HINT = "interval";
65 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
66 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
67 private static final String LIST_VAL_FILE_HINT = "list-val-file";
68 private static final String LIST_HINT = "list";
69 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
70 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
71 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
72 private static final String AUTO_HINT = "auto";
73
74 private static final String GEN_FIELDS_HINT = "gen-fields";
75
76 // data generator hints
77 private static final String DGEN_HINT = "dgen";
Till Westmann31c21f92013-05-08 09:21:53 -070078
79 private static class IndexParams {
80 public IndexType type;
81 public int gramLength;
82
83 public IndexParams(IndexType type, int gramLength) {
84 this.type = type;
85 this.gramLength = gramLength;
86 }
87 };
vinayakb38b7ca42012-03-05 05:44:15 +000088
89 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070090 if (t.specialToken == null) {
91 return null;
92 }
93 String s = t.specialToken.image;
94 int n = s.length();
95 if (n < 2) {
96 return null;
97 }
98 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +000099 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700100
101 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
102 IRecordFieldDataGen rfdg = null;
103 String splits[] = hint.split(" +");
104 if (splits[0].equals(VAL_FILE_HINT)) {
105 File[] valFiles = new File[splits.length - 1];
106 for (int k=1; k<splits.length; k++) {
107 valFiles[k-1] = new File(splits[k]);
108 }
109 rfdg = new FieldValFileDataGen(valFiles);
110 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
111 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
112 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
113 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
114 } else if (splits[0].equals(LIST_HINT)) {
115 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
116 } else if (splits[0].equals(INTERVAL_HINT)) {
117 FieldIntervalDataGen.ValueType vt;
118 if (splits[1].equals("int")) {
119 vt = FieldIntervalDataGen.ValueType.INT;
120 } else if (splits[1].equals("long")) {
121 vt = FieldIntervalDataGen.ValueType.LONG;
122 } else if (splits[1].equals("float")) {
123 vt = FieldIntervalDataGen.ValueType.FLOAT;
124 } else if (splits[1].equals("double")) {
125 vt = FieldIntervalDataGen.ValueType.DOUBLE;
126 } else {
127 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
128 }
129 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
130 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
131 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
132 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
133 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
134 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
135 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
136 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
137 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
138 } else if (splits[0].equals(AUTO_HINT)) {
139 rfdg = new AutoDataGen(splits[1]);
140 }
141 return rfdg;
142 }
vinayakb38b7ca42012-03-05 05:44:15 +0000143
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000144 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700145 this(new StringReader(s));
146 super.setInput(s);
147 }
vinayakb38b7ca42012-03-05 05:44:15 +0000148
Till Westmann31c21f92013-05-08 09:21:53 -0700149 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
150 File file = new File(args[0]);
151 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
152 AQLParser parser = new AQLParser(fis);
153 List<Statement> st = parser.Statement();
154 //st.accept(new AQLPrintVisitor(), 0);
155 }
vinayakb38b7ca42012-03-05 05:44:15 +0000156}
157
158PARSER_END(AQLParser)
159
160
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000161List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000162{
vinayakb38b7ca42012-03-05 05:44:15 +0000163 scopeStack.push(RootScopeFactory.createRootScope(this));
164 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700165 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000166}
167{
Till Westmann31c21f92013-05-08 09:21:53 -0700168 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000169 {
Till Westmann31c21f92013-05-08 09:21:53 -0700170 decls.add(stmt);
171 }
172 )*
173 <EOF>
174 {
175 return decls;
176 }
177}
178
179Statement SingleStatement() throws ParseException:
180{
181 Statement stmt = null;
182}
183{
184 (
185 stmt = DataverseDeclaration()
186 | stmt = FunctionDeclaration()
187 | stmt = CreateStatement()
188 | stmt = LoadStatement()
189 | stmt = DropStatement()
190 | stmt = WriteStatement()
191 | stmt = SetStatement()
192 | stmt = InsertStatement()
193 | stmt = DeleteStatement()
194 | stmt = UpdateStatement()
195 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700196 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700197 | stmt = Query()
198 )
199 {
200 return stmt;
201 }
202}
203
204DataverseDecl DataverseDeclaration() throws ParseException:
205{
Till Westmann14a20a72013-05-09 00:06:24 -0700206 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700207}
208{
Till Westmanna4242bc2013-05-08 17:49:55 -0700209 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700210 {
Till Westmann14a20a72013-05-09 00:06:24 -0700211 defaultDataverse = dvName;
212 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700213 }
214}
215
216Statement CreateStatement() throws ParseException:
217{
218 String hint = null;
219 boolean dgen = false;
220 Statement stmt = null;
221}
222{
223 "create"
224 (
225 {
226 hint = getHint(token);
227 if (hint != null && hint.startsWith(DGEN_HINT)) {
228 dgen = true;
229 }
230 }
231 stmt = TypeSpecification(hint, dgen)
232 | stmt = NodegroupSpecification()
233 | stmt = DatasetSpecification()
234 | stmt = IndexSpecification()
235 | stmt = DataverseSpecification()
236 | stmt = FunctionSpecification()
237 )
238 {
239 return stmt;
240 }
241}
242
243TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
244{
245 Pair<Identifier,Identifier> nameComponents = null;
246 boolean ifNotExists = false;
247 TypeExpression typeExpr = null;
248}
249{
250 "type" nameComponents = FunctionOrTypeName() ifNotExists = IfNotExists()
251 "as" typeExpr = TypeExpr()
252 {
253 long numValues = -1;
254 String filename = null;
255 if (dgen) {
256 String splits[] = hint.split(" +");
257 if (splits.length != 3) {
258 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
259 }
260 filename = splits[1];
261 numValues = Long.parseLong(splits[2]);
262 }
263 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
264 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
265 }
266}
267
268
269NodegroupDecl NodegroupSpecification() throws ParseException:
270{
Till Westmann14a20a72013-05-09 00:06:24 -0700271 String name = null;
272 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700273 boolean ifNotExists = false;
274 List<Identifier>ncNames = null;
275}
276{
Till Westmanna4242bc2013-05-08 17:49:55 -0700277 "nodegroup" name = Identifier()
278 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700279 {
280 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700281 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700282 }
Till Westmann96c1f172013-08-01 02:05:48 -0700283 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700284 {
Till Westmann14a20a72013-05-09 00:06:24 -0700285 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700286 }
287 )*
288 {
Till Westmann14a20a72013-05-09 00:06:24 -0700289 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700290 }
291}
292
293DatasetDecl DatasetSpecification() throws ParseException:
294{
295 Pair<Identifier,Identifier> nameComponents = null;
296 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700297 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700298 String adapterName = null;
299 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700300 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700301 FunctionSignature appliedFunction = null;
302 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700303 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700304 Map<String,String> hints = new HashMap<String,String>();
305 DatasetDecl dsetDecl = null;
salsubaiee0b423fa2013-09-19 19:16:48 -0700306 String compactionPolicy = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700307}
308{
309 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700310 "external" <DATASET> nameComponents = QualifiedName()
311 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
312 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700313 "using" adapterName = AdapterName() properties = Configuration()
314 ( "hints" hints = Properties() )?
315 {
Abdullah Alamoudi4f96fc92013-09-14 21:29:14 -0700316 ExternalDetailsDecl edd = new ExternalDetailsDecl();
317 edd.setAdapter(adapterName);
318 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700319 dsetDecl = new DatasetDecl(nameComponents.first,
320 nameComponents.second,
321 new Identifier(typeName),
322 hints,
323 DatasetType.EXTERNAL,
324 edd,
325 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700326 }
327
Till Westmanna4242bc2013-05-08 17:49:55 -0700328 | "feed" <DATASET> nameComponents = QualifiedName()
329 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
330 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700331 "using" adapterName = AdapterName() properties = Configuration()
332 (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey()
Till Westmanna4242bc2013-05-08 17:49:55 -0700333 ( "on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700334 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700335 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700336 {
Till Westmann14a20a72013-05-09 00:06:24 -0700337 FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName,
338 properties,
339 appliedFunction,
340 nodeGroupName != null
341 ? new Identifier(nodeGroupName)
342 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700343 primaryKeyFields,
344 compactionPolicy,
345 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700346 dsetDecl = new DatasetDecl(nameComponents.first,
347 nameComponents.second,
348 new Identifier(typeName),
349 hints,
350 DatasetType.FEED,
351 fdd,
352 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700353 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700354 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700355 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
356 ifNotExists = IfNotExists()
357 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700358 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700359 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700360 {
Till Westmann14a20a72013-05-09 00:06:24 -0700361 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
362 ? new Identifier(nodeGroupName)
363 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700364 primaryKeyFields,
365 compactionPolicy,
366 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700367 dsetDecl = new DatasetDecl(nameComponents.first,
368 nameComponents.second,
369 new Identifier(typeName),
370 hints,
371 DatasetType.INTERNAL,
372 idd,
373 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700374 }
375 )
376 {
377 return dsetDecl;
378 }
379}
380
381CreateIndexStatement IndexSpecification() throws ParseException:
382{
383 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700384 String indexName = null;
385 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700386 boolean ifNotExists = false;
387 Pair<Identifier,Identifier> nameComponents = null;
388 IndexParams indexType = null;
389}
390{
Till Westmanna4242bc2013-05-08 17:49:55 -0700391 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700392 ifNotExists = IfNotExists()
393 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700394 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700395 {
Till Westmann14a20a72013-05-09 00:06:24 -0700396 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700397 }
Till Westmann96c1f172013-08-01 02:05:48 -0700398 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700399 {
Till Westmann14a20a72013-05-09 00:06:24 -0700400 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700401 }
402 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
403 {
Till Westmann14a20a72013-05-09 00:06:24 -0700404 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700405 cis.setIfNotExists(ifNotExists);
406 cis.setDataverseName(nameComponents.first);
407 cis.setDatasetName(nameComponents.second);
408 if (indexType != null) {
409 cis.setIndexType(indexType.type);
410 cis.setGramLength(indexType.gramLength);
411 }
412 return cis;
413 }
414}
415
salsubaiee0b423fa2013-09-19 19:16:48 -0700416String CompactionPolicy() throws ParseException :
417{
418 String compactionPolicy = null;
419}
420{
421 compactionPolicy = Identifier()
422 {
423 return compactionPolicy;
424 }
425}
426
Till Westmann31c21f92013-05-08 09:21:53 -0700427IndexParams IndexType() throws ParseException:
428{
429 IndexType type = null;
430 int gramLength = 0;
431}
432{
433 ("btree"
434 {
435 type = IndexType.BTREE;
436 }
437 | "rtree"
438 {
439 type = IndexType.RTREE;
440 }
441 | "keyword"
442 {
JIMAHNb75446d2013-06-03 08:35:27 -0700443 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700444 }
445 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
446 {
JIMAHNb75446d2013-06-03 08:35:27 -0700447 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700448 gramLength = Integer.valueOf(token.image);
449 }
450 <RIGHTPAREN>)
451 {
452 return new IndexParams(type, gramLength);
453 }
454}
455
456CreateDataverseStatement DataverseSpecification() throws ParseException :
457{
Till Westmann14a20a72013-05-09 00:06:24 -0700458 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700459 boolean ifNotExists = false;
460 String format = null;
461}
462{
Till Westmanna4242bc2013-05-08 17:49:55 -0700463 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700464 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700465 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700466 {
Till Westmann14a20a72013-05-09 00:06:24 -0700467 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700468 }
469}
470
471CreateFunctionStatement FunctionSpecification() throws ParseException:
472{
473 FunctionSignature signature;
474 boolean ifNotExists = false;
475 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
476 String functionBody;
Till Westmann31c21f92013-05-08 09:21:53 -0700477 Expression functionBodyExpr;
478 Token beginPos;
479 Token endPos;
480 Pair<Identifier,Identifier> nameComponents=null;
481
482 createNewScope();
483}
484{
485 "function" nameComponents = FunctionOrTypeName()
486 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700487 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700488 <LEFTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700489 {
490 beginPos = token;
491 }
Till Westmann96c1f172013-08-01 02:05:48 -0700492 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700493 {
494 endPos = token;
495 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
496 String dataverse = nameComponents.first.getValue();
497 String functionName = nameComponents.second.getValue();
498 signature = new FunctionSignature(dataverse, functionName, paramList.size());
499 getCurrentScope().addFunctionDescriptor(signature, false);
500 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
501 }
502}
503
504List<VarIdentifier> ParameterList() throws ParseException:
505{
506 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
507 VarIdentifier var = null;
508}
509{
Till Westmann31c21f92013-05-08 09:21:53 -0700510 <LEFTPAREN> (<VARIABLE>
511 {
512 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700513 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700514 paramList.add(var);
515 getCurrentScope().addNewVarSymbolToScope(var);
516 }
Till Westmann96c1f172013-08-01 02:05:48 -0700517 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700518 {
519 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700520 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700521 paramList.add(var);
522 getCurrentScope().addNewVarSymbolToScope(var);
523 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700524 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700525 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700526 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700527 }
528}
529
530boolean IfNotExists() throws ParseException:
531{
532}
533{
534 ( "if not exists"
535 {
536 return true;
537 }
538 )?
539 {
540 return false;
541 }
542}
543
544FunctionSignature ApplyFunction() throws ParseException:
545{
546 FunctionSignature funcSig = null;
547}
548{
549 "apply" "function" funcSig = FunctionSignature()
550 {
551 return funcSig;
552 }
553}
554
555FunctionSignature FunctionSignature() throws ParseException:
556{
557 Pair<Identifier,Identifier> pairId = null;
558 int arity = 0;
559}
560{
561 pairId = FunctionOrTypeName() "@" <INTEGER_LITERAL>
562 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700563 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700564 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
565 throw new ParseException(" invalid arity:" + arity);
566 }
567
568 String dataverse = pairId.first.getValue();
569 String functionName = pairId.second.getValue();
570 return new FunctionSignature(dataverse, functionName, arity);
571 }
572}
573
574List<String> PrimaryKey() throws ParseException:
575{
Till Westmann14a20a72013-05-09 00:06:24 -0700576 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700577 List<String> primaryKeyFields = new ArrayList<String>();
578}
579{
Till Westmann14a20a72013-05-09 00:06:24 -0700580 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700581 {
Till Westmann14a20a72013-05-09 00:06:24 -0700582 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700583 }
Till Westmann96c1f172013-08-01 02:05:48 -0700584 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700585 {
Till Westmann14a20a72013-05-09 00:06:24 -0700586 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700587 }
588 )*
589 {
590 return primaryKeyFields;
591 }
592}
593
594Statement DropStatement() throws ParseException:
595{
Till Westmann14a20a72013-05-09 00:06:24 -0700596 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700597 Pair<Identifier,Identifier> pairId = null;
598 Triple<Identifier,Identifier,Identifier> tripleId = null;
599 FunctionSignature funcSig = null;
600 boolean ifExists = false;
601 Statement stmt = null;
602}
603{
604 "drop"
605 (
606 <DATASET> pairId = QualifiedName() ifExists = IfExists()
607 {
608 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
609 }
610 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
611 {
612 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
613 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700614 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700615 {
Till Westmann14a20a72013-05-09 00:06:24 -0700616 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700617 }
618 | "type" pairId = FunctionOrTypeName() ifExists = IfExists()
619 {
620 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
621 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700622 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700623 {
Till Westmann14a20a72013-05-09 00:06:24 -0700624 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700625 }
626 | "function" funcSig = FunctionSignature() ifExists = IfExists()
627 {
628 stmt = new FunctionDropStatement(funcSig, ifExists);
629 }
630 )
631 {
632 return stmt;
633 }
634}
635
636boolean IfExists() throws ParseException :
637{
638}
639{
Till Westmann96c1f172013-08-01 02:05:48 -0700640 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700641 {
642 return true;
643 }
644 )?
645 {
646 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000647 }
648}
649
650InsertStatement InsertStatement() throws ParseException:
651{
Till Westmann31c21f92013-05-08 09:21:53 -0700652 Pair<Identifier,Identifier> nameComponents = null;
653 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000654}
655{
Till Westmann31c21f92013-05-08 09:21:53 -0700656 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
657 {
658 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
659 }
vinayakb38b7ca42012-03-05 05:44:15 +0000660}
661
662DeleteStatement DeleteStatement() throws ParseException:
663{
Till Westmann31c21f92013-05-08 09:21:53 -0700664 VariableExpr var = null;
665 Expression condition = null;
666 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000667}
668{
Till Westmann31c21f92013-05-08 09:21:53 -0700669 "delete" var = Variable()
670 {
671 getCurrentScope().addNewVarSymbolToScope(var.getVar());
672 }
673 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700674 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700675 {
676 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
677 }
vinayakb38b7ca42012-03-05 05:44:15 +0000678}
679
680UpdateStatement UpdateStatement() throws ParseException:
681{
Till Westmann31c21f92013-05-08 09:21:53 -0700682 VariableExpr vars;
683 Expression target;
684 Expression condition;
685 UpdateClause uc;
686 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000687}
688{
Till Westmann96c1f172013-08-01 02:05:48 -0700689 "update" vars = Variable() <IN> target = Expression()
690 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700691 <LEFTPAREN> (uc = UpdateClause()
692 {
693 ucs.add(uc);
694 }
Till Westmann96c1f172013-08-01 02:05:48 -0700695 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700696 {
697 ucs.add(uc);
698 }
699 )*) <RIGHTPAREN>
700 {
701 return new UpdateStatement(vars, target, condition, ucs);
702 }
vinayakb38b7ca42012-03-05 05:44:15 +0000703}
704
vinayakb38b7ca42012-03-05 05:44:15 +0000705UpdateClause UpdateClause() throws ParseException:
706{
Till Westmann31c21f92013-05-08 09:21:53 -0700707 Expression target = null;
708 Expression value = null ;
709 InsertStatement is = null;
710 DeleteStatement ds = null;
711 UpdateStatement us = null;
712 Expression condition = null;
713 UpdateClause ifbranch = null;
714 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000715}
716{
Till Westmann96c1f172013-08-01 02:05:48 -0700717 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700718 | is = InsertStatement()
719 | ds = DeleteStatement()
720 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700721 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
722 <THEN> ifbranch = UpdateClause()
723 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700724 {
725 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
726 }
vinayakb38b7ca42012-03-05 05:44:15 +0000727}
728
vinayakb38b7ca42012-03-05 05:44:15 +0000729Statement SetStatement() throws ParseException:
730{
731 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700732 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000733}
734{
Till Westmann7d535322013-05-09 00:40:02 -0700735 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700736 {
Till Westmann31c21f92013-05-08 09:21:53 -0700737 return new SetStatement(pn, pv);
738 }
vinayakb38b7ca42012-03-05 05:44:15 +0000739}
740
741Statement WriteStatement() throws ParseException:
742{
Till Westmann14a20a72013-05-09 00:06:24 -0700743 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000744 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000745 Query query;
746 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000747 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000748}
749{
Till Westmann96c1f172013-08-01 02:05:48 -0700750 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700751 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700752 {
753 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000754 }
755}
756
vinayakb38b7ca42012-03-05 05:44:15 +0000757LoadFromFileStatement LoadStatement() throws ParseException:
758{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000759 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000760 Identifier datasetName = null;
761 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000762 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000763 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000764 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000765}
766{
Till Westmann31c21f92013-05-08 09:21:53 -0700767 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000768 {
Till Westmann31c21f92013-05-08 09:21:53 -0700769 dataverseName = nameComponents.first;
770 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000771 }
Till Westmann31c21f92013-05-08 09:21:53 -0700772 "using" adapterName = AdapterName() properties = Configuration()
773 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000774 {
Till Westmann31c21f92013-05-08 09:21:53 -0700775 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000776 }
777 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700778 {
779 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
780 }
vinayakb38b7ca42012-03-05 05:44:15 +0000781}
782
vinayakb38b7ca42012-03-05 05:44:15 +0000783
Till Westmann31c21f92013-05-08 09:21:53 -0700784String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000785{
ramangrover29669d8f62013-02-11 06:03:32 +0000786 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000787}
788{
Till Westmann68d99652013-05-09 11:15:21 -0700789 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000790 {
Till Westmann7d535322013-05-09 00:40:02 -0700791 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000792 }
vinayakb38b7ca42012-03-05 05:44:15 +0000793}
794
salsubaiee0b423fa2013-09-19 19:16:48 -0700795Statement CompactStatement() throws ParseException:
796{
797 Pair<Identifier,Identifier> nameComponents = null;
798 Statement stmt = null;
799}
800{
801 "compact" <DATASET> nameComponents = QualifiedName()
802 {
803 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
804 }
805 {
806 return stmt;
807 }
808}
809
Till Westmann31c21f92013-05-08 09:21:53 -0700810Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000811{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000812 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700813 Map<String,String> configuration = null;
814 Statement stmt = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000815}
816{
Till Westmann31c21f92013-05-08 09:21:53 -0700817 (
818 "begin" "feed" nameComponents = QualifiedName()
819 {
820 stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter());
821 }
822 | "suspend" "feed" nameComponents = QualifiedName()
823 {
824 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second);
825 }
826 | "resume" "feed" nameComponents = QualifiedName()
827 {
828 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second);
829 }
830 | "end" "feed" nameComponents = QualifiedName()
831 {
832 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second);
833 }
834 | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration()
835 {
836 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
837 }
838 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000839 {
Till Westmann31c21f92013-05-08 09:21:53 -0700840 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000841 }
842}
843
Till Westmann31c21f92013-05-08 09:21:53 -0700844Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000845{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000846 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700847 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000848}
849{
Till Westmann31c21f92013-05-08 09:21:53 -0700850 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000851 {
Till Westmann31c21f92013-05-08 09:21:53 -0700852 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000853 }
Till Westmann96c1f172013-08-01 02:05:48 -0700854 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000855 {
Till Westmann31c21f92013-05-08 09:21:53 -0700856 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000857 }
Till Westmann31c21f92013-05-08 09:21:53 -0700858 )* )? <RIGHTPAREN>
859 {
860 return configuration;
861 }
862}
863
864Pair<String, String> KeyValuePair() throws ParseException:
865{
866 String key;
867 String value;
868}
869{
Till Westmann96c1f172013-08-01 02:05:48 -0700870 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700871 {
872 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000873 }
Till Westmann31c21f92013-05-08 09:21:53 -0700874}
875
876Map<String,String> Properties() throws ParseException:
877{
878 Map<String,String> properties = new HashMap<String,String>();
879 Pair<String, String> property;
880}
881{
882 ( <LEFTPAREN> property = Property()
883 {
884 properties.put(property.first, property.second);
885 }
Till Westmann96c1f172013-08-01 02:05:48 -0700886 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700887 {
888 properties.put(property.first, property.second);
889 }
890 )* <RIGHTPAREN> )?
891 {
892 return properties;
893 }
894}
895
896Pair<String, String> Property() throws ParseException:
897{
898 String key;
899 String value;
900}
901{
Till Westmann96c1f172013-08-01 02:05:48 -0700902 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700903 {
904 try {
905 value = "" + Long.valueOf(token.image);
906 } catch (NumberFormatException nfe) {
907 throw new ParseException("inapproriate value: " + token.image);
908 }
909 }
910 )
911 {
912 return new Pair<String, String>(key.toUpperCase(), value);
913 }
vinayakb38b7ca42012-03-05 05:44:15 +0000914}
915
916TypeExpression TypeExpr() throws ParseException:
917{
918 TypeExpression typeExpr = null;
919}
920{
921 (
922 typeExpr = RecordTypeDef()
923 | typeExpr = TypeReference()
924 | typeExpr = OrderedListTypeDef()
925 | typeExpr = UnorderedListTypeDef()
926 )
927 {
928 return typeExpr;
929 }
930}
931
932RecordTypeDefinition RecordTypeDef() throws ParseException:
933{
934 RecordTypeDefinition recType = new RecordTypeDefinition();
935 RecordTypeDefinition.RecordKind recordKind = null;
936}
937{
938 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
939 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700940 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000941 {
942 String hint = getHint(token);
943 if (hint != null) {
944 String splits[] = hint.split(" +");
945 if (splits[0].equals(GEN_FIELDS_HINT)) {
946 if (splits.length != 5) {
947 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
948 }
949 if (!splits[1].equals("int")) {
950 throw new ParseException("The only supported type for gen-fields is int.");
951 }
952 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
953 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
954 recType.setUndeclaredFieldsDataGen(ufdg);
955 }
956 }
957
958 }
959 (
960 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700961 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000962 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700963 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000964 {
965 if (recordKind == null) {
966 recordKind = RecordTypeDefinition.RecordKind.OPEN;
967 }
968 recType.setRecordKind(recordKind);
969 return recType;
970 }
971}
972
973void RecordField(RecordTypeDefinition recType) throws ParseException:
974{
Till Westmann77cb2f42013-07-15 16:44:19 -0700975 String fieldName;
976 TypeExpression type = null;
977 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000978}
979{
Till Westmann77cb2f42013-07-15 16:44:19 -0700980 fieldName = Identifier()
981 {
982 String hint = getHint(token);
983 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
984 }
Till Westmann96c1f172013-08-01 02:05:48 -0700985 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -0700986 {
987 recType.addField(fieldName, type, nullable, rfdg);
988 }
vinayakb38b7ca42012-03-05 05:44:15 +0000989}
990
991TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000992{
Till Westmann14a20a72013-05-09 00:06:24 -0700993 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700994}
995{
996 id = Identifier()
997 {
Till Westmann14a20a72013-05-09 00:06:24 -0700998 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700999 }
vinayakb38b7ca42012-03-05 05:44:15 +00001000}
1001
1002OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1003{
1004 TypeExpression type = null;
1005}
1006{
Till Westmann96c1f172013-08-01 02:05:48 -07001007 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001008 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001009 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001010 {
1011 return new OrderedListTypeDefinition(type);
1012 }
1013}
1014
1015
1016UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1017{
1018 TypeExpression type = null;
1019}
1020{
Till Westmann96c1f172013-08-01 02:05:48 -07001021 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001022 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001023 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001024 {
1025 return new UnorderedListTypeDefinition(type);
1026 }
1027}
1028
Till Westmann31c21f92013-05-08 09:21:53 -07001029
1030Pair<Identifier,Identifier> FunctionOrTypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001031{
Till Westmann31c21f92013-05-08 09:21:53 -07001032 Pair<Identifier,Identifier> name = null;
1033}
1034{
1035 name = QualifiedName()
1036 {
1037 if (name.first == null) {
1038 name.first = new Identifier(defaultDataverse);
1039 }
1040 return name;
1041 }
1042}
1043
Till Westmann14a20a72013-05-09 00:06:24 -07001044String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001045{
Till Westmann68d99652013-05-09 11:15:21 -07001046 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001047}
1048{
1049 <IDENTIFIER>
1050 {
Till Westmann14a20a72013-05-09 00:06:24 -07001051 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001052 }
Till Westmann68d99652013-05-09 11:15:21 -07001053 | lit = StringLiteral()
1054 {
1055 return lit;
1056 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001057}
1058
Till Westmann7d535322013-05-09 00:40:02 -07001059String StringLiteral() throws ParseException:
1060{
1061}
1062{
1063 <STRING_LITERAL>
1064 {
1065 return removeQuotesAndEscapes(token.image);
1066 }
1067}
1068
Till Westmann31c21f92013-05-08 09:21:53 -07001069Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1070{
Till Westmann14a20a72013-05-09 00:06:24 -07001071 String first = null;
1072 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001073}
1074{
Till Westmann96c1f172013-08-01 02:05:48 -07001075 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001076 {
Till Westmann14a20a72013-05-09 00:06:24 -07001077 Identifier id1 = null;
1078 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001079 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001080 id2 = new Identifier(first);
1081 } else
1082 {
1083 id1 = new Identifier(first);
1084 id2 = new Identifier(second);
1085 }
1086 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001087 }
1088}
1089
Till Westmann31c21f92013-05-08 09:21:53 -07001090Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001091{
Till Westmann14a20a72013-05-09 00:06:24 -07001092 String first = null;
1093 String second = null;
1094 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001095}
1096{
Till Westmann96c1f172013-08-01 02:05:48 -07001097 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001098 {
Till Westmann14a20a72013-05-09 00:06:24 -07001099 Identifier id1 = null;
1100 Identifier id2 = null;
1101 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001102 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001103 id2 = new Identifier(first);
1104 id3 = new Identifier(second);
1105 } else {
1106 id1 = new Identifier(first);
1107 id2 = new Identifier(second);
1108 id3 = new Identifier(third);
1109 }
1110 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001111 }
1112}
1113
vinayakb38b7ca42012-03-05 05:44:15 +00001114FunctionDecl FunctionDeclaration() throws ParseException:
1115{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001116 FunctionDecl funcDecl;
1117 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001118 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001119 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1120 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001121 createNewScope();
1122}
1123{
Till Westmannd7dcb122013-05-16 13:19:09 -07001124 "declare" "function" functionName = Identifier()
1125 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001126 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001127 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001128 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001129 getCurrentScope().addFunctionDescriptor(signature, false);
1130 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001131 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001132 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001133 }
1134}
1135
vinayakb38b7ca42012-03-05 05:44:15 +00001136
Till Westmann31c21f92013-05-08 09:21:53 -07001137Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001138{
1139 Query query = new Query();
1140 Expression expr;
1141}
1142{
Till Westmann31c21f92013-05-08 09:21:53 -07001143 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001144 {
1145 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001146 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001147 return query;
1148 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001149
vinayakb38b7ca42012-03-05 05:44:15 +00001150}
1151
1152
1153
1154Expression Expression():
1155{
1156 Expression expr = null;
1157 Expression exprP = null;
1158}
1159{
1160(
1161
1162//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1163 expr = OperatorExpr()
1164 | expr = IfThenElse()
1165 | expr = FLWOGR()
1166 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001167
vinayakb38b7ca42012-03-05 05:44:15 +00001168
1169)
1170 {
1171 return (exprP==null) ? expr : exprP;
1172 }
1173}
1174
1175
1176
1177Expression OperatorExpr()throws ParseException:
1178{
1179 OperatorExpr op = null;
1180 Expression operand = null;
1181}
1182{
1183 operand = AndExpr()
1184 (
1185
Till Westmann96c1f172013-08-01 02:05:48 -07001186 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001187 {
1188 if (op == null) {
1189 op = new OperatorExpr();
1190 op.addOperand(operand);
1191 op.setCurrentop(true);
1192 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001193 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001194 }
1195
1196 operand = AndExpr()
1197 {
1198 op.addOperand(operand);
1199 }
1200
1201 )*
1202
1203 {
1204 return op==null? operand: op;
1205 }
1206}
1207
1208Expression AndExpr()throws ParseException:
1209{
1210 OperatorExpr op = null;
1211 Expression operand = null;
1212}
1213{
1214 operand = RelExpr()
1215 (
1216
Till Westmann96c1f172013-08-01 02:05:48 -07001217 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001218 {
1219 if (op == null) {
1220 op = new OperatorExpr();
1221 op.addOperand(operand);
1222 op.setCurrentop(true);
1223 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001224 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001225 }
1226
1227 operand = RelExpr()
1228 {
1229 op.addOperand(operand);
1230 }
1231
1232 )*
1233
1234 {
1235 return op==null? operand: op;
1236 }
1237}
1238
1239
1240
1241Expression RelExpr()throws ParseException:
1242{
1243 OperatorExpr op = null;
1244 Expression operand = null;
1245 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001246 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001247}
1248{
1249 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001250 {
1251 if (operand instanceof VariableExpr) {
1252 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001253 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001254 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001255 }
1256 }
1257 }
1258
1259 (
Till Westmann96c1f172013-08-01 02:05:48 -07001260 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001261 {
alexander.behm07617fd2012-07-25 10:13:50 +00001262 String mhint = getHint(token);
1263 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1264 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1265 }
vinayakb38b7ca42012-03-05 05:44:15 +00001266 if (op == null) {
1267 op = new OperatorExpr();
1268 op.addOperand(operand, broadcast);
1269 op.setCurrentop(true);
1270 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001271 }
1272 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001273 }
1274
1275 operand = AddExpr()
1276 {
alexander.behm07617fd2012-07-25 10:13:50 +00001277 broadcast = false;
1278 if (operand instanceof VariableExpr) {
1279 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001280 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1281 broadcast = true;
1282 }
alexander.behm07617fd2012-07-25 10:13:50 +00001283 }
vinayakb38b7ca42012-03-05 05:44:15 +00001284 op.addOperand(operand, broadcast);
1285 }
1286 )?
1287
1288 {
alexander.behm07617fd2012-07-25 10:13:50 +00001289 if (annotation != null) {
1290 op.addHint(annotation);
1291 }
vinayakb38b7ca42012-03-05 05:44:15 +00001292 return op==null? operand: op;
1293 }
1294}
1295
1296Expression AddExpr()throws ParseException:
1297{
1298 OperatorExpr op = null;
1299 Expression operand = null;
1300}
1301{
1302 operand = MultExpr()
1303
Till Westmann96c1f172013-08-01 02:05:48 -07001304 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001305 {
1306 if (op == null) {
1307 op = new OperatorExpr();
1308 op.addOperand(operand);
1309 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001310 }
1311 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001312 }
1313
1314 operand = MultExpr()
1315 {
1316 op.addOperand(operand);
1317 }
1318 )*
1319
1320 {
1321 return op==null? operand: op;
1322 }
1323}
1324
1325Expression MultExpr()throws ParseException:
1326{
1327 OperatorExpr op = null;
1328 Expression operand = null;
1329}
1330{
1331 operand = UnionExpr()
1332
Till Westmann96c1f172013-08-01 02:05:48 -07001333 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001334 {
1335 if (op == null) {
1336 op = new OperatorExpr();
1337 op.addOperand(operand);
1338 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001339 }
1340 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001341 }
1342 operand = UnionExpr()
1343 {
1344 op.addOperand(operand);
1345 }
1346 )*
1347
1348 {
1349 return op==null?operand:op;
1350 }
1351}
1352
1353Expression UnionExpr() throws ParseException:
1354{
1355 UnionExpr union = null;
1356 Expression operand1 = null;
1357 Expression operand2 = null;
1358}
1359{
1360 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001361 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001362 (operand2 = UnaryExpr()) {
1363 if (union == null) {
1364 union = new UnionExpr();
1365 union.addExpr(operand1);
1366 }
1367 union.addExpr(operand2);
1368 } )*
1369 {
1370 return (union == null)? operand1: union;
1371 }
1372}
1373
1374Expression UnaryExpr() throws ParseException:
1375{
1376 Expression uexpr = null;
1377 Expression expr = null;
1378}
1379{
Till Westmann96c1f172013-08-01 02:05:48 -07001380 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001381 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001382 uexpr = new UnaryExpr();
1383 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001384 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001385 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001386 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1387 else
1388 throw new ParseException();
1389 }
1390 )?
1391
1392 expr = ValueExpr()
1393 {
1394 if(uexpr!=null){
1395 ((UnaryExpr)uexpr).setExpr(expr);
1396 return uexpr;
1397 }
1398 else{
1399 return expr;
1400 }
1401 }
1402}
1403
Till Westmann04478e72013-05-13 23:01:34 -07001404Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001405{
1406 Expression expr = null;
1407 Identifier ident = null;
1408 AbstractAccessor fa = null;
1409 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001410}
1411{
Till Westmann04478e72013-05-13 23:01:34 -07001412 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001413 {
Till Westmann04478e72013-05-13 23:01:34 -07001414 fa = (fa == null ? new FieldAccessor(expr, ident)
1415 : new FieldAccessor(fa, ident));
1416 }
1417 | index = Index()
1418 {
1419 fa = (fa == null ? new IndexAccessor(expr, index)
1420 : new IndexAccessor(fa, index));
1421 }
1422 )*
1423 {
1424 return fa == null ? expr : fa;
1425 }
vinayakb38b7ca42012-03-05 05:44:15 +00001426}
1427
1428Identifier Field() throws ParseException:
1429{
Till Westmann14a20a72013-05-09 00:06:24 -07001430 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001431}
1432{
Till Westmann96c1f172013-08-01 02:05:48 -07001433 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001434 {
Till Westmann14a20a72013-05-09 00:06:24 -07001435 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001436 }
vinayakb38b7ca42012-03-05 05:44:15 +00001437}
1438
1439int Index() throws ParseException:
1440{
1441 Expression expr = null;
1442 int idx = -2;
1443}
1444{
Till Westmann96c1f172013-08-01 02:05:48 -07001445 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001446 {
1447 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1448 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001449 Literal lit = ((LiteralExpr)expr).getValue();
1450 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1451 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001452 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001453 }
vinayakb38b7ca42012-03-05 05:44:15 +00001454 else {
1455 throw new ParseException("Index should be an INTEGER");
1456 }
1457 }
1458
1459 }
1460
Till Westmann96c1f172013-08-01 02:05:48 -07001461 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001462 {
1463 idx = IndexAccessor.ANY;
1464 // ANY
1465 }
1466
1467 )
1468
Till Westmann96c1f172013-08-01 02:05:48 -07001469 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001470 {
1471 return idx;
1472 }
1473}
1474
1475
1476Expression PrimaryExpr()throws ParseException:
1477{
1478 Expression expr = null;
1479}
1480{
Till Westmann68d99652013-05-09 11:15:21 -07001481 ( LOOKAHEAD(2)
1482 expr = FunctionCallExpr()
1483 | expr = Literal()
1484 | expr = DatasetAccessExpression()
1485 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001486 {
1487 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001488 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001489 }
Till Westmann68d99652013-05-09 11:15:21 -07001490 | expr = ListConstructor()
1491 | expr = RecordConstructor()
1492 | expr = ParenthesizedExpression()
1493 )
1494 {
1495 return expr;
1496 }
vinayakb38b7ca42012-03-05 05:44:15 +00001497}
1498
1499Expression Literal() throws ParseException:
1500{
vinayakb38b7ca42012-03-05 05:44:15 +00001501 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001502 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001503}
1504{
Till Westmann7d535322013-05-09 00:40:02 -07001505 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001506 {
Till Westmann7d535322013-05-09 00:40:02 -07001507 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001508 }
1509 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001510 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001511 try {
1512 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1513 } catch(NumberFormatException ex) {
1514 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1515 }
1516 }
1517 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001518 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001519 lit.setValue(new FloatLiteral(new Float(token.image)));
1520 }
1521 | <DOUBLE_LITERAL>
1522 {
1523 lit.setValue(new DoubleLiteral(new Double(token.image)));
1524 }
1525 | <NULL>
1526 {
1527 lit.setValue(NullLiteral.INSTANCE);
1528 }
1529 | <TRUE>
1530 {
1531 lit.setValue(TrueLiteral.INSTANCE);
1532 }
1533 | <FALSE>
1534 {
1535 lit.setValue(FalseLiteral.INSTANCE);
1536 }
1537 )
vinayakb38b7ca42012-03-05 05:44:15 +00001538 {
1539 return lit;
1540 }
1541}
1542
1543
1544VariableExpr VariableRef() throws ParseException:
1545{
1546 VariableExpr varExp = new VariableExpr();
1547 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001548}
1549{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001550 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001551 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001552 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001553 Identifier ident = lookupSymbol(varName);
1554 if (isInForbiddenScopes(varName)) {
1555 throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
1556 }
1557 if(ident != null) { // exist such ident
1558 varExp.setIsNewVar(false);
1559 varExp.setVar((VarIdentifier)ident);
1560 } else {
1561 varExp.setVar(var);
1562 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001563 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001564 return varExp;
1565 }
1566}
1567
1568
1569VariableExpr Variable() throws ParseException:
1570{
1571 VariableExpr varExp = new VariableExpr();
1572 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001573}
1574{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001575 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001576 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001577 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001578 if(ident != null) { // exist such ident
1579 varExp.setIsNewVar(false);
1580 }
1581 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001582 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001583 return varExp;
1584 }
1585}
1586
1587Expression ListConstructor() throws ParseException:
1588{
1589 Expression expr = null;
1590}
1591{
1592 (
1593 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1594 )
1595
1596 {
1597 return expr;
1598 }
1599}
1600
1601
1602ListConstructor OrderedListConstructor() throws ParseException:
1603{
1604 ListConstructor expr = new ListConstructor();
1605 Expression tmp = null;
1606 List<Expression> exprList = new ArrayList<Expression>();
1607 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1608}
1609{
1610
Till Westmann96c1f172013-08-01 02:05:48 -07001611 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001612 ( tmp = Expression()
1613 {
1614 exprList.add(tmp);
1615 }
1616
Till Westmann96c1f172013-08-01 02:05:48 -07001617 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001618 )?
1619
Till Westmann96c1f172013-08-01 02:05:48 -07001620 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001621
1622 {
1623 expr.setExprList(exprList);
1624 return expr;
1625 }
1626}
1627
1628ListConstructor UnorderedListConstructor() throws ParseException:
1629{
1630 ListConstructor expr = new ListConstructor();
1631 Expression tmp = null;
1632 List<Expression> exprList = new ArrayList<Expression>();
1633 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1634}
1635{
1636
Till Westmann96c1f172013-08-01 02:05:48 -07001637 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001638 {
1639 exprList.add(tmp);
1640 }
Till Westmann96c1f172013-08-01 02:05:48 -07001641 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001642 {
1643 expr.setExprList(exprList);
1644 return expr;
1645 }
1646}
1647
1648RecordConstructor RecordConstructor() throws ParseException:
1649{
1650 RecordConstructor expr = new RecordConstructor();
1651 FieldBinding tmp = null;
1652 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1653}
1654{
Till Westmann96c1f172013-08-01 02:05:48 -07001655 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001656 {
1657 fbList.add(tmp);
1658 }
Till Westmann96c1f172013-08-01 02:05:48 -07001659 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001660 {
1661 expr.setFbList(fbList);
1662 return expr;
1663 }
1664}
1665
1666FieldBinding FieldBinding() throws ParseException:
1667{
1668 FieldBinding fb = new FieldBinding();
1669 Expression left, right;
1670}
1671{
Till Westmann96c1f172013-08-01 02:05:48 -07001672 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001673 {
1674 fb.setLeftExpr(left);
1675 fb.setRightExpr(right);
1676 return fb;
1677 }
1678}
1679
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001680
vinayakb38b7ca42012-03-05 05:44:15 +00001681Expression FunctionCallExpr() throws ParseException:
1682{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001683 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001684 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001685 Expression tmp;
1686 int arity = 0;
Till Westmann31c21f92013-05-08 09:21:53 -07001687 Pair<Identifier,Identifier> funcId = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001688 String funcName;
1689 String dataverse;
Till Westmann31c21f92013-05-08 09:21:53 -07001690 String hint = null;
1691 String id1 = null;
1692 String id2 = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001693}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001694{
Till Westmann31c21f92013-05-08 09:21:53 -07001695 funcId = FunctionOrTypeName()
vinayakb38b7ca42012-03-05 05:44:15 +00001696 {
Till Westmann31c21f92013-05-08 09:21:53 -07001697 dataverse = funcId.first.getValue();
1698 funcName = funcId.second.getValue();
1699 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001700 }
Till Westmann31c21f92013-05-08 09:21:53 -07001701 <LEFTPAREN> (tmp = Expression()
1702 {
1703 argList.add(tmp);
1704 arity ++;
1705 }
Till Westmann96c1f172013-08-01 02:05:48 -07001706 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001707 {
1708 argList.add(tmp);
1709 arity++;
1710 }
1711 )*)? <RIGHTPAREN>
1712 {
1713 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
1714 if (signature == null) {
1715 signature = new FunctionSignature(dataverse, funcName, arity);
1716 }
1717 callExpr = new CallExpr(signature,argList);
1718 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1719 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1720 }
1721 return callExpr;
1722 }
vinayakb38b7ca42012-03-05 05:44:15 +00001723}
1724
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001725Expression DatasetAccessExpression() throws ParseException:
1726{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001727 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001728 String arg1 = null;
1729 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001730 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001731}
1732{
Till Westmann14a20a72013-05-09 00:06:24 -07001733 <DATASET>
1734 {
Till Westmann14a20a72013-05-09 00:06:24 -07001735 funcName = token.image;
1736 }
Till Westmann96c1f172013-08-01 02:05:48 -07001737 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001738 {
1739 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001740 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001741 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001742 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001743 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001744 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001745 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001746 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1747 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1748 if (signature == null) {
1749 signature = new FunctionSignature(dataverse, funcName, 1);
1750 }
1751 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001752 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001753 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001754 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001755}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001756
vinayakb38b7ca42012-03-05 05:44:15 +00001757Expression ParenthesizedExpression() throws ParseException:
1758{
1759 Expression expr;
1760}
1761{
1762 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1763 {
1764 return expr;
1765 }
1766}
1767
1768Expression IfThenElse() throws ParseException:
1769{
1770 Expression condExpr;
1771 Expression thenExpr;
1772 Expression elseExpr;
1773 IfExpr ifExpr = new IfExpr();
1774}
1775{
Till Westmann96c1f172013-08-01 02:05:48 -07001776 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001777
1778 {
1779 ifExpr.setCondExpr(condExpr);
1780 ifExpr.setThenExpr(thenExpr);
1781 ifExpr.setElseExpr(elseExpr);
1782 return ifExpr;
1783 }
1784}
1785
1786Expression FLWOGR() throws ParseException:
1787{
1788 FLWOGRExpression flworg = new FLWOGRExpression();
1789 List<Clause> clauseList = new ArrayList<Clause>();
1790 Expression returnExpr;
1791 Clause tmp;
1792 createNewScope();
1793}
1794{
1795 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001796 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001797
1798 {
1799 flworg.setClauseList(clauseList);
1800 flworg.setReturnExpr(returnExpr);
1801 removeCurrentScope();
1802 return flworg;
1803 }
1804}
1805
1806Clause Clause()throws ParseException :
1807{
1808 Clause clause;
1809}
1810{
1811 (
1812 clause = ForClause()
1813 | clause = LetClause()
1814 | clause = WhereClause()
1815 | clause = OrderbyClause()
1816 | clause = GroupClause()
1817 | clause = LimitClause()
1818 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001819 )
1820 {
1821 return clause;
1822 }
1823}
1824
1825Clause ForClause()throws ParseException :
1826{
1827 ForClause fc = new ForClause();
1828 VariableExpr varExp;
1829 VariableExpr varPos = null;
1830 Expression inExp;
1831 extendCurrentScope();
1832}
1833{
Till Westmann96c1f172013-08-01 02:05:48 -07001834 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001835 {
1836 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001837 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001838 fc.setInExpr(inExp);
1839 if (varPos != null) {
1840 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001841 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001842 }
1843 return fc;
1844 }
1845}
1846
1847Clause LetClause() throws ParseException:
1848{
1849 LetClause lc = new LetClause();
1850 VariableExpr varExp;
1851 Expression beExp;
1852 extendCurrentScope();
1853}
1854{
Till Westmann96c1f172013-08-01 02:05:48 -07001855 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001856 {
1857 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001858 lc.setVarExpr(varExp);
1859 lc.setBeExpr(beExp);
1860 return lc;
1861 }
1862}
1863
1864Clause WhereClause()throws ParseException :
1865{
1866 WhereClause wc = new WhereClause();
1867 Expression whereExpr;
1868}
1869{
Till Westmann96c1f172013-08-01 02:05:48 -07001870 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001871 {
1872 wc.setWhereExpr(whereExpr);
1873 return wc;
1874 }
1875}
1876
1877Clause OrderbyClause()throws ParseException :
1878{
1879 OrderbyClause oc = new OrderbyClause();
1880 Expression orderbyExpr;
1881 List<Expression> orderbyList = new ArrayList<Expression>();
1882 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1883 int numOfOrderby = 0;
1884}
1885{
1886 (
Till Westmann96c1f172013-08-01 02:05:48 -07001887 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001888 {
1889 String hint = getHint(token);
1890 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1891 String splits[] = hint.split(" +");
1892 int numFrames = Integer.parseInt(splits[1]);
1893 int numTuples = Integer.parseInt(splits[2]);
1894 oc.setNumFrames(numFrames);
1895 oc.setNumTuples(numTuples);
1896 }
1897 }
Till Westmann96c1f172013-08-01 02:05:48 -07001898 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001899 {
1900 orderbyList.add(orderbyExpr);
1901 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1902 }
Till Westmann96c1f172013-08-01 02:05:48 -07001903 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1904 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001905 {
1906 modifierList.add(modif);
1907 }
1908
Till Westmann96c1f172013-08-01 02:05:48 -07001909 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001910 {
1911 orderbyList.add(orderbyExpr);
1912 modif = OrderbyClause.OrderModifier.ASC;
1913 }
Till Westmann96c1f172013-08-01 02:05:48 -07001914 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1915 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001916 {
1917 modifierList.add(modif);
1918 }
1919 )*
1920)
1921 {
1922 oc.setModifierList(modifierList);
1923 oc.setOrderbyList(orderbyList);
1924 return oc;
1925 }
1926}
1927Clause GroupClause()throws ParseException :
1928{
1929 GroupbyClause gbc = new GroupbyClause();
1930 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1931 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1932 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1933 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1934 VariableExpr var = null;
1935 VariableExpr withVar = null;
1936 Expression expr = null;
1937 VariableExpr decorVar = null;
1938 Expression decorExpr = null;
1939}
1940{
1941 {
1942 Scope newScope = extendCurrentScopeNoPush(true);
1943 // extendCurrentScope(true);
1944 }
Till Westmann96c1f172013-08-01 02:05:48 -07001945 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00001946 {
1947 String hint = getHint(token);
1948 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1949 gbc.setHashGroupByHint(true);
1950 }
1951 }
Till Westmann96c1f172013-08-01 02:05:48 -07001952 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001953 {
1954 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001955 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001956 expr = Expression()
1957 {
1958 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1959 vePairList.add(pair1);
1960 }
Till Westmann96c1f172013-08-01 02:05:48 -07001961 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001962 {
1963 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001964 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001965 expr = Expression()
1966 {
1967 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1968 vePairList.add(pair2);
1969 }
1970 )*
Till Westmann96c1f172013-08-01 02:05:48 -07001971 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001972 {
1973 newScope.addNewVarSymbolToScope(decorVar.getVar());
1974 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1975 decorPairList.add(pair3);
1976 }
Till Westmann96c1f172013-08-01 02:05:48 -07001977 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001978 {
1979 newScope.addNewVarSymbolToScope(decorVar.getVar());
1980 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
1981 decorPairList.add(pair4);
1982 }
1983 )*
1984 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001985 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001986 {
1987 if(withVar.getIsNewVar()==true)
1988 throw new ParseException("can't find variable " + withVar.getVar());
1989 withVarList.add(withVar);
1990 newScope.addNewVarSymbolToScope(withVar.getVar());
1991 }
Till Westmann96c1f172013-08-01 02:05:48 -07001992 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001993 {
1994 if(withVar.getIsNewVar()==true)
1995 throw new ParseException("can't find variable " + withVar.getVar());
1996 withVarList.add(withVar);
1997 newScope.addNewVarSymbolToScope(withVar.getVar());
1998 })*
1999 {
2000 gbc.setGbyPairList(vePairList);
2001 gbc.setDecorPairList(decorPairList);
2002 gbc.setWithVarList(withVarList);
2003 replaceCurrentScope(newScope);
2004 return gbc;
2005 }
2006}
2007
2008
2009LimitClause LimitClause() throws ParseException:
2010{
2011 LimitClause lc = new LimitClause();
2012 Expression expr;
2013 pushForbiddenScope(getCurrentScope());
2014}
2015{
Till Westmann96c1f172013-08-01 02:05:48 -07002016 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2017 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002018
2019 {
2020 popForbiddenScope();
2021 return lc;
2022 }
2023}
2024
2025DistinctClause DistinctClause() throws ParseException:
2026{
2027 List<Expression> exprs = new ArrayList<Expression>();
2028 Expression expr;
2029}
2030{
Till Westmann96c1f172013-08-01 02:05:48 -07002031 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002032 {
2033 exprs.add(expr);
2034 }
Till Westmann96c1f172013-08-01 02:05:48 -07002035 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002036 {
2037 exprs.add(expr);
2038 }
2039 )*
2040 {
2041 return new DistinctClause(exprs);
2042 }
2043}
2044
vinayakb38b7ca42012-03-05 05:44:15 +00002045QuantifiedExpression QuantifiedExpression()throws ParseException:
2046{
2047 QuantifiedExpression qc = new QuantifiedExpression();
2048 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2049 Expression satisfiesExpr;
2050 VariableExpr var;
2051 Expression inExpr;
2052 QuantifiedPair pair;
2053}
2054{
2055 {
2056 createNewScope();
2057 }
2058
Till Westmann96c1f172013-08-01 02:05:48 -07002059 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2060 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2061 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002062 {
2063 pair = new QuantifiedPair(var, inExpr);
2064 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2065 quantifiedList.add(pair);
2066 }
2067 (
Till Westmann96c1f172013-08-01 02:05:48 -07002068 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002069 {
2070 pair = new QuantifiedPair(var, inExpr);
2071 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2072 quantifiedList.add(pair);
2073 }
2074 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002075 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002076 {
2077 qc.setSatisfiesExpr(satisfiesExpr);
2078 qc.setQuantifiedList(quantifiedList);
2079 removeCurrentScope();
2080 return qc;
2081 }
2082}
2083
2084TOKEN_MGR_DECLS:
2085{
Till Westmann96c1f172013-08-01 02:05:48 -07002086 public int commentDepth = 0;
2087 public IntStack lexerStateStack = new IntStack();
2088
2089 public void pushState() {
2090 lexerStateStack.push( curLexState );
2091 }
2092
2093 public void popState() {
2094 if (lexerStateStack.size() > 0) {
2095 SwitchTo( lexerStateStack.pop() );
2096 } else {
2097 throw new RuntimeException();
2098 }
2099 }
vinayakb38b7ca42012-03-05 05:44:15 +00002100}
2101
Till Westmann96c1f172013-08-01 02:05:48 -07002102<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002103TOKEN :
2104{
Till Westmann5df7b452013-08-02 13:07:16 -07002105 <ASC : "asc">
2106 | <AT : "at">
2107 | <BY : "by">
2108 | <DATASET : "dataset">
2109 | <DECOR : "decor">
2110 | <DESC : "desc">
2111 | <DISTINCT : "distinct">
2112 | <ELSE : "else">
2113 | <EVERY : "every">
2114 | <FOR : "for">
2115 | <GROUP : "group">
2116 | <IF : "if">
2117 | <IN : "in">
2118 | <LET : "let">
2119 | <LIMIT : "limit">
2120 | <OFFSET : "offset">
2121 | <ORDER : "order">
2122 | <RETURN : "return">
2123 | <SATISFIES : "satisfies">
2124 | <SOME : "some">
2125 | <THEN : "then">
2126 | <UNION : "union">
2127 | <WHERE : "where">
2128 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002129}
2130
Till Westmann96c1f172013-08-01 02:05:48 -07002131<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002132TOKEN :
2133{
Till Westmann5df7b452013-08-02 13:07:16 -07002134 <CARET : "^">
2135 | <DIV : "/">
2136 | <IDIV : "idiv">
2137 | <MINUS : "-">
2138 | <MOD : "%">
2139 | <MUL : "*">
2140 | <PLUS : "+">
2141
2142 | <LEFTPAREN : "(">
2143 | <RIGHTPAREN : ")">
2144 | <LEFTBRACKET : "[">
2145 | <RIGHTBRACKET : "]">
2146
2147 | <COLON : ":">
2148 | <COMMA : ",">
2149 | <DOT : ".">
2150 | <QUES : "?">
2151
2152 | <LT : "<">
2153 | <GT : ">">
2154 | <LE : "<=">
2155 | <GE : ">=">
2156 | <EQ : "=">
2157 | <NE : "!=">
2158 | <SIMILAR : "~=">
2159 | <ASSIGN : ":=">
2160
2161 | <AND : "and">
2162 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002163}
2164
Till Westmann96c1f172013-08-01 02:05:48 -07002165<DEFAULT,IN_DBL_BRACE>
2166TOKEN :
2167{
Till Westmann5df7b452013-08-02 13:07:16 -07002168 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
Till Westmann96c1f172013-08-01 02:05:48 -07002169}
vinayakb38b7ca42012-03-05 05:44:15 +00002170
2171<DEFAULT>
2172TOKEN :
2173{
Till Westmann5df7b452013-08-02 13:07:16 -07002174 <RIGHTBRACE : "}"> { popState(); }
Till Westmann96c1f172013-08-01 02:05:48 -07002175}
2176
2177<DEFAULT,IN_DBL_BRACE>
2178TOKEN :
2179{
Till Westmann5df7b452013-08-02 13:07:16 -07002180 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
Till Westmann96c1f172013-08-01 02:05:48 -07002181}
2182
2183<IN_DBL_BRACE>
2184TOKEN :
2185{
Till Westmann5df7b452013-08-02 13:07:16 -07002186 <RIGHTDBLBRACE : "}}"> { popState(); }
Till Westmann96c1f172013-08-01 02:05:48 -07002187}
2188
2189<DEFAULT,IN_DBL_BRACE>
2190TOKEN :
2191{
Till Westmann5df7b452013-08-02 13:07:16 -07002192 <INTEGER_LITERAL : (<DIGIT>)+ >
Till Westmann96c1f172013-08-01 02:05:48 -07002193}
2194
2195<DEFAULT,IN_DBL_BRACE>
2196TOKEN :
2197{
Till Westmann5df7b452013-08-02 13:07:16 -07002198 <NULL : "null">
2199 | <TRUE : "true">
2200 | <FALSE : "false">
Till Westmann96c1f172013-08-01 02:05:48 -07002201}
2202
2203<DEFAULT,IN_DBL_BRACE>
2204TOKEN :
2205{
Till Westmann5df7b452013-08-02 13:07:16 -07002206 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002207}
2208
Till Westmann96c1f172013-08-01 02:05:48 -07002209<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002210TOKEN:
2211{
Till Westmann5df7b452013-08-02 13:07:16 -07002212 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002213 | <DIGITS> ( "." <DIGITS> )?
2214 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002215 >
2216 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002217 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2218 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002219 >
2220 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222
Till Westmann96c1f172013-08-01 02:05:48 -07002223<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002224TOKEN :
2225{
Till Westmann5df7b452013-08-02 13:07:16 -07002226 <#LETTER : ["A" - "Z", "a" - "z"]>
2227 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002228}
2229
Till Westmann96c1f172013-08-01 02:05:48 -07002230<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002231TOKEN :
2232{
Till Westmann5df7b452013-08-02 13:07:16 -07002233 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2234 | < #EscapeQuot: "\\\"" >
2235 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002236}
2237
Till Westmann96c1f172013-08-01 02:05:48 -07002238<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002239TOKEN :
2240{
Till Westmann5df7b452013-08-02 13:07:16 -07002241 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002242}
2243
Till Westmann96c1f172013-08-01 02:05:48 -07002244<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002245TOKEN :
2246{
Till Westmann5df7b452013-08-02 13:07:16 -07002247 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002248}
2249
Till Westmann96c1f172013-08-01 02:05:48 -07002250<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002251SKIP:
2252{
2253 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002254 | "\t"
2255 | "\r"
2256 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002257}
2258
Till Westmann96c1f172013-08-01 02:05:48 -07002259<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002260SKIP:
2261{
Till Westmann5df7b452013-08-02 13:07:16 -07002262 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002263}
2264
Till Westmann96c1f172013-08-01 02:05:48 -07002265<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002266SKIP:
2267{
Till Westmann5df7b452013-08-02 13:07:16 -07002268 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002269}
2270
Till Westmann96c1f172013-08-01 02:05:48 -07002271<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002272SKIP:
2273{
Till Westmann96c1f172013-08-01 02:05:48 -07002274 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002275}
2276
2277<INSIDE_COMMENT>
2278SPECIAL_TOKEN:
2279{
Till Westmann5df7b452013-08-02 13:07:16 -07002280 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002281}
2282
2283<INSIDE_COMMENT>
2284SKIP:
2285{
Till Westmann96c1f172013-08-01 02:05:48 -07002286 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002287}
2288
2289<INSIDE_COMMENT>
2290SKIP:
2291{
Till Westmann96c1f172013-08-01 02:05:48 -07002292 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002293 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002294}