blob: f7b5f7509eda463bb7f9102e2e52e6d940dbebbb [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()
196 | stmt = Query()
197 )
198 {
199 return stmt;
200 }
201}
202
203DataverseDecl DataverseDeclaration() throws ParseException:
204{
Till Westmann14a20a72013-05-09 00:06:24 -0700205 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700206}
207{
Till Westmanna4242bc2013-05-08 17:49:55 -0700208 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700209 {
Till Westmann14a20a72013-05-09 00:06:24 -0700210 defaultDataverse = dvName;
211 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700212 }
213}
214
215Statement CreateStatement() throws ParseException:
216{
217 String hint = null;
218 boolean dgen = false;
219 Statement stmt = null;
220}
221{
222 "create"
223 (
224 {
225 hint = getHint(token);
226 if (hint != null && hint.startsWith(DGEN_HINT)) {
227 dgen = true;
228 }
229 }
230 stmt = TypeSpecification(hint, dgen)
231 | stmt = NodegroupSpecification()
232 | stmt = DatasetSpecification()
233 | stmt = IndexSpecification()
234 | stmt = DataverseSpecification()
235 | stmt = FunctionSpecification()
236 )
237 {
238 return stmt;
239 }
240}
241
242TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
243{
244 Pair<Identifier,Identifier> nameComponents = null;
245 boolean ifNotExists = false;
246 TypeExpression typeExpr = null;
247}
248{
249 "type" nameComponents = FunctionOrTypeName() ifNotExists = IfNotExists()
250 "as" typeExpr = TypeExpr()
251 {
252 long numValues = -1;
253 String filename = null;
254 if (dgen) {
255 String splits[] = hint.split(" +");
256 if (splits.length != 3) {
257 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
258 }
259 filename = splits[1];
260 numValues = Long.parseLong(splits[2]);
261 }
262 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
263 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
264 }
265}
266
267
268NodegroupDecl NodegroupSpecification() throws ParseException:
269{
Till Westmann14a20a72013-05-09 00:06:24 -0700270 String name = null;
271 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700272 boolean ifNotExists = false;
273 List<Identifier>ncNames = null;
274}
275{
Till Westmanna4242bc2013-05-08 17:49:55 -0700276 "nodegroup" name = Identifier()
277 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700278 {
279 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700280 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700281 }
Till Westmann96c1f172013-08-01 02:05:48 -0700282 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700283 {
Till Westmann14a20a72013-05-09 00:06:24 -0700284 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700285 }
286 )*
287 {
Till Westmann14a20a72013-05-09 00:06:24 -0700288 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700289 }
290}
291
292DatasetDecl DatasetSpecification() throws ParseException:
293{
294 Pair<Identifier,Identifier> nameComponents = null;
295 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700296 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700297 String adapterName = null;
298 Map<String,String> properties = null;
299 FunctionSignature appliedFunction = null;
300 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700301 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700302 Map<String,String> hints = new HashMap<String,String>();
303 DatasetDecl dsetDecl = null;
304}
305{
306 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700307 "external" <DATASET> nameComponents = QualifiedName()
308 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
309 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700310 "using" adapterName = AdapterName() properties = Configuration()
311 ( "hints" hints = Properties() )?
312 {
313 ExternalDetailsDecl edd = new ExternalDetailsDecl();
314 edd.setAdapter(adapterName);
315 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700316 dsetDecl = new DatasetDecl(nameComponents.first,
317 nameComponents.second,
318 new Identifier(typeName),
319 hints,
320 DatasetType.EXTERNAL,
321 edd,
322 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700323 }
324
Till Westmanna4242bc2013-05-08 17:49:55 -0700325 | "feed" <DATASET> nameComponents = QualifiedName()
326 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
327 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700328 "using" adapterName = AdapterName() properties = Configuration()
329 (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey()
Till Westmanna4242bc2013-05-08 17:49:55 -0700330 ( "on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700331 ( "hints" hints = Properties() )?
332 {
Till Westmann14a20a72013-05-09 00:06:24 -0700333 FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName,
334 properties,
335 appliedFunction,
336 nodeGroupName != null
337 ? new Identifier(nodeGroupName)
338 : null,
339 primaryKeyFields);
340 dsetDecl = new DatasetDecl(nameComponents.first,
341 nameComponents.second,
342 new Identifier(typeName),
343 hints,
344 DatasetType.FEED,
345 fdd,
346 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700347 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700348 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700349 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
350 ifNotExists = IfNotExists()
351 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700352 ( "hints" hints = Properties() )?
353 {
Till Westmann14a20a72013-05-09 00:06:24 -0700354 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
355 ? new Identifier(nodeGroupName)
356 : null,
357 primaryKeyFields);
358 dsetDecl = new DatasetDecl(nameComponents.first,
359 nameComponents.second,
360 new Identifier(typeName),
361 hints,
362 DatasetType.INTERNAL,
363 idd,
364 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700365 }
366 )
367 {
368 return dsetDecl;
369 }
370}
371
372CreateIndexStatement IndexSpecification() throws ParseException:
373{
374 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700375 String indexName = null;
376 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700377 boolean ifNotExists = false;
378 Pair<Identifier,Identifier> nameComponents = null;
379 IndexParams indexType = null;
380}
381{
Till Westmanna4242bc2013-05-08 17:49:55 -0700382 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700383 ifNotExists = IfNotExists()
384 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700385 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700386 {
Till Westmann14a20a72013-05-09 00:06:24 -0700387 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700388 }
Till Westmann96c1f172013-08-01 02:05:48 -0700389 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700390 {
Till Westmann14a20a72013-05-09 00:06:24 -0700391 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700392 }
393 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
394 {
Till Westmann14a20a72013-05-09 00:06:24 -0700395 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700396 cis.setIfNotExists(ifNotExists);
397 cis.setDataverseName(nameComponents.first);
398 cis.setDatasetName(nameComponents.second);
399 if (indexType != null) {
400 cis.setIndexType(indexType.type);
401 cis.setGramLength(indexType.gramLength);
402 }
403 return cis;
404 }
405}
406
407IndexParams IndexType() throws ParseException:
408{
409 IndexType type = null;
410 int gramLength = 0;
411}
412{
413 ("btree"
414 {
415 type = IndexType.BTREE;
416 }
417 | "rtree"
418 {
419 type = IndexType.RTREE;
420 }
421 | "keyword"
422 {
JIMAHNb75446d2013-06-03 08:35:27 -0700423 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700424 }
425 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
426 {
JIMAHNb75446d2013-06-03 08:35:27 -0700427 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700428 gramLength = Integer.valueOf(token.image);
429 }
430 <RIGHTPAREN>)
431 {
432 return new IndexParams(type, gramLength);
433 }
434}
435
436CreateDataverseStatement DataverseSpecification() throws ParseException :
437{
Till Westmann14a20a72013-05-09 00:06:24 -0700438 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700439 boolean ifNotExists = false;
440 String format = null;
441}
442{
Till Westmanna4242bc2013-05-08 17:49:55 -0700443 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700444 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700445 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700446 {
Till Westmann14a20a72013-05-09 00:06:24 -0700447 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700448 }
449}
450
451CreateFunctionStatement FunctionSpecification() throws ParseException:
452{
453 FunctionSignature signature;
454 boolean ifNotExists = false;
455 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
456 String functionBody;
Till Westmann31c21f92013-05-08 09:21:53 -0700457 Expression functionBodyExpr;
458 Token beginPos;
459 Token endPos;
460 Pair<Identifier,Identifier> nameComponents=null;
461
462 createNewScope();
463}
464{
465 "function" nameComponents = FunctionOrTypeName()
466 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700467 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700468 <LEFTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700469 {
470 beginPos = token;
471 }
Till Westmann96c1f172013-08-01 02:05:48 -0700472 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700473 {
474 endPos = token;
475 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
476 String dataverse = nameComponents.first.getValue();
477 String functionName = nameComponents.second.getValue();
478 signature = new FunctionSignature(dataverse, functionName, paramList.size());
479 getCurrentScope().addFunctionDescriptor(signature, false);
480 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
481 }
482}
483
484List<VarIdentifier> ParameterList() throws ParseException:
485{
486 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
487 VarIdentifier var = null;
488}
489{
Till Westmann31c21f92013-05-08 09:21:53 -0700490 <LEFTPAREN> (<VARIABLE>
491 {
492 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700493 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700494 paramList.add(var);
495 getCurrentScope().addNewVarSymbolToScope(var);
496 }
Till Westmann96c1f172013-08-01 02:05:48 -0700497 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700498 {
499 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700500 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700501 paramList.add(var);
502 getCurrentScope().addNewVarSymbolToScope(var);
503 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700504 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700505 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700506 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700507 }
508}
509
510boolean IfNotExists() throws ParseException:
511{
512}
513{
514 ( "if not exists"
515 {
516 return true;
517 }
518 )?
519 {
520 return false;
521 }
522}
523
524FunctionSignature ApplyFunction() throws ParseException:
525{
526 FunctionSignature funcSig = null;
527}
528{
529 "apply" "function" funcSig = FunctionSignature()
530 {
531 return funcSig;
532 }
533}
534
535FunctionSignature FunctionSignature() throws ParseException:
536{
537 Pair<Identifier,Identifier> pairId = null;
538 int arity = 0;
539}
540{
541 pairId = FunctionOrTypeName() "@" <INTEGER_LITERAL>
542 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700543 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700544 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
545 throw new ParseException(" invalid arity:" + arity);
546 }
547
548 String dataverse = pairId.first.getValue();
549 String functionName = pairId.second.getValue();
550 return new FunctionSignature(dataverse, functionName, arity);
551 }
552}
553
554List<String> PrimaryKey() throws ParseException:
555{
Till Westmann14a20a72013-05-09 00:06:24 -0700556 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700557 List<String> primaryKeyFields = new ArrayList<String>();
558}
559{
Till Westmann14a20a72013-05-09 00:06:24 -0700560 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700561 {
Till Westmann14a20a72013-05-09 00:06:24 -0700562 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700563 }
Till Westmann96c1f172013-08-01 02:05:48 -0700564 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700565 {
Till Westmann14a20a72013-05-09 00:06:24 -0700566 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700567 }
568 )*
569 {
570 return primaryKeyFields;
571 }
572}
573
574Statement DropStatement() throws ParseException:
575{
Till Westmann14a20a72013-05-09 00:06:24 -0700576 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700577 Pair<Identifier,Identifier> pairId = null;
578 Triple<Identifier,Identifier,Identifier> tripleId = null;
579 FunctionSignature funcSig = null;
580 boolean ifExists = false;
581 Statement stmt = null;
582}
583{
584 "drop"
585 (
586 <DATASET> pairId = QualifiedName() ifExists = IfExists()
587 {
588 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
589 }
590 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
591 {
592 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
593 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700594 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700595 {
Till Westmann14a20a72013-05-09 00:06:24 -0700596 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700597 }
598 | "type" pairId = FunctionOrTypeName() ifExists = IfExists()
599 {
600 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
601 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700602 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700603 {
Till Westmann14a20a72013-05-09 00:06:24 -0700604 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700605 }
606 | "function" funcSig = FunctionSignature() ifExists = IfExists()
607 {
608 stmt = new FunctionDropStatement(funcSig, ifExists);
609 }
610 )
611 {
612 return stmt;
613 }
614}
615
616boolean IfExists() throws ParseException :
617{
618}
619{
Till Westmann96c1f172013-08-01 02:05:48 -0700620 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700621 {
622 return true;
623 }
624 )?
625 {
626 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000627 }
628}
629
630InsertStatement InsertStatement() throws ParseException:
631{
Till Westmann31c21f92013-05-08 09:21:53 -0700632 Pair<Identifier,Identifier> nameComponents = null;
633 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000634}
635{
Till Westmann31c21f92013-05-08 09:21:53 -0700636 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
637 {
638 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
639 }
vinayakb38b7ca42012-03-05 05:44:15 +0000640}
641
642DeleteStatement DeleteStatement() throws ParseException:
643{
Till Westmann31c21f92013-05-08 09:21:53 -0700644 VariableExpr var = null;
645 Expression condition = null;
646 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000647}
648{
Till Westmann31c21f92013-05-08 09:21:53 -0700649 "delete" var = Variable()
650 {
651 getCurrentScope().addNewVarSymbolToScope(var.getVar());
652 }
653 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700654 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700655 {
656 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
657 }
vinayakb38b7ca42012-03-05 05:44:15 +0000658}
659
660UpdateStatement UpdateStatement() throws ParseException:
661{
Till Westmann31c21f92013-05-08 09:21:53 -0700662 VariableExpr vars;
663 Expression target;
664 Expression condition;
665 UpdateClause uc;
666 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000667}
668{
Till Westmann96c1f172013-08-01 02:05:48 -0700669 "update" vars = Variable() <IN> target = Expression()
670 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700671 <LEFTPAREN> (uc = UpdateClause()
672 {
673 ucs.add(uc);
674 }
Till Westmann96c1f172013-08-01 02:05:48 -0700675 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700676 {
677 ucs.add(uc);
678 }
679 )*) <RIGHTPAREN>
680 {
681 return new UpdateStatement(vars, target, condition, ucs);
682 }
vinayakb38b7ca42012-03-05 05:44:15 +0000683}
684
vinayakb38b7ca42012-03-05 05:44:15 +0000685UpdateClause UpdateClause() throws ParseException:
686{
Till Westmann31c21f92013-05-08 09:21:53 -0700687 Expression target = null;
688 Expression value = null ;
689 InsertStatement is = null;
690 DeleteStatement ds = null;
691 UpdateStatement us = null;
692 Expression condition = null;
693 UpdateClause ifbranch = null;
694 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000695}
696{
Till Westmann96c1f172013-08-01 02:05:48 -0700697 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700698 | is = InsertStatement()
699 | ds = DeleteStatement()
700 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700701 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
702 <THEN> ifbranch = UpdateClause()
703 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700704 {
705 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
706 }
vinayakb38b7ca42012-03-05 05:44:15 +0000707}
708
vinayakb38b7ca42012-03-05 05:44:15 +0000709Statement SetStatement() throws ParseException:
710{
711 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700712 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000713}
714{
Till Westmann7d535322013-05-09 00:40:02 -0700715 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700716 {
Till Westmann31c21f92013-05-08 09:21:53 -0700717 return new SetStatement(pn, pv);
718 }
vinayakb38b7ca42012-03-05 05:44:15 +0000719}
720
721Statement WriteStatement() throws ParseException:
722{
Till Westmann14a20a72013-05-09 00:06:24 -0700723 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000724 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000725 Query query;
726 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000727 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000728}
729{
Till Westmann96c1f172013-08-01 02:05:48 -0700730 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700731 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700732 {
733 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000734 }
735}
736
vinayakb38b7ca42012-03-05 05:44:15 +0000737LoadFromFileStatement LoadStatement() throws ParseException:
738{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000739 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000740 Identifier datasetName = null;
741 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000742 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000743 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000744 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000745}
746{
Till Westmann31c21f92013-05-08 09:21:53 -0700747 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000748 {
Till Westmann31c21f92013-05-08 09:21:53 -0700749 dataverseName = nameComponents.first;
750 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000751 }
Till Westmann31c21f92013-05-08 09:21:53 -0700752 "using" adapterName = AdapterName() properties = Configuration()
753 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000754 {
Till Westmann31c21f92013-05-08 09:21:53 -0700755 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000756 }
757 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700758 {
759 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
760 }
vinayakb38b7ca42012-03-05 05:44:15 +0000761}
762
vinayakb38b7ca42012-03-05 05:44:15 +0000763
Till Westmann31c21f92013-05-08 09:21:53 -0700764String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000765{
ramangrover29669d8f62013-02-11 06:03:32 +0000766 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000767}
768{
Till Westmann68d99652013-05-09 11:15:21 -0700769 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000770 {
Till Westmann7d535322013-05-09 00:40:02 -0700771 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000772 }
vinayakb38b7ca42012-03-05 05:44:15 +0000773}
774
Till Westmann31c21f92013-05-08 09:21:53 -0700775Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000776{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000777 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700778 Map<String,String> configuration = null;
779 Statement stmt = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000780}
781{
Till Westmann31c21f92013-05-08 09:21:53 -0700782 (
783 "begin" "feed" nameComponents = QualifiedName()
784 {
785 stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter());
786 }
787 | "suspend" "feed" nameComponents = QualifiedName()
788 {
789 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second);
790 }
791 | "resume" "feed" nameComponents = QualifiedName()
792 {
793 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second);
794 }
795 | "end" "feed" nameComponents = QualifiedName()
796 {
797 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second);
798 }
799 | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration()
800 {
801 stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration);
802 }
803 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000804 {
Till Westmann31c21f92013-05-08 09:21:53 -0700805 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000806 }
807}
808
Till Westmann31c21f92013-05-08 09:21:53 -0700809Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000810{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000811 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700812 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000813}
814{
Till Westmann31c21f92013-05-08 09:21:53 -0700815 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000816 {
Till Westmann31c21f92013-05-08 09:21:53 -0700817 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000818 }
Till Westmann96c1f172013-08-01 02:05:48 -0700819 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000820 {
Till Westmann31c21f92013-05-08 09:21:53 -0700821 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000822 }
Till Westmann31c21f92013-05-08 09:21:53 -0700823 )* )? <RIGHTPAREN>
824 {
825 return configuration;
826 }
827}
828
829Pair<String, String> KeyValuePair() throws ParseException:
830{
831 String key;
832 String value;
833}
834{
Till Westmann96c1f172013-08-01 02:05:48 -0700835 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700836 {
837 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000838 }
Till Westmann31c21f92013-05-08 09:21:53 -0700839}
840
841Map<String,String> Properties() throws ParseException:
842{
843 Map<String,String> properties = new HashMap<String,String>();
844 Pair<String, String> property;
845}
846{
847 ( <LEFTPAREN> property = Property()
848 {
849 properties.put(property.first, property.second);
850 }
Till Westmann96c1f172013-08-01 02:05:48 -0700851 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700852 {
853 properties.put(property.first, property.second);
854 }
855 )* <RIGHTPAREN> )?
856 {
857 return properties;
858 }
859}
860
861Pair<String, String> Property() throws ParseException:
862{
863 String key;
864 String value;
865}
866{
Till Westmann96c1f172013-08-01 02:05:48 -0700867 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700868 {
869 try {
870 value = "" + Long.valueOf(token.image);
871 } catch (NumberFormatException nfe) {
872 throw new ParseException("inapproriate value: " + token.image);
873 }
874 }
875 )
876 {
877 return new Pair<String, String>(key.toUpperCase(), value);
878 }
vinayakb38b7ca42012-03-05 05:44:15 +0000879}
880
881TypeExpression TypeExpr() throws ParseException:
882{
883 TypeExpression typeExpr = null;
884}
885{
886 (
887 typeExpr = RecordTypeDef()
888 | typeExpr = TypeReference()
889 | typeExpr = OrderedListTypeDef()
890 | typeExpr = UnorderedListTypeDef()
891 )
892 {
893 return typeExpr;
894 }
895}
896
897RecordTypeDefinition RecordTypeDef() throws ParseException:
898{
899 RecordTypeDefinition recType = new RecordTypeDefinition();
900 RecordTypeDefinition.RecordKind recordKind = null;
901}
902{
903 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
904 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700905 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000906 {
907 String hint = getHint(token);
908 if (hint != null) {
909 String splits[] = hint.split(" +");
910 if (splits[0].equals(GEN_FIELDS_HINT)) {
911 if (splits.length != 5) {
912 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
913 }
914 if (!splits[1].equals("int")) {
915 throw new ParseException("The only supported type for gen-fields is int.");
916 }
917 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
918 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
919 recType.setUndeclaredFieldsDataGen(ufdg);
920 }
921 }
922
923 }
924 (
925 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700926 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000927 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700928 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000929 {
930 if (recordKind == null) {
931 recordKind = RecordTypeDefinition.RecordKind.OPEN;
932 }
933 recType.setRecordKind(recordKind);
934 return recType;
935 }
936}
937
938void RecordField(RecordTypeDefinition recType) throws ParseException:
939{
Till Westmann77cb2f42013-07-15 16:44:19 -0700940 String fieldName;
941 TypeExpression type = null;
942 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000943}
944{
Till Westmann77cb2f42013-07-15 16:44:19 -0700945 fieldName = Identifier()
946 {
947 String hint = getHint(token);
948 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
949 }
Till Westmann96c1f172013-08-01 02:05:48 -0700950 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -0700951 {
952 recType.addField(fieldName, type, nullable, rfdg);
953 }
vinayakb38b7ca42012-03-05 05:44:15 +0000954}
955
956TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000957{
Till Westmann14a20a72013-05-09 00:06:24 -0700958 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700959}
960{
961 id = Identifier()
962 {
Till Westmann14a20a72013-05-09 00:06:24 -0700963 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700964 }
vinayakb38b7ca42012-03-05 05:44:15 +0000965}
966
967OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
968{
969 TypeExpression type = null;
970}
971{
Till Westmann96c1f172013-08-01 02:05:48 -0700972 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000973 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -0700974 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000975 {
976 return new OrderedListTypeDefinition(type);
977 }
978}
979
980
981UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
982{
983 TypeExpression type = null;
984}
985{
Till Westmann96c1f172013-08-01 02:05:48 -0700986 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000987 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -0700988 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000989 {
990 return new UnorderedListTypeDefinition(type);
991 }
992}
993
Till Westmann31c21f92013-05-08 09:21:53 -0700994
995Pair<Identifier,Identifier> FunctionOrTypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000996{
Till Westmann31c21f92013-05-08 09:21:53 -0700997 Pair<Identifier,Identifier> name = null;
998}
999{
1000 name = QualifiedName()
1001 {
1002 if (name.first == null) {
1003 name.first = new Identifier(defaultDataverse);
1004 }
1005 return name;
1006 }
1007}
1008
Till Westmann14a20a72013-05-09 00:06:24 -07001009String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001010{
Till Westmann68d99652013-05-09 11:15:21 -07001011 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001012}
1013{
1014 <IDENTIFIER>
1015 {
Till Westmann14a20a72013-05-09 00:06:24 -07001016 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001017 }
Till Westmann68d99652013-05-09 11:15:21 -07001018 | lit = StringLiteral()
1019 {
1020 return lit;
1021 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001022}
1023
Till Westmann7d535322013-05-09 00:40:02 -07001024String StringLiteral() throws ParseException:
1025{
1026}
1027{
1028 <STRING_LITERAL>
1029 {
1030 return removeQuotesAndEscapes(token.image);
1031 }
1032}
1033
Till Westmann31c21f92013-05-08 09:21:53 -07001034Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1035{
Till Westmann14a20a72013-05-09 00:06:24 -07001036 String first = null;
1037 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001038}
1039{
Till Westmann96c1f172013-08-01 02:05:48 -07001040 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001041 {
Till Westmann14a20a72013-05-09 00:06:24 -07001042 Identifier id1 = null;
1043 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001044 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001045 id2 = new Identifier(first);
1046 } else
1047 {
1048 id1 = new Identifier(first);
1049 id2 = new Identifier(second);
1050 }
1051 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001052 }
1053}
1054
Till Westmann31c21f92013-05-08 09:21:53 -07001055Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001056{
Till Westmann14a20a72013-05-09 00:06:24 -07001057 String first = null;
1058 String second = null;
1059 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001060}
1061{
Till Westmann96c1f172013-08-01 02:05:48 -07001062 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001063 {
Till Westmann14a20a72013-05-09 00:06:24 -07001064 Identifier id1 = null;
1065 Identifier id2 = null;
1066 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001067 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001068 id2 = new Identifier(first);
1069 id3 = new Identifier(second);
1070 } else {
1071 id1 = new Identifier(first);
1072 id2 = new Identifier(second);
1073 id3 = new Identifier(third);
1074 }
1075 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001076 }
1077}
1078
vinayakb38b7ca42012-03-05 05:44:15 +00001079FunctionDecl FunctionDeclaration() throws ParseException:
1080{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001081 FunctionDecl funcDecl;
1082 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001083 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001084 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1085 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001086 createNewScope();
1087}
1088{
Till Westmannd7dcb122013-05-16 13:19:09 -07001089 "declare" "function" functionName = Identifier()
1090 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001091 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001092 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001093 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001094 getCurrentScope().addFunctionDescriptor(signature, false);
1095 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001096 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001097 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001098 }
1099}
1100
vinayakb38b7ca42012-03-05 05:44:15 +00001101
Till Westmann31c21f92013-05-08 09:21:53 -07001102Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001103{
1104 Query query = new Query();
1105 Expression expr;
1106}
1107{
Till Westmann31c21f92013-05-08 09:21:53 -07001108 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001109 {
1110 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001111 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001112 return query;
1113 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001114
vinayakb38b7ca42012-03-05 05:44:15 +00001115}
1116
1117
1118
1119Expression Expression():
1120{
1121 Expression expr = null;
1122 Expression exprP = null;
1123}
1124{
1125(
1126
1127//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1128 expr = OperatorExpr()
1129 | expr = IfThenElse()
1130 | expr = FLWOGR()
1131 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001132
vinayakb38b7ca42012-03-05 05:44:15 +00001133
1134)
1135 {
1136 return (exprP==null) ? expr : exprP;
1137 }
1138}
1139
1140
1141
1142Expression OperatorExpr()throws ParseException:
1143{
1144 OperatorExpr op = null;
1145 Expression operand = null;
1146}
1147{
1148 operand = AndExpr()
1149 (
1150
Till Westmann96c1f172013-08-01 02:05:48 -07001151 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001152 {
1153 if (op == null) {
1154 op = new OperatorExpr();
1155 op.addOperand(operand);
1156 op.setCurrentop(true);
1157 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001158 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001159 }
1160
1161 operand = AndExpr()
1162 {
1163 op.addOperand(operand);
1164 }
1165
1166 )*
1167
1168 {
1169 return op==null? operand: op;
1170 }
1171}
1172
1173Expression AndExpr()throws ParseException:
1174{
1175 OperatorExpr op = null;
1176 Expression operand = null;
1177}
1178{
1179 operand = RelExpr()
1180 (
1181
Till Westmann96c1f172013-08-01 02:05:48 -07001182 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001183 {
1184 if (op == null) {
1185 op = new OperatorExpr();
1186 op.addOperand(operand);
1187 op.setCurrentop(true);
1188 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001189 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001190 }
1191
1192 operand = RelExpr()
1193 {
1194 op.addOperand(operand);
1195 }
1196
1197 )*
1198
1199 {
1200 return op==null? operand: op;
1201 }
1202}
1203
1204
1205
1206Expression RelExpr()throws ParseException:
1207{
1208 OperatorExpr op = null;
1209 Expression operand = null;
1210 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001211 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001212}
1213{
1214 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001215 {
1216 if (operand instanceof VariableExpr) {
1217 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001218 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001219 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001220 }
1221 }
1222 }
1223
1224 (
Till Westmann96c1f172013-08-01 02:05:48 -07001225 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001226 {
alexander.behm07617fd2012-07-25 10:13:50 +00001227 String mhint = getHint(token);
1228 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1229 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1230 }
vinayakb38b7ca42012-03-05 05:44:15 +00001231 if (op == null) {
1232 op = new OperatorExpr();
1233 op.addOperand(operand, broadcast);
1234 op.setCurrentop(true);
1235 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001236 }
1237 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001238 }
1239
1240 operand = AddExpr()
1241 {
alexander.behm07617fd2012-07-25 10:13:50 +00001242 broadcast = false;
1243 if (operand instanceof VariableExpr) {
1244 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001245 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1246 broadcast = true;
1247 }
alexander.behm07617fd2012-07-25 10:13:50 +00001248 }
vinayakb38b7ca42012-03-05 05:44:15 +00001249 op.addOperand(operand, broadcast);
1250 }
1251 )?
1252
1253 {
alexander.behm07617fd2012-07-25 10:13:50 +00001254 if (annotation != null) {
1255 op.addHint(annotation);
1256 }
vinayakb38b7ca42012-03-05 05:44:15 +00001257 return op==null? operand: op;
1258 }
1259}
1260
1261Expression AddExpr()throws ParseException:
1262{
1263 OperatorExpr op = null;
1264 Expression operand = null;
1265}
1266{
1267 operand = MultExpr()
1268
Till Westmann96c1f172013-08-01 02:05:48 -07001269 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001270 {
1271 if (op == null) {
1272 op = new OperatorExpr();
1273 op.addOperand(operand);
1274 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001275 }
1276 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001277 }
1278
1279 operand = MultExpr()
1280 {
1281 op.addOperand(operand);
1282 }
1283 )*
1284
1285 {
1286 return op==null? operand: op;
1287 }
1288}
1289
1290Expression MultExpr()throws ParseException:
1291{
1292 OperatorExpr op = null;
1293 Expression operand = null;
1294}
1295{
1296 operand = UnionExpr()
1297
Till Westmann96c1f172013-08-01 02:05:48 -07001298 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001299 {
1300 if (op == null) {
1301 op = new OperatorExpr();
1302 op.addOperand(operand);
1303 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001304 }
1305 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001306 }
1307 operand = UnionExpr()
1308 {
1309 op.addOperand(operand);
1310 }
1311 )*
1312
1313 {
1314 return op==null?operand:op;
1315 }
1316}
1317
1318Expression UnionExpr() throws ParseException:
1319{
1320 UnionExpr union = null;
1321 Expression operand1 = null;
1322 Expression operand2 = null;
1323}
1324{
1325 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001326 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001327 (operand2 = UnaryExpr()) {
1328 if (union == null) {
1329 union = new UnionExpr();
1330 union.addExpr(operand1);
1331 }
1332 union.addExpr(operand2);
1333 } )*
1334 {
1335 return (union == null)? operand1: union;
1336 }
1337}
1338
1339Expression UnaryExpr() throws ParseException:
1340{
1341 Expression uexpr = null;
1342 Expression expr = null;
1343}
1344{
Till Westmann96c1f172013-08-01 02:05:48 -07001345 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001346 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001347 uexpr = new UnaryExpr();
1348 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001349 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001350 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001351 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1352 else
1353 throw new ParseException();
1354 }
1355 )?
1356
1357 expr = ValueExpr()
1358 {
1359 if(uexpr!=null){
1360 ((UnaryExpr)uexpr).setExpr(expr);
1361 return uexpr;
1362 }
1363 else{
1364 return expr;
1365 }
1366 }
1367}
1368
Till Westmann04478e72013-05-13 23:01:34 -07001369Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001370{
1371 Expression expr = null;
1372 Identifier ident = null;
1373 AbstractAccessor fa = null;
1374 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001375}
1376{
Till Westmann04478e72013-05-13 23:01:34 -07001377 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001378 {
Till Westmann04478e72013-05-13 23:01:34 -07001379 fa = (fa == null ? new FieldAccessor(expr, ident)
1380 : new FieldAccessor(fa, ident));
1381 }
1382 | index = Index()
1383 {
1384 fa = (fa == null ? new IndexAccessor(expr, index)
1385 : new IndexAccessor(fa, index));
1386 }
1387 )*
1388 {
1389 return fa == null ? expr : fa;
1390 }
vinayakb38b7ca42012-03-05 05:44:15 +00001391}
1392
1393Identifier Field() throws ParseException:
1394{
Till Westmann14a20a72013-05-09 00:06:24 -07001395 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001396}
1397{
Till Westmann96c1f172013-08-01 02:05:48 -07001398 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001399 {
Till Westmann14a20a72013-05-09 00:06:24 -07001400 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001401 }
vinayakb38b7ca42012-03-05 05:44:15 +00001402}
1403
1404int Index() throws ParseException:
1405{
1406 Expression expr = null;
1407 int idx = -2;
1408}
1409{
Till Westmann96c1f172013-08-01 02:05:48 -07001410 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001411 {
1412 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1413 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001414 Literal lit = ((LiteralExpr)expr).getValue();
1415 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1416 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001417 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001418 }
vinayakb38b7ca42012-03-05 05:44:15 +00001419 else {
1420 throw new ParseException("Index should be an INTEGER");
1421 }
1422 }
1423
1424 }
1425
Till Westmann96c1f172013-08-01 02:05:48 -07001426 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001427 {
1428 idx = IndexAccessor.ANY;
1429 // ANY
1430 }
1431
1432 )
1433
Till Westmann96c1f172013-08-01 02:05:48 -07001434 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001435 {
1436 return idx;
1437 }
1438}
1439
1440
1441Expression PrimaryExpr()throws ParseException:
1442{
1443 Expression expr = null;
1444}
1445{
Till Westmann68d99652013-05-09 11:15:21 -07001446 ( LOOKAHEAD(2)
1447 expr = FunctionCallExpr()
1448 | expr = Literal()
1449 | expr = DatasetAccessExpression()
1450 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001451 {
1452 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001453 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001454 }
Till Westmann68d99652013-05-09 11:15:21 -07001455 | expr = ListConstructor()
1456 | expr = RecordConstructor()
1457 | expr = ParenthesizedExpression()
1458 )
1459 {
1460 return expr;
1461 }
vinayakb38b7ca42012-03-05 05:44:15 +00001462}
1463
1464Expression Literal() throws ParseException:
1465{
vinayakb38b7ca42012-03-05 05:44:15 +00001466 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001467 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001468}
1469{
Till Westmann7d535322013-05-09 00:40:02 -07001470 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001471 {
Till Westmann7d535322013-05-09 00:40:02 -07001472 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001473 }
1474 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001475 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001476 try {
1477 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1478 } catch(NumberFormatException ex) {
1479 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1480 }
1481 }
1482 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001483 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001484 lit.setValue(new FloatLiteral(new Float(token.image)));
1485 }
1486 | <DOUBLE_LITERAL>
1487 {
1488 lit.setValue(new DoubleLiteral(new Double(token.image)));
1489 }
1490 | <NULL>
1491 {
1492 lit.setValue(NullLiteral.INSTANCE);
1493 }
1494 | <TRUE>
1495 {
1496 lit.setValue(TrueLiteral.INSTANCE);
1497 }
1498 | <FALSE>
1499 {
1500 lit.setValue(FalseLiteral.INSTANCE);
1501 }
1502 )
vinayakb38b7ca42012-03-05 05:44:15 +00001503 {
1504 return lit;
1505 }
1506}
1507
1508
1509VariableExpr VariableRef() throws ParseException:
1510{
1511 VariableExpr varExp = new VariableExpr();
1512 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001513}
1514{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001515 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001516 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001517 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001518 Identifier ident = lookupSymbol(varName);
1519 if (isInForbiddenScopes(varName)) {
1520 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.");
1521 }
1522 if(ident != null) { // exist such ident
1523 varExp.setIsNewVar(false);
1524 varExp.setVar((VarIdentifier)ident);
1525 } else {
1526 varExp.setVar(var);
1527 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001528 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001529 return varExp;
1530 }
1531}
1532
1533
1534VariableExpr Variable() throws ParseException:
1535{
1536 VariableExpr varExp = new VariableExpr();
1537 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001538}
1539{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001540 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001541 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001542 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001543 if(ident != null) { // exist such ident
1544 varExp.setIsNewVar(false);
1545 }
1546 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001547 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001548 return varExp;
1549 }
1550}
1551
1552Expression ListConstructor() throws ParseException:
1553{
1554 Expression expr = null;
1555}
1556{
1557 (
1558 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1559 )
1560
1561 {
1562 return expr;
1563 }
1564}
1565
1566
1567ListConstructor OrderedListConstructor() throws ParseException:
1568{
1569 ListConstructor expr = new ListConstructor();
1570 Expression tmp = null;
1571 List<Expression> exprList = new ArrayList<Expression>();
1572 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1573}
1574{
1575
Till Westmann96c1f172013-08-01 02:05:48 -07001576 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001577 ( tmp = Expression()
1578 {
1579 exprList.add(tmp);
1580 }
1581
Till Westmann96c1f172013-08-01 02:05:48 -07001582 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001583 )?
1584
Till Westmann96c1f172013-08-01 02:05:48 -07001585 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001586
1587 {
1588 expr.setExprList(exprList);
1589 return expr;
1590 }
1591}
1592
1593ListConstructor UnorderedListConstructor() throws ParseException:
1594{
1595 ListConstructor expr = new ListConstructor();
1596 Expression tmp = null;
1597 List<Expression> exprList = new ArrayList<Expression>();
1598 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1599}
1600{
1601
Till Westmann96c1f172013-08-01 02:05:48 -07001602 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001603 {
1604 exprList.add(tmp);
1605 }
Till Westmann96c1f172013-08-01 02:05:48 -07001606 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001607 {
1608 expr.setExprList(exprList);
1609 return expr;
1610 }
1611}
1612
1613RecordConstructor RecordConstructor() throws ParseException:
1614{
1615 RecordConstructor expr = new RecordConstructor();
1616 FieldBinding tmp = null;
1617 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1618}
1619{
Till Westmann96c1f172013-08-01 02:05:48 -07001620 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001621 {
1622 fbList.add(tmp);
1623 }
Till Westmann96c1f172013-08-01 02:05:48 -07001624 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001625 {
1626 expr.setFbList(fbList);
1627 return expr;
1628 }
1629}
1630
1631FieldBinding FieldBinding() throws ParseException:
1632{
1633 FieldBinding fb = new FieldBinding();
1634 Expression left, right;
1635}
1636{
Till Westmann96c1f172013-08-01 02:05:48 -07001637 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001638 {
1639 fb.setLeftExpr(left);
1640 fb.setRightExpr(right);
1641 return fb;
1642 }
1643}
1644
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001645
vinayakb38b7ca42012-03-05 05:44:15 +00001646Expression FunctionCallExpr() throws ParseException:
1647{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001648 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001649 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001650 Expression tmp;
1651 int arity = 0;
Till Westmann31c21f92013-05-08 09:21:53 -07001652 Pair<Identifier,Identifier> funcId = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001653 String funcName;
1654 String dataverse;
Till Westmann31c21f92013-05-08 09:21:53 -07001655 String hint = null;
1656 String id1 = null;
1657 String id2 = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001658}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001659{
Till Westmann31c21f92013-05-08 09:21:53 -07001660 funcId = FunctionOrTypeName()
vinayakb38b7ca42012-03-05 05:44:15 +00001661 {
Till Westmann31c21f92013-05-08 09:21:53 -07001662 dataverse = funcId.first.getValue();
1663 funcName = funcId.second.getValue();
1664 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001665 }
Till Westmann31c21f92013-05-08 09:21:53 -07001666 <LEFTPAREN> (tmp = Expression()
1667 {
1668 argList.add(tmp);
1669 arity ++;
1670 }
Till Westmann96c1f172013-08-01 02:05:48 -07001671 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001672 {
1673 argList.add(tmp);
1674 arity++;
1675 }
1676 )*)? <RIGHTPAREN>
1677 {
1678 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity);
1679 if (signature == null) {
1680 signature = new FunctionSignature(dataverse, funcName, arity);
1681 }
1682 callExpr = new CallExpr(signature,argList);
1683 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1684 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1685 }
1686 return callExpr;
1687 }
vinayakb38b7ca42012-03-05 05:44:15 +00001688}
1689
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001690Expression DatasetAccessExpression() throws ParseException:
1691{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001692 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001693 String arg1 = null;
1694 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001695 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001696}
1697{
Till Westmann14a20a72013-05-09 00:06:24 -07001698 <DATASET>
1699 {
Till Westmann14a20a72013-05-09 00:06:24 -07001700 funcName = token.image;
1701 }
Till Westmann96c1f172013-08-01 02:05:48 -07001702 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001703 {
1704 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001705 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001706 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001707 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001708 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001709 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001710 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001711 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1712 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1713 if (signature == null) {
1714 signature = new FunctionSignature(dataverse, funcName, 1);
1715 }
1716 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001717 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001718 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001719 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001720}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001721
vinayakb38b7ca42012-03-05 05:44:15 +00001722Expression ParenthesizedExpression() throws ParseException:
1723{
1724 Expression expr;
1725}
1726{
1727 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1728 {
1729 return expr;
1730 }
1731}
1732
1733Expression IfThenElse() throws ParseException:
1734{
1735 Expression condExpr;
1736 Expression thenExpr;
1737 Expression elseExpr;
1738 IfExpr ifExpr = new IfExpr();
1739}
1740{
Till Westmann96c1f172013-08-01 02:05:48 -07001741 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001742
1743 {
1744 ifExpr.setCondExpr(condExpr);
1745 ifExpr.setThenExpr(thenExpr);
1746 ifExpr.setElseExpr(elseExpr);
1747 return ifExpr;
1748 }
1749}
1750
1751Expression FLWOGR() throws ParseException:
1752{
1753 FLWOGRExpression flworg = new FLWOGRExpression();
1754 List<Clause> clauseList = new ArrayList<Clause>();
1755 Expression returnExpr;
1756 Clause tmp;
1757 createNewScope();
1758}
1759{
1760 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001761 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001762
1763 {
1764 flworg.setClauseList(clauseList);
1765 flworg.setReturnExpr(returnExpr);
1766 removeCurrentScope();
1767 return flworg;
1768 }
1769}
1770
1771Clause Clause()throws ParseException :
1772{
1773 Clause clause;
1774}
1775{
1776 (
1777 clause = ForClause()
1778 | clause = LetClause()
1779 | clause = WhereClause()
1780 | clause = OrderbyClause()
1781 | clause = GroupClause()
1782 | clause = LimitClause()
1783 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001784 )
1785 {
1786 return clause;
1787 }
1788}
1789
1790Clause ForClause()throws ParseException :
1791{
1792 ForClause fc = new ForClause();
1793 VariableExpr varExp;
1794 VariableExpr varPos = null;
1795 Expression inExp;
1796 extendCurrentScope();
1797}
1798{
Till Westmann96c1f172013-08-01 02:05:48 -07001799 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001800 {
1801 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001802 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001803 fc.setInExpr(inExp);
1804 if (varPos != null) {
1805 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001806 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001807 }
1808 return fc;
1809 }
1810}
1811
1812Clause LetClause() throws ParseException:
1813{
1814 LetClause lc = new LetClause();
1815 VariableExpr varExp;
1816 Expression beExp;
1817 extendCurrentScope();
1818}
1819{
Till Westmann96c1f172013-08-01 02:05:48 -07001820 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001821 {
1822 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001823 lc.setVarExpr(varExp);
1824 lc.setBeExpr(beExp);
1825 return lc;
1826 }
1827}
1828
1829Clause WhereClause()throws ParseException :
1830{
1831 WhereClause wc = new WhereClause();
1832 Expression whereExpr;
1833}
1834{
Till Westmann96c1f172013-08-01 02:05:48 -07001835 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001836 {
1837 wc.setWhereExpr(whereExpr);
1838 return wc;
1839 }
1840}
1841
1842Clause OrderbyClause()throws ParseException :
1843{
1844 OrderbyClause oc = new OrderbyClause();
1845 Expression orderbyExpr;
1846 List<Expression> orderbyList = new ArrayList<Expression>();
1847 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1848 int numOfOrderby = 0;
1849}
1850{
1851 (
Till Westmann96c1f172013-08-01 02:05:48 -07001852 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001853 {
1854 String hint = getHint(token);
1855 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1856 String splits[] = hint.split(" +");
1857 int numFrames = Integer.parseInt(splits[1]);
1858 int numTuples = Integer.parseInt(splits[2]);
1859 oc.setNumFrames(numFrames);
1860 oc.setNumTuples(numTuples);
1861 }
1862 }
Till Westmann96c1f172013-08-01 02:05:48 -07001863 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001864 {
1865 orderbyList.add(orderbyExpr);
1866 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1867 }
Till Westmann96c1f172013-08-01 02:05:48 -07001868 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1869 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001870 {
1871 modifierList.add(modif);
1872 }
1873
Till Westmann96c1f172013-08-01 02:05:48 -07001874 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001875 {
1876 orderbyList.add(orderbyExpr);
1877 modif = OrderbyClause.OrderModifier.ASC;
1878 }
Till Westmann96c1f172013-08-01 02:05:48 -07001879 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1880 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001881 {
1882 modifierList.add(modif);
1883 }
1884 )*
1885)
1886 {
1887 oc.setModifierList(modifierList);
1888 oc.setOrderbyList(orderbyList);
1889 return oc;
1890 }
1891}
1892Clause GroupClause()throws ParseException :
1893{
1894 GroupbyClause gbc = new GroupbyClause();
1895 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1896 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1897 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1898 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1899 VariableExpr var = null;
1900 VariableExpr withVar = null;
1901 Expression expr = null;
1902 VariableExpr decorVar = null;
1903 Expression decorExpr = null;
1904}
1905{
1906 {
1907 Scope newScope = extendCurrentScopeNoPush(true);
1908 // extendCurrentScope(true);
1909 }
Till Westmann96c1f172013-08-01 02:05:48 -07001910 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00001911 {
1912 String hint = getHint(token);
1913 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1914 gbc.setHashGroupByHint(true);
1915 }
1916 }
Till Westmann96c1f172013-08-01 02:05:48 -07001917 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001918 {
1919 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001920 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001921 expr = Expression()
1922 {
1923 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1924 vePairList.add(pair1);
1925 }
Till Westmann96c1f172013-08-01 02:05:48 -07001926 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001927 {
1928 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001929 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001930 expr = Expression()
1931 {
1932 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1933 vePairList.add(pair2);
1934 }
1935 )*
Till Westmann96c1f172013-08-01 02:05:48 -07001936 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001937 {
1938 newScope.addNewVarSymbolToScope(decorVar.getVar());
1939 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1940 decorPairList.add(pair3);
1941 }
Till Westmann96c1f172013-08-01 02:05:48 -07001942 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001943 {
1944 newScope.addNewVarSymbolToScope(decorVar.getVar());
1945 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
1946 decorPairList.add(pair4);
1947 }
1948 )*
1949 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001950 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001951 {
1952 if(withVar.getIsNewVar()==true)
1953 throw new ParseException("can't find variable " + withVar.getVar());
1954 withVarList.add(withVar);
1955 newScope.addNewVarSymbolToScope(withVar.getVar());
1956 }
Till Westmann96c1f172013-08-01 02:05:48 -07001957 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001958 {
1959 if(withVar.getIsNewVar()==true)
1960 throw new ParseException("can't find variable " + withVar.getVar());
1961 withVarList.add(withVar);
1962 newScope.addNewVarSymbolToScope(withVar.getVar());
1963 })*
1964 {
1965 gbc.setGbyPairList(vePairList);
1966 gbc.setDecorPairList(decorPairList);
1967 gbc.setWithVarList(withVarList);
1968 replaceCurrentScope(newScope);
1969 return gbc;
1970 }
1971}
1972
1973
1974LimitClause LimitClause() throws ParseException:
1975{
1976 LimitClause lc = new LimitClause();
1977 Expression expr;
1978 pushForbiddenScope(getCurrentScope());
1979}
1980{
Till Westmann96c1f172013-08-01 02:05:48 -07001981 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
1982 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00001983
1984 {
1985 popForbiddenScope();
1986 return lc;
1987 }
1988}
1989
1990DistinctClause DistinctClause() throws ParseException:
1991{
1992 List<Expression> exprs = new ArrayList<Expression>();
1993 Expression expr;
1994}
1995{
Till Westmann96c1f172013-08-01 02:05:48 -07001996 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001997 {
1998 exprs.add(expr);
1999 }
Till Westmann96c1f172013-08-01 02:05:48 -07002000 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002001 {
2002 exprs.add(expr);
2003 }
2004 )*
2005 {
2006 return new DistinctClause(exprs);
2007 }
2008}
2009
vinayakb38b7ca42012-03-05 05:44:15 +00002010QuantifiedExpression QuantifiedExpression()throws ParseException:
2011{
2012 QuantifiedExpression qc = new QuantifiedExpression();
2013 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2014 Expression satisfiesExpr;
2015 VariableExpr var;
2016 Expression inExpr;
2017 QuantifiedPair pair;
2018}
2019{
2020 {
2021 createNewScope();
2022 }
2023
Till Westmann96c1f172013-08-01 02:05:48 -07002024 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2025 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2026 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002027 {
2028 pair = new QuantifiedPair(var, inExpr);
2029 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2030 quantifiedList.add(pair);
2031 }
2032 (
Till Westmann96c1f172013-08-01 02:05:48 -07002033 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002034 {
2035 pair = new QuantifiedPair(var, inExpr);
2036 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2037 quantifiedList.add(pair);
2038 }
2039 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002040 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002041 {
2042 qc.setSatisfiesExpr(satisfiesExpr);
2043 qc.setQuantifiedList(quantifiedList);
2044 removeCurrentScope();
2045 return qc;
2046 }
2047}
2048
2049TOKEN_MGR_DECLS:
2050{
Till Westmann96c1f172013-08-01 02:05:48 -07002051 public int commentDepth = 0;
2052 public IntStack lexerStateStack = new IntStack();
2053
2054 public void pushState() {
2055 lexerStateStack.push( curLexState );
2056 }
2057
2058 public void popState() {
2059 if (lexerStateStack.size() > 0) {
2060 SwitchTo( lexerStateStack.pop() );
2061 } else {
2062 throw new RuntimeException();
2063 }
2064 }
vinayakb38b7ca42012-03-05 05:44:15 +00002065}
2066
Till Westmann96c1f172013-08-01 02:05:48 -07002067<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002068TOKEN :
2069{
Till Westmann96c1f172013-08-01 02:05:48 -07002070 <ASC : "asc">
vinayakb38b7ca42012-03-05 05:44:15 +00002071}
2072
Till Westmann96c1f172013-08-01 02:05:48 -07002073<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002074TOKEN :
2075{
Till Westmann96c1f172013-08-01 02:05:48 -07002076 <AT : "at">
vinayakb38b7ca42012-03-05 05:44:15 +00002077}
2078
Till Westmann96c1f172013-08-01 02:05:48 -07002079<DEFAULT,IN_DBL_BRACE>
2080TOKEN :
2081{
2082 <BY : "by">
2083}
2084
2085<DEFAULT,IN_DBL_BRACE>
2086TOKEN :
2087{
2088 <DATASET : "dataset">
2089}
2090
2091<DEFAULT,IN_DBL_BRACE>
2092TOKEN :
2093{
2094 <DECOR : "decor">
2095}
2096
2097<DEFAULT,IN_DBL_BRACE>
2098TOKEN :
2099{
2100 <DESC : "desc">
2101}
2102
2103<DEFAULT,IN_DBL_BRACE>
2104TOKEN :
2105{
2106 <DISTINCT : "distinct">
2107}
2108
2109<DEFAULT,IN_DBL_BRACE>
2110TOKEN :
2111{
2112 <ELSE : "else">
2113}
2114
2115<DEFAULT,IN_DBL_BRACE>
2116TOKEN :
2117{
2118 <EVERY : "every">
2119}
2120
2121<DEFAULT,IN_DBL_BRACE>
2122TOKEN :
2123{
2124 <FOR : "for">
2125}
2126
2127<DEFAULT,IN_DBL_BRACE>
2128TOKEN :
2129{
2130 <GROUP : "group">
2131}
2132
2133<DEFAULT,IN_DBL_BRACE>
2134TOKEN :
2135{
2136 <IF : "if">
2137}
2138
2139<DEFAULT,IN_DBL_BRACE>
2140TOKEN :
2141{
2142 <IN : "in">
2143}
2144
2145<DEFAULT,IN_DBL_BRACE>
2146TOKEN :
2147{
2148 <LET : "let">
2149}
2150
2151<DEFAULT,IN_DBL_BRACE>
2152TOKEN :
2153{
2154 <LIMIT : "limit">
2155}
2156
2157<DEFAULT,IN_DBL_BRACE>
2158TOKEN :
2159{
2160 <OFFSET : "offset">
2161}
2162
2163<DEFAULT,IN_DBL_BRACE>
2164TOKEN :
2165{
2166 <ORDER : "order">
2167}
2168
2169<DEFAULT,IN_DBL_BRACE>
2170TOKEN :
2171{
2172 <RETURN : "return">
2173}
2174
2175<DEFAULT,IN_DBL_BRACE>
2176TOKEN :
2177{
2178 <SATISFIES : "satisfies">
2179}
2180
2181<DEFAULT,IN_DBL_BRACE>
2182TOKEN :
2183{
2184 <SOME : "some">
2185}
2186
2187<DEFAULT,IN_DBL_BRACE>
2188TOKEN :
2189{
2190 <THEN : "then">
2191}
2192
2193<DEFAULT,IN_DBL_BRACE>
2194TOKEN :
2195{
2196 <UNION : "union">
2197}
2198
2199<DEFAULT,IN_DBL_BRACE>
2200TOKEN :
2201{
2202 <WHERE : "where">
2203}
2204
2205<DEFAULT,IN_DBL_BRACE>
2206TOKEN :
2207{
2208 <WITH : "with">
2209}
2210
2211<DEFAULT,IN_DBL_BRACE>
2212TOKEN :
2213{
2214 <CARET : "^">
2215}
2216
2217<DEFAULT,IN_DBL_BRACE>
2218TOKEN :
2219{
2220 <DIV : "/">
2221}
2222
2223<DEFAULT,IN_DBL_BRACE>
2224TOKEN :
2225{
2226 <IDIV : "idiv">
2227}
2228
2229<DEFAULT,IN_DBL_BRACE>
2230TOKEN :
2231{
2232 <MOD : "%">
2233}
2234
2235<DEFAULT,IN_DBL_BRACE>
2236TOKEN :
2237{
2238 <MUL : "*">
2239}
2240
2241<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002242TOKEN :
2243{
2244 <LEFTPAREN : "(" >
2245}
2246
Till Westmann96c1f172013-08-01 02:05:48 -07002247<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002248TOKEN :
2249{
2250 <RIGHTPAREN : ")" >
2251}
2252
Till Westmann96c1f172013-08-01 02:05:48 -07002253<DEFAULT,IN_DBL_BRACE>
2254TOKEN :
2255{
2256 <LEFTBRACKET : "[" >
2257}
2258
2259<DEFAULT,IN_DBL_BRACE>
2260TOKEN :
2261{
2262 <RIGHTBRACKET : "]" >
2263}
2264
2265<DEFAULT,IN_DBL_BRACE>
2266TOKEN :
2267{
2268 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2269}
vinayakb38b7ca42012-03-05 05:44:15 +00002270
2271<DEFAULT>
2272TOKEN :
2273{
Till Westmann96c1f172013-08-01 02:05:48 -07002274 <RIGHTBRACE : "}"> { popState(); }
2275}
2276
2277<DEFAULT,IN_DBL_BRACE>
2278TOKEN :
2279{
2280 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2281}
2282
2283<IN_DBL_BRACE>
2284TOKEN :
2285{
2286 <RIGHTDBLBRACE : "}}"> { popState(); }
2287}
2288
2289<DEFAULT,IN_DBL_BRACE>
2290TOKEN :
2291{
2292 <COMMA : ",">
2293}
2294
2295<DEFAULT,IN_DBL_BRACE>
2296TOKEN :
2297{
2298 <DOT : ".">
2299}
2300
2301<DEFAULT,IN_DBL_BRACE>
2302TOKEN :
2303{
2304 <PLUS : "+">
2305}
2306
2307<DEFAULT,IN_DBL_BRACE>
2308TOKEN :
2309{
2310 <MINUS : "-">
2311}
2312
2313<DEFAULT,IN_DBL_BRACE>
2314TOKEN :
2315{
2316 <COLON : ":">
2317}
2318
2319<DEFAULT,IN_DBL_BRACE>
2320TOKEN :
2321{
2322 <QUES : "?">
2323}
2324
2325<DEFAULT,IN_DBL_BRACE>
2326TOKEN :
2327{
2328 <LT : "<">
2329}
2330
2331<DEFAULT,IN_DBL_BRACE>
2332TOKEN :
2333{
2334 <GT : ">">
2335}
2336
2337<DEFAULT,IN_DBL_BRACE>
2338TOKEN :
2339{
2340 <LE : "<=">
2341}
2342
2343<DEFAULT,IN_DBL_BRACE>
2344TOKEN :
2345{
2346 <GE : ">=">
2347}
2348
2349<DEFAULT,IN_DBL_BRACE>
2350TOKEN :
2351{
2352 <EQ : "=">
2353}
2354
2355<DEFAULT,IN_DBL_BRACE>
2356TOKEN :
2357{
2358 <NE : "!=">
2359}
2360
2361<DEFAULT,IN_DBL_BRACE>
2362TOKEN :
2363{
2364 <SIMILAR : "~=">
2365}
2366
2367<DEFAULT,IN_DBL_BRACE>
2368TOKEN :
2369{
2370 <ASSIGN : ":=">
2371}
2372
2373<DEFAULT,IN_DBL_BRACE>
2374TOKEN :
2375{
2376 <OR : "or">
2377}
2378
2379<DEFAULT,IN_DBL_BRACE>
2380TOKEN :
2381{
2382 <AND : "and">
2383}
2384
2385<DEFAULT,IN_DBL_BRACE>
2386TOKEN :
2387{
vinayakb38b7ca42012-03-05 05:44:15 +00002388 <INTEGER_LITERAL : (<DIGIT>)+ >
2389}
2390
Till Westmann96c1f172013-08-01 02:05:48 -07002391<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002392TOKEN :
2393{
2394 <NULL : "null">
2395}
2396
Till Westmann96c1f172013-08-01 02:05:48 -07002397<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002398TOKEN :
2399{
2400 <TRUE : "true">
2401}
2402
Till Westmann96c1f172013-08-01 02:05:48 -07002403<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002404TOKEN :
2405{
2406 <FALSE : "false">
2407}
2408
Till Westmann96c1f172013-08-01 02:05:48 -07002409<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002410TOKEN :
2411{
2412 <#DIGIT : ["0" - "9"]>
2413}
2414
Till Westmann96c1f172013-08-01 02:05:48 -07002415<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002416TOKEN:
2417{
Till Westmannaf0551c2013-07-23 14:53:31 -07002418 < DOUBLE_LITERAL: <DIGITS>
2419 | <DIGITS> ( "." <DIGITS> )?
2420 | "." <DIGITS>
vinayakb38b7ca42012-03-05 05:44:15 +00002421 >
2422 |
Till Westmannaf0551c2013-07-23 14:53:31 -07002423 < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2424 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2425 | "." <DIGITS> ( "f" | "F" )
vinayakb38b7ca42012-03-05 05:44:15 +00002426 >
2427 |
Till Westmannaf0551c2013-07-23 14:53:31 -07002428 <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002429}
2430
Till Westmann96c1f172013-08-01 02:05:48 -07002431<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002432TOKEN :
2433{
2434 <#LETTER : ["A" - "Z", "a" - "z"]>
2435}
2436
Till Westmann96c1f172013-08-01 02:05:48 -07002437<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002438TOKEN :
2439{
2440 <SPECIALCHARS : ["$", "_", "-"] >
2441}
2442
Till Westmann96c1f172013-08-01 02:05:48 -07002443<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002444TOKEN :
2445{
2446 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2447 |
2448 < #EscapeQuot: "\\\"" >
2449 |
2450 < #EscapeApos: "\\\'" >
2451}
2452
Till Westmann96c1f172013-08-01 02:05:48 -07002453<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002454TOKEN :
2455{
Till Westmannaf0551c2013-07-23 14:53:31 -07002456 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002457}
2458
Till Westmann96c1f172013-08-01 02:05:48 -07002459<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002460TOKEN :
2461{
Till Westmannaf0551c2013-07-23 14:53:31 -07002462 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002463}
2464
Till Westmann96c1f172013-08-01 02:05:48 -07002465<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002466SKIP:
2467{
2468 " "
2469| "\t"
2470| "\r"
2471| "\n"
2472}
2473
Till Westmann96c1f172013-08-01 02:05:48 -07002474<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002475SKIP:
2476{
2477 <"//" (~["\n"])* "\n">
2478}
2479
Till Westmann96c1f172013-08-01 02:05:48 -07002480<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002481SKIP:
2482{
2483 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2484}
2485
Till Westmann96c1f172013-08-01 02:05:48 -07002486<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002487SKIP:
2488{
Till Westmann96c1f172013-08-01 02:05:48 -07002489 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002490}
2491
2492<INSIDE_COMMENT>
2493SPECIAL_TOKEN:
2494{
Till Westmann96c1f172013-08-01 02:05:48 -07002495 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002496}
2497
2498<INSIDE_COMMENT>
2499SKIP:
2500{
Till Westmann96c1f172013-08-01 02:05:48 -07002501 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002502}
2503
2504<INSIDE_COMMENT>
2505SKIP:
2506{
Till Westmann96c1f172013-08-01 02:05:48 -07002507 <"*/"> { popState(); }
2508| <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002509}