blob: 9b8f0516fe15653c204fb4bf5fcf173d8ab8742c [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
ramangrover299f76a5e2013-06-18 10:25:17 -070089 private static class FunctionName {
90 public String dataverse = null;
91 public String library = null;
92 public String function = null;
93 }
94
vinayakb38b7ca42012-03-05 05:44:15 +000095 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070096 if (t.specialToken == null) {
97 return null;
98 }
99 String s = t.specialToken.image;
100 int n = s.length();
101 if (n < 2) {
102 return null;
103 }
104 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000105 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700106
107 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
108 IRecordFieldDataGen rfdg = null;
109 String splits[] = hint.split(" +");
110 if (splits[0].equals(VAL_FILE_HINT)) {
111 File[] valFiles = new File[splits.length - 1];
112 for (int k=1; k<splits.length; k++) {
113 valFiles[k-1] = new File(splits[k]);
114 }
115 rfdg = new FieldValFileDataGen(valFiles);
116 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
117 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
118 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
119 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
120 } else if (splits[0].equals(LIST_HINT)) {
121 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
122 } else if (splits[0].equals(INTERVAL_HINT)) {
123 FieldIntervalDataGen.ValueType vt;
124 if (splits[1].equals("int")) {
125 vt = FieldIntervalDataGen.ValueType.INT;
126 } else if (splits[1].equals("long")) {
127 vt = FieldIntervalDataGen.ValueType.LONG;
128 } else if (splits[1].equals("float")) {
129 vt = FieldIntervalDataGen.ValueType.FLOAT;
130 } else if (splits[1].equals("double")) {
131 vt = FieldIntervalDataGen.ValueType.DOUBLE;
132 } else {
133 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
134 }
135 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
136 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
137 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
138 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
139 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
140 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
141 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
142 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
143 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
144 } else if (splits[0].equals(AUTO_HINT)) {
145 rfdg = new AutoDataGen(splits[1]);
146 }
147 return rfdg;
148 }
vinayakb38b7ca42012-03-05 05:44:15 +0000149
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000150 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700151 this(new StringReader(s));
152 super.setInput(s);
153 }
vinayakb38b7ca42012-03-05 05:44:15 +0000154
Till Westmann31c21f92013-05-08 09:21:53 -0700155 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
156 File file = new File(args[0]);
157 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
158 AQLParser parser = new AQLParser(fis);
159 List<Statement> st = parser.Statement();
160 //st.accept(new AQLPrintVisitor(), 0);
161 }
vinayakb38b7ca42012-03-05 05:44:15 +0000162}
163
164PARSER_END(AQLParser)
165
166
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000167List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000168{
vinayakb38b7ca42012-03-05 05:44:15 +0000169 scopeStack.push(RootScopeFactory.createRootScope(this));
170 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700171 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000172}
173{
Till Westmann31c21f92013-05-08 09:21:53 -0700174 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000175 {
Till Westmann31c21f92013-05-08 09:21:53 -0700176 decls.add(stmt);
177 }
178 )*
179 <EOF>
180 {
181 return decls;
182 }
183}
184
185Statement SingleStatement() throws ParseException:
186{
187 Statement stmt = null;
188}
189{
190 (
191 stmt = DataverseDeclaration()
192 | stmt = FunctionDeclaration()
193 | stmt = CreateStatement()
194 | stmt = LoadStatement()
195 | stmt = DropStatement()
196 | stmt = WriteStatement()
197 | stmt = SetStatement()
198 | stmt = InsertStatement()
199 | stmt = DeleteStatement()
200 | stmt = UpdateStatement()
201 | stmt = FeedStatement()
202 | stmt = Query()
203 )
204 {
205 return stmt;
206 }
207}
208
209DataverseDecl DataverseDeclaration() throws ParseException:
210{
Till Westmann14a20a72013-05-09 00:06:24 -0700211 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700212}
213{
Till Westmanna4242bc2013-05-08 17:49:55 -0700214 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700215 {
Till Westmann14a20a72013-05-09 00:06:24 -0700216 defaultDataverse = dvName;
217 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700218 }
219}
220
221Statement CreateStatement() throws ParseException:
222{
223 String hint = null;
224 boolean dgen = false;
225 Statement stmt = null;
226}
227{
228 "create"
229 (
230 {
231 hint = getHint(token);
232 if (hint != null && hint.startsWith(DGEN_HINT)) {
233 dgen = true;
234 }
235 }
236 stmt = TypeSpecification(hint, dgen)
237 | stmt = NodegroupSpecification()
238 | stmt = DatasetSpecification()
239 | stmt = IndexSpecification()
240 | stmt = DataverseSpecification()
241 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700242 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700243 )
244 {
245 return stmt;
246 }
247}
248
249TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
250{
251 Pair<Identifier,Identifier> nameComponents = null;
252 boolean ifNotExists = false;
253 TypeExpression typeExpr = null;
254}
255{
ramangrover299f76a5e2013-06-18 10:25:17 -0700256 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700257 "as" typeExpr = TypeExpr()
258 {
259 long numValues = -1;
260 String filename = null;
261 if (dgen) {
262 String splits[] = hint.split(" +");
263 if (splits.length != 3) {
264 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
265 }
266 filename = splits[1];
267 numValues = Long.parseLong(splits[2]);
268 }
269 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
270 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
271 }
272}
273
274
275NodegroupDecl NodegroupSpecification() throws ParseException:
276{
Till Westmann14a20a72013-05-09 00:06:24 -0700277 String name = null;
278 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700279 boolean ifNotExists = false;
280 List<Identifier>ncNames = null;
281}
282{
Till Westmanna4242bc2013-05-08 17:49:55 -0700283 "nodegroup" name = Identifier()
284 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700285 {
286 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700287 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700288 }
Till Westmann96c1f172013-08-01 02:05:48 -0700289 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700290 {
Till Westmann14a20a72013-05-09 00:06:24 -0700291 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700292 }
293 )*
294 {
Till Westmann14a20a72013-05-09 00:06:24 -0700295 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700296 }
297}
298
299DatasetDecl DatasetSpecification() throws ParseException:
300{
301 Pair<Identifier,Identifier> nameComponents = null;
302 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700303 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700304 String adapterName = null;
305 Map<String,String> properties = null;
306 FunctionSignature appliedFunction = null;
307 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700308 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700309 Map<String,String> hints = new HashMap<String,String>();
310 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700311 boolean autogenerated = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700312}
313{
314 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700315 "external" <DATASET> nameComponents = QualifiedName()
316 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
317 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700318 "using" adapterName = AdapterName() properties = Configuration()
319 ( "hints" hints = Properties() )?
320 {
321 ExternalDetailsDecl edd = new ExternalDetailsDecl();
322 edd.setAdapter(adapterName);
323 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700324 dsetDecl = new DatasetDecl(nameComponents.first,
325 nameComponents.second,
326 new Identifier(typeName),
327 hints,
328 DatasetType.EXTERNAL,
329 edd,
330 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700331 }
332
Till Westmannd7dcb122013-05-16 13:19:09 -0700333 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700334 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
335 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700336 primaryKeyFields = PrimaryKey()
337 ("autogenerated" { autogenerated = true; } )?
338 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700339 ( "hints" hints = Properties() )?
340 {
Till Westmann14a20a72013-05-09 00:06:24 -0700341 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
342 ? new Identifier(nodeGroupName)
343 : null,
zheilbron2467f2e2013-08-23 19:07:31 -0700344 primaryKeyFields, autogenerated);
Till Westmann14a20a72013-05-09 00:06:24 -0700345 dsetDecl = new DatasetDecl(nameComponents.first,
346 nameComponents.second,
347 new Identifier(typeName),
348 hints,
349 DatasetType.INTERNAL,
350 idd,
351 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700352 }
353 )
354 {
355 return dsetDecl;
356 }
357}
358
359CreateIndexStatement IndexSpecification() throws ParseException:
360{
361 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700362 String indexName = null;
363 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700364 boolean ifNotExists = false;
365 Pair<Identifier,Identifier> nameComponents = null;
366 IndexParams indexType = null;
367}
368{
Till Westmanna4242bc2013-05-08 17:49:55 -0700369 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700370 ifNotExists = IfNotExists()
371 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700372 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700373 {
Till Westmann14a20a72013-05-09 00:06:24 -0700374 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700375 }
Till Westmann96c1f172013-08-01 02:05:48 -0700376 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700377 {
Till Westmann14a20a72013-05-09 00:06:24 -0700378 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700379 }
380 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
381 {
Till Westmann14a20a72013-05-09 00:06:24 -0700382 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700383 cis.setIfNotExists(ifNotExists);
384 cis.setDataverseName(nameComponents.first);
385 cis.setDatasetName(nameComponents.second);
386 if (indexType != null) {
387 cis.setIndexType(indexType.type);
388 cis.setGramLength(indexType.gramLength);
389 }
390 return cis;
391 }
392}
393
394IndexParams IndexType() throws ParseException:
395{
396 IndexType type = null;
397 int gramLength = 0;
398}
399{
400 ("btree"
401 {
402 type = IndexType.BTREE;
403 }
404 | "rtree"
405 {
406 type = IndexType.RTREE;
407 }
408 | "keyword"
409 {
JIMAHNb75446d2013-06-03 08:35:27 -0700410 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700411 }
412 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
413 {
JIMAHNb75446d2013-06-03 08:35:27 -0700414 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700415 gramLength = Integer.valueOf(token.image);
416 }
417 <RIGHTPAREN>)
418 {
419 return new IndexParams(type, gramLength);
420 }
421}
422
423CreateDataverseStatement DataverseSpecification() throws ParseException :
424{
Till Westmann14a20a72013-05-09 00:06:24 -0700425 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700426 boolean ifNotExists = false;
427 String format = null;
428}
429{
Till Westmanna4242bc2013-05-08 17:49:55 -0700430 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700431 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700432 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700433 {
Till Westmann14a20a72013-05-09 00:06:24 -0700434 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700435 }
436}
437
438CreateFunctionStatement FunctionSpecification() throws ParseException:
439{
440 FunctionSignature signature;
441 boolean ifNotExists = false;
442 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
443 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700444 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700445 Expression functionBodyExpr;
446 Token beginPos;
447 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700448 FunctionName fctName = null;
449
Till Westmann31c21f92013-05-08 09:21:53 -0700450 createNewScope();
451}
452{
ramangrover299f76a5e2013-06-18 10:25:17 -0700453 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700454 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700455 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700456 <LEFTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700457 {
458 beginPos = token;
459 }
Till Westmann96c1f172013-08-01 02:05:48 -0700460 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700461 {
462 endPos = token;
463 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700464 // TODO use fctName.library
465 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700466 getCurrentScope().addFunctionDescriptor(signature, false);
467 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
468 }
469}
470
ramangrover29a774ef22013-07-17 09:29:18 -0700471CreateFeedStatement FeedSpecification() throws ParseException:
472{
473 Pair<Identifier,Identifier> nameComponents = null;
474 boolean ifNotExists = false;
475 String adaptorName = null;
476 Map<String,String> properties = null;
477 FunctionSignature appliedFunction = null;
478 CreateFeedStatement cfs = null;
479}
480{
481 (
482 "feed" nameComponents = QualifiedName()
483 ifNotExists = IfNotExists()
484 "using" adaptorName = AdapterName() properties = Configuration()
485 (appliedFunction = ApplyFunction())?
486 {
487 cfs = new CreateFeedStatement(nameComponents.first,
488 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
489 }
490
491 )
492 {
493 return cfs;
494 }
495}
496
497
498
Till Westmannd7dcb122013-05-16 13:19:09 -0700499List<VarIdentifier> ParameterList() throws ParseException:
500{
501 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
502 VarIdentifier var = null;
503}
504{
Till Westmann31c21f92013-05-08 09:21:53 -0700505 <LEFTPAREN> (<VARIABLE>
506 {
507 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700508 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700509 paramList.add(var);
510 getCurrentScope().addNewVarSymbolToScope(var);
511 }
Till Westmann96c1f172013-08-01 02:05:48 -0700512 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700513 {
514 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700515 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700516 paramList.add(var);
517 getCurrentScope().addNewVarSymbolToScope(var);
518 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700519 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700520 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700521 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700522 }
523}
524
525boolean IfNotExists() throws ParseException:
526{
527}
528{
529 ( "if not exists"
530 {
531 return true;
532 }
533 )?
534 {
535 return false;
536 }
537}
538
539FunctionSignature ApplyFunction() throws ParseException:
540{
541 FunctionSignature funcSig = null;
542}
543{
544 "apply" "function" funcSig = FunctionSignature()
545 {
546 return funcSig;
547 }
548}
549
ramangrover29566b3a92013-05-28 09:07:10 -0700550String GetPolicy() throws ParseException:
551{
552 String policy = null;
553}
554{
555 "using" "policy" policy = Identifier()
556 {
557 return policy;
558 }
559
560}
561
Till Westmann31c21f92013-05-08 09:21:53 -0700562FunctionSignature FunctionSignature() throws ParseException:
563{
ramangrover299f76a5e2013-06-18 10:25:17 -0700564 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700565 int arity = 0;
566}
567{
ramangrover299f76a5e2013-06-18 10:25:17 -0700568 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700569 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700570 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700571 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
572 throw new ParseException(" invalid arity:" + arity);
573 }
574
ramangrover299f76a5e2013-06-18 10:25:17 -0700575 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700576 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
577 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700578 }
579}
580
581List<String> PrimaryKey() throws ParseException:
582{
Till Westmann14a20a72013-05-09 00:06:24 -0700583 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700584 List<String> primaryKeyFields = new ArrayList<String>();
585}
586{
Till Westmann14a20a72013-05-09 00:06:24 -0700587 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700588 {
Till Westmann14a20a72013-05-09 00:06:24 -0700589 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700590 }
Till Westmann96c1f172013-08-01 02:05:48 -0700591 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700592 {
Till Westmann14a20a72013-05-09 00:06:24 -0700593 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700594 }
595 )*
596 {
597 return primaryKeyFields;
598 }
599}
600
601Statement DropStatement() throws ParseException:
602{
Till Westmann14a20a72013-05-09 00:06:24 -0700603 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700604 Pair<Identifier,Identifier> pairId = null;
605 Triple<Identifier,Identifier,Identifier> tripleId = null;
606 FunctionSignature funcSig = null;
607 boolean ifExists = false;
608 Statement stmt = null;
609}
610{
611 "drop"
612 (
613 <DATASET> pairId = QualifiedName() ifExists = IfExists()
614 {
615 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
616 }
617 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
618 {
619 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
620 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700621 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700622 {
Till Westmann14a20a72013-05-09 00:06:24 -0700623 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700624 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700625 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700626 {
627 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
628 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700629 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700630 {
Till Westmann14a20a72013-05-09 00:06:24 -0700631 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700632 }
633 | "function" funcSig = FunctionSignature() ifExists = IfExists()
634 {
635 stmt = new FunctionDropStatement(funcSig, ifExists);
636 }
ramangrover29a774ef22013-07-17 09:29:18 -0700637 | "feed" pairId = QualifiedName() ifExists = IfExists()
638 {
639 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
640 }
Till Westmann31c21f92013-05-08 09:21:53 -0700641 )
642 {
643 return stmt;
644 }
645}
646
647boolean IfExists() throws ParseException :
648{
649}
650{
Till Westmann96c1f172013-08-01 02:05:48 -0700651 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700652 {
653 return true;
654 }
655 )?
656 {
657 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000658 }
659}
660
661InsertStatement InsertStatement() throws ParseException:
662{
Till Westmann31c21f92013-05-08 09:21:53 -0700663 Pair<Identifier,Identifier> nameComponents = null;
664 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000665}
666{
Till Westmann31c21f92013-05-08 09:21:53 -0700667 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
668 {
669 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
670 }
vinayakb38b7ca42012-03-05 05:44:15 +0000671}
672
673DeleteStatement DeleteStatement() throws ParseException:
674{
Till Westmann31c21f92013-05-08 09:21:53 -0700675 VariableExpr var = null;
676 Expression condition = null;
677 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000678}
679{
Till Westmann31c21f92013-05-08 09:21:53 -0700680 "delete" var = Variable()
681 {
682 getCurrentScope().addNewVarSymbolToScope(var.getVar());
683 }
684 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700685 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700686 {
687 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
688 }
vinayakb38b7ca42012-03-05 05:44:15 +0000689}
690
691UpdateStatement UpdateStatement() throws ParseException:
692{
Till Westmann31c21f92013-05-08 09:21:53 -0700693 VariableExpr vars;
694 Expression target;
695 Expression condition;
696 UpdateClause uc;
697 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000698}
699{
Till Westmann96c1f172013-08-01 02:05:48 -0700700 "update" vars = Variable() <IN> target = Expression()
701 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700702 <LEFTPAREN> (uc = UpdateClause()
703 {
704 ucs.add(uc);
705 }
Till Westmann96c1f172013-08-01 02:05:48 -0700706 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700707 {
708 ucs.add(uc);
709 }
710 )*) <RIGHTPAREN>
711 {
712 return new UpdateStatement(vars, target, condition, ucs);
713 }
vinayakb38b7ca42012-03-05 05:44:15 +0000714}
715
vinayakb38b7ca42012-03-05 05:44:15 +0000716UpdateClause UpdateClause() throws ParseException:
717{
Till Westmann31c21f92013-05-08 09:21:53 -0700718 Expression target = null;
719 Expression value = null ;
720 InsertStatement is = null;
721 DeleteStatement ds = null;
722 UpdateStatement us = null;
723 Expression condition = null;
724 UpdateClause ifbranch = null;
725 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000726}
727{
Till Westmann96c1f172013-08-01 02:05:48 -0700728 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700729 | is = InsertStatement()
730 | ds = DeleteStatement()
731 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700732 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
733 <THEN> ifbranch = UpdateClause()
734 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700735 {
736 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
737 }
vinayakb38b7ca42012-03-05 05:44:15 +0000738}
739
vinayakb38b7ca42012-03-05 05:44:15 +0000740Statement SetStatement() throws ParseException:
741{
742 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700743 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000744}
745{
Till Westmann7d535322013-05-09 00:40:02 -0700746 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700747 {
Till Westmann31c21f92013-05-08 09:21:53 -0700748 return new SetStatement(pn, pv);
749 }
vinayakb38b7ca42012-03-05 05:44:15 +0000750}
751
752Statement WriteStatement() throws ParseException:
753{
Till Westmann14a20a72013-05-09 00:06:24 -0700754 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000755 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000756 Query query;
757 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000758 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000759}
760{
Till Westmann96c1f172013-08-01 02:05:48 -0700761 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700762 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700763 {
764 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000765 }
766}
767
vinayakb38b7ca42012-03-05 05:44:15 +0000768LoadFromFileStatement LoadStatement() throws ParseException:
769{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000770 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000771 Identifier datasetName = null;
772 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000773 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000774 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000775 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000776}
777{
Till Westmann31c21f92013-05-08 09:21:53 -0700778 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000779 {
Till Westmann31c21f92013-05-08 09:21:53 -0700780 dataverseName = nameComponents.first;
781 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000782 }
Till Westmann31c21f92013-05-08 09:21:53 -0700783 "using" adapterName = AdapterName() properties = Configuration()
784 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000785 {
Till Westmann31c21f92013-05-08 09:21:53 -0700786 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000787 }
788 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700789 {
790 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
791 }
vinayakb38b7ca42012-03-05 05:44:15 +0000792}
793
vinayakb38b7ca42012-03-05 05:44:15 +0000794
Till Westmann31c21f92013-05-08 09:21:53 -0700795String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000796{
ramangrover29669d8f62013-02-11 06:03:32 +0000797 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000798}
799{
Till Westmann68d99652013-05-09 11:15:21 -0700800 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000801 {
Till Westmann7d535322013-05-09 00:40:02 -0700802 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000803 }
vinayakb38b7ca42012-03-05 05:44:15 +0000804}
805
Till Westmann31c21f92013-05-08 09:21:53 -0700806Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000807{
ramangrover29a774ef22013-07-17 09:29:18 -0700808 Pair<Identifier,Identifier> feedNameComponents = null;
809 Pair<Identifier,Identifier> datasetNameComponents = null;
810
Till Westmann31c21f92013-05-08 09:21:53 -0700811 Map<String,String> configuration = null;
812 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700813 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000814}
815{
Till Westmann31c21f92013-05-08 09:21:53 -0700816 (
ramangrover29a774ef22013-07-17 09:29:18 -0700817 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700818 {
ramangrover29a774ef22013-07-17 09:29:18 -0700819 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700820 }
ramangrover29a774ef22013-07-17 09:29:18 -0700821 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700822 {
ramangrover29a774ef22013-07-17 09:29:18 -0700823 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700824 }
825 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000826 {
Till Westmann31c21f92013-05-08 09:21:53 -0700827 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000828 }
829}
830
Till Westmann31c21f92013-05-08 09:21:53 -0700831Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000832{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000833 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700834 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000835}
836{
Till Westmann31c21f92013-05-08 09:21:53 -0700837 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000838 {
Till Westmann31c21f92013-05-08 09:21:53 -0700839 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000840 }
Till Westmann96c1f172013-08-01 02:05:48 -0700841 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000842 {
Till Westmann31c21f92013-05-08 09:21:53 -0700843 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000844 }
Till Westmann31c21f92013-05-08 09:21:53 -0700845 )* )? <RIGHTPAREN>
846 {
847 return configuration;
848 }
849}
850
851Pair<String, String> KeyValuePair() throws ParseException:
852{
853 String key;
854 String value;
855}
856{
Till Westmann96c1f172013-08-01 02:05:48 -0700857 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700858 {
859 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000860 }
Till Westmann31c21f92013-05-08 09:21:53 -0700861}
862
863Map<String,String> Properties() throws ParseException:
864{
865 Map<String,String> properties = new HashMap<String,String>();
866 Pair<String, String> property;
867}
868{
869 ( <LEFTPAREN> property = Property()
870 {
871 properties.put(property.first, property.second);
872 }
Till Westmann96c1f172013-08-01 02:05:48 -0700873 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700874 {
875 properties.put(property.first, property.second);
876 }
877 )* <RIGHTPAREN> )?
878 {
879 return properties;
880 }
881}
882
883Pair<String, String> Property() throws ParseException:
884{
885 String key;
886 String value;
887}
888{
Till Westmann96c1f172013-08-01 02:05:48 -0700889 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700890 {
891 try {
892 value = "" + Long.valueOf(token.image);
893 } catch (NumberFormatException nfe) {
894 throw new ParseException("inapproriate value: " + token.image);
895 }
896 }
897 )
898 {
899 return new Pair<String, String>(key.toUpperCase(), value);
900 }
vinayakb38b7ca42012-03-05 05:44:15 +0000901}
902
903TypeExpression TypeExpr() throws ParseException:
904{
905 TypeExpression typeExpr = null;
906}
907{
908 (
909 typeExpr = RecordTypeDef()
910 | typeExpr = TypeReference()
911 | typeExpr = OrderedListTypeDef()
912 | typeExpr = UnorderedListTypeDef()
913 )
914 {
915 return typeExpr;
916 }
917}
918
919RecordTypeDefinition RecordTypeDef() throws ParseException:
920{
921 RecordTypeDefinition recType = new RecordTypeDefinition();
922 RecordTypeDefinition.RecordKind recordKind = null;
923}
924{
925 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
926 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700927 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000928 {
929 String hint = getHint(token);
930 if (hint != null) {
931 String splits[] = hint.split(" +");
932 if (splits[0].equals(GEN_FIELDS_HINT)) {
933 if (splits.length != 5) {
934 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
935 }
936 if (!splits[1].equals("int")) {
937 throw new ParseException("The only supported type for gen-fields is int.");
938 }
939 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
940 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
941 recType.setUndeclaredFieldsDataGen(ufdg);
942 }
943 }
944
945 }
946 (
947 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700948 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000949 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700950 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000951 {
952 if (recordKind == null) {
953 recordKind = RecordTypeDefinition.RecordKind.OPEN;
954 }
955 recType.setRecordKind(recordKind);
956 return recType;
957 }
958}
959
960void RecordField(RecordTypeDefinition recType) throws ParseException:
961{
Till Westmann77cb2f42013-07-15 16:44:19 -0700962 String fieldName;
963 TypeExpression type = null;
964 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000965}
966{
Till Westmann77cb2f42013-07-15 16:44:19 -0700967 fieldName = Identifier()
968 {
969 String hint = getHint(token);
970 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
971 }
Till Westmann96c1f172013-08-01 02:05:48 -0700972 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -0700973 {
974 recType.addField(fieldName, type, nullable, rfdg);
975 }
vinayakb38b7ca42012-03-05 05:44:15 +0000976}
977
978TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000979{
Till Westmann14a20a72013-05-09 00:06:24 -0700980 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700981}
982{
983 id = Identifier()
984 {
Till Westmann14a20a72013-05-09 00:06:24 -0700985 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700986 }
vinayakb38b7ca42012-03-05 05:44:15 +0000987}
988
989OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
990{
991 TypeExpression type = null;
992}
993{
Till Westmann96c1f172013-08-01 02:05:48 -0700994 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000995 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -0700996 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000997 {
998 return new OrderedListTypeDefinition(type);
999 }
1000}
1001
1002
1003UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1004{
1005 TypeExpression type = null;
1006}
1007{
Till Westmann96c1f172013-08-01 02:05:48 -07001008 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001009 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001010 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001011 {
1012 return new UnorderedListTypeDefinition(type);
1013 }
1014}
1015
ramangrover299f76a5e2013-06-18 10:25:17 -07001016FunctionName FunctionName() throws ParseException:
1017{
1018 String first = null;
1019 String second = null;
1020 String third = null;
1021 boolean secondAfterDot = false;
1022}
1023{
zheilbron555dc9d2013-08-14 19:58:00 -07001024 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001025 {
1026 secondAfterDot = true;
1027 }
1028 ("#" third = Identifier())? | "#" second = Identifier() )?
1029 {
1030 FunctionName result = new FunctionName();
1031 if (second == null) {
1032 result.dataverse = defaultDataverse;
1033 result.library = null;
1034 result.function = first;
1035 } else if (third == null) {
1036 if (secondAfterDot) {
1037 result.dataverse = first;
1038 result.library = null;
1039 result.function = second;
1040 } else {
1041 result.dataverse = defaultDataverse;
1042 result.library = first;
1043 result.function = second;
1044 }
1045 } else {
1046 result.dataverse = first;
1047 result.library = second;
1048 result.function = third;
1049 }
1050 return result;
1051 }
1052}
Till Westmann31c21f92013-05-08 09:21:53 -07001053
ramangrover299f76a5e2013-06-18 10:25:17 -07001054
1055Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001056{
Till Westmann31c21f92013-05-08 09:21:53 -07001057 Pair<Identifier,Identifier> name = null;
1058}
1059{
1060 name = QualifiedName()
1061 {
1062 if (name.first == null) {
1063 name.first = new Identifier(defaultDataverse);
1064 }
1065 return name;
1066 }
1067}
1068
Till Westmann14a20a72013-05-09 00:06:24 -07001069String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001070{
Till Westmann68d99652013-05-09 11:15:21 -07001071 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001072}
1073{
1074 <IDENTIFIER>
1075 {
Till Westmann14a20a72013-05-09 00:06:24 -07001076 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001077 }
Till Westmann68d99652013-05-09 11:15:21 -07001078 | lit = StringLiteral()
1079 {
1080 return lit;
1081 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001082}
1083
Till Westmann7d535322013-05-09 00:40:02 -07001084String StringLiteral() throws ParseException:
1085{
1086}
1087{
1088 <STRING_LITERAL>
1089 {
1090 return removeQuotesAndEscapes(token.image);
1091 }
1092}
1093
Till Westmann31c21f92013-05-08 09:21:53 -07001094Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1095{
Till Westmann14a20a72013-05-09 00:06:24 -07001096 String first = null;
1097 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001098}
1099{
Till Westmann96c1f172013-08-01 02:05:48 -07001100 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001101 {
Till Westmann14a20a72013-05-09 00:06:24 -07001102 Identifier id1 = null;
1103 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001104 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001105 id2 = new Identifier(first);
1106 } else
1107 {
1108 id1 = new Identifier(first);
1109 id2 = new Identifier(second);
1110 }
1111 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001112 }
1113}
1114
Till Westmann31c21f92013-05-08 09:21:53 -07001115Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001116{
Till Westmann14a20a72013-05-09 00:06:24 -07001117 String first = null;
1118 String second = null;
1119 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001120}
1121{
Till Westmann96c1f172013-08-01 02:05:48 -07001122 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001123 {
Till Westmann14a20a72013-05-09 00:06:24 -07001124 Identifier id1 = null;
1125 Identifier id2 = null;
1126 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001127 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001128 id2 = new Identifier(first);
1129 id3 = new Identifier(second);
1130 } else {
1131 id1 = new Identifier(first);
1132 id2 = new Identifier(second);
1133 id3 = new Identifier(third);
1134 }
1135 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001136 }
1137}
1138
vinayakb38b7ca42012-03-05 05:44:15 +00001139FunctionDecl FunctionDeclaration() throws ParseException:
1140{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001141 FunctionDecl funcDecl;
1142 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001143 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001144 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1145 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001146 createNewScope();
1147}
1148{
Till Westmannd7dcb122013-05-16 13:19:09 -07001149 "declare" "function" functionName = Identifier()
1150 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001151 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001152 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001153 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001154 getCurrentScope().addFunctionDescriptor(signature, false);
1155 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001156 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001157 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001158 }
1159}
1160
vinayakb38b7ca42012-03-05 05:44:15 +00001161
Till Westmann31c21f92013-05-08 09:21:53 -07001162Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001163{
1164 Query query = new Query();
1165 Expression expr;
1166}
1167{
Till Westmann31c21f92013-05-08 09:21:53 -07001168 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001169 {
1170 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001171 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001172 return query;
1173 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001174
vinayakb38b7ca42012-03-05 05:44:15 +00001175}
1176
1177
1178
1179Expression Expression():
1180{
1181 Expression expr = null;
1182 Expression exprP = null;
1183}
1184{
1185(
1186
1187//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1188 expr = OperatorExpr()
1189 | expr = IfThenElse()
1190 | expr = FLWOGR()
1191 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001192
vinayakb38b7ca42012-03-05 05:44:15 +00001193
1194)
1195 {
1196 return (exprP==null) ? expr : exprP;
1197 }
1198}
1199
1200
1201
1202Expression OperatorExpr()throws ParseException:
1203{
1204 OperatorExpr op = null;
1205 Expression operand = null;
1206}
1207{
1208 operand = AndExpr()
1209 (
1210
Till Westmann96c1f172013-08-01 02:05:48 -07001211 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001212 {
1213 if (op == null) {
1214 op = new OperatorExpr();
1215 op.addOperand(operand);
1216 op.setCurrentop(true);
1217 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001218 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001219 }
1220
1221 operand = AndExpr()
1222 {
1223 op.addOperand(operand);
1224 }
1225
1226 )*
1227
1228 {
1229 return op==null? operand: op;
1230 }
1231}
1232
1233Expression AndExpr()throws ParseException:
1234{
1235 OperatorExpr op = null;
1236 Expression operand = null;
1237}
1238{
1239 operand = RelExpr()
1240 (
1241
Till Westmann96c1f172013-08-01 02:05:48 -07001242 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001243 {
1244 if (op == null) {
1245 op = new OperatorExpr();
1246 op.addOperand(operand);
1247 op.setCurrentop(true);
1248 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001249 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001250 }
1251
1252 operand = RelExpr()
1253 {
1254 op.addOperand(operand);
1255 }
1256
1257 )*
1258
1259 {
1260 return op==null? operand: op;
1261 }
1262}
1263
1264
1265
1266Expression RelExpr()throws ParseException:
1267{
1268 OperatorExpr op = null;
1269 Expression operand = null;
1270 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001271 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001272}
1273{
1274 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001275 {
1276 if (operand instanceof VariableExpr) {
1277 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001278 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001279 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001280 }
1281 }
1282 }
1283
1284 (
Till Westmann96c1f172013-08-01 02:05:48 -07001285 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001286 {
alexander.behm07617fd2012-07-25 10:13:50 +00001287 String mhint = getHint(token);
1288 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1289 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1290 }
vinayakb38b7ca42012-03-05 05:44:15 +00001291 if (op == null) {
1292 op = new OperatorExpr();
1293 op.addOperand(operand, broadcast);
1294 op.setCurrentop(true);
1295 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001296 }
1297 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001298 }
1299
1300 operand = AddExpr()
1301 {
alexander.behm07617fd2012-07-25 10:13:50 +00001302 broadcast = false;
1303 if (operand instanceof VariableExpr) {
1304 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001305 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1306 broadcast = true;
1307 }
alexander.behm07617fd2012-07-25 10:13:50 +00001308 }
vinayakb38b7ca42012-03-05 05:44:15 +00001309 op.addOperand(operand, broadcast);
1310 }
1311 )?
1312
1313 {
alexander.behm07617fd2012-07-25 10:13:50 +00001314 if (annotation != null) {
1315 op.addHint(annotation);
1316 }
vinayakb38b7ca42012-03-05 05:44:15 +00001317 return op==null? operand: op;
1318 }
1319}
1320
1321Expression AddExpr()throws ParseException:
1322{
1323 OperatorExpr op = null;
1324 Expression operand = null;
1325}
1326{
1327 operand = MultExpr()
1328
Till Westmann96c1f172013-08-01 02:05:48 -07001329 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001330 {
1331 if (op == null) {
1332 op = new OperatorExpr();
1333 op.addOperand(operand);
1334 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001335 }
1336 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001337 }
1338
1339 operand = MultExpr()
1340 {
1341 op.addOperand(operand);
1342 }
1343 )*
1344
1345 {
1346 return op==null? operand: op;
1347 }
1348}
1349
1350Expression MultExpr()throws ParseException:
1351{
1352 OperatorExpr op = null;
1353 Expression operand = null;
1354}
1355{
1356 operand = UnionExpr()
1357
Till Westmann96c1f172013-08-01 02:05:48 -07001358 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001359 {
1360 if (op == null) {
1361 op = new OperatorExpr();
1362 op.addOperand(operand);
1363 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001364 }
1365 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001366 }
1367 operand = UnionExpr()
1368 {
1369 op.addOperand(operand);
1370 }
1371 )*
1372
1373 {
1374 return op==null?operand:op;
1375 }
1376}
1377
1378Expression UnionExpr() throws ParseException:
1379{
1380 UnionExpr union = null;
1381 Expression operand1 = null;
1382 Expression operand2 = null;
1383}
1384{
1385 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001386 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001387 (operand2 = UnaryExpr()) {
1388 if (union == null) {
1389 union = new UnionExpr();
1390 union.addExpr(operand1);
1391 }
1392 union.addExpr(operand2);
1393 } )*
1394 {
1395 return (union == null)? operand1: union;
1396 }
1397}
1398
1399Expression UnaryExpr() throws ParseException:
1400{
1401 Expression uexpr = null;
1402 Expression expr = null;
1403}
1404{
Till Westmann96c1f172013-08-01 02:05:48 -07001405 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001406 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001407 uexpr = new UnaryExpr();
1408 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001409 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001410 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001411 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1412 else
1413 throw new ParseException();
1414 }
1415 )?
1416
1417 expr = ValueExpr()
1418 {
1419 if(uexpr!=null){
1420 ((UnaryExpr)uexpr).setExpr(expr);
1421 return uexpr;
1422 }
1423 else{
1424 return expr;
1425 }
1426 }
1427}
1428
Till Westmann04478e72013-05-13 23:01:34 -07001429Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001430{
1431 Expression expr = null;
1432 Identifier ident = null;
1433 AbstractAccessor fa = null;
1434 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001435}
1436{
Till Westmann04478e72013-05-13 23:01:34 -07001437 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001438 {
Till Westmann04478e72013-05-13 23:01:34 -07001439 fa = (fa == null ? new FieldAccessor(expr, ident)
1440 : new FieldAccessor(fa, ident));
1441 }
1442 | index = Index()
1443 {
1444 fa = (fa == null ? new IndexAccessor(expr, index)
1445 : new IndexAccessor(fa, index));
1446 }
1447 )*
1448 {
1449 return fa == null ? expr : fa;
1450 }
vinayakb38b7ca42012-03-05 05:44:15 +00001451}
1452
1453Identifier Field() throws ParseException:
1454{
Till Westmann14a20a72013-05-09 00:06:24 -07001455 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001456}
1457{
Till Westmann96c1f172013-08-01 02:05:48 -07001458 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001459 {
Till Westmann14a20a72013-05-09 00:06:24 -07001460 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001461 }
vinayakb38b7ca42012-03-05 05:44:15 +00001462}
1463
1464int Index() throws ParseException:
1465{
1466 Expression expr = null;
1467 int idx = -2;
1468}
1469{
Till Westmann96c1f172013-08-01 02:05:48 -07001470 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001471 {
1472 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1473 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001474 Literal lit = ((LiteralExpr)expr).getValue();
1475 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1476 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001477 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001478 }
vinayakb38b7ca42012-03-05 05:44:15 +00001479 else {
1480 throw new ParseException("Index should be an INTEGER");
1481 }
1482 }
1483
1484 }
1485
Till Westmann96c1f172013-08-01 02:05:48 -07001486 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001487 {
1488 idx = IndexAccessor.ANY;
1489 // ANY
1490 }
1491
1492 )
1493
Till Westmann96c1f172013-08-01 02:05:48 -07001494 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001495 {
1496 return idx;
1497 }
1498}
1499
1500
1501Expression PrimaryExpr()throws ParseException:
1502{
1503 Expression expr = null;
1504}
1505{
Till Westmann68d99652013-05-09 11:15:21 -07001506 ( LOOKAHEAD(2)
1507 expr = FunctionCallExpr()
1508 | expr = Literal()
1509 | expr = DatasetAccessExpression()
1510 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001511 {
1512 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001513 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001514 }
Till Westmann68d99652013-05-09 11:15:21 -07001515 | expr = ListConstructor()
1516 | expr = RecordConstructor()
1517 | expr = ParenthesizedExpression()
1518 )
1519 {
1520 return expr;
1521 }
vinayakb38b7ca42012-03-05 05:44:15 +00001522}
1523
1524Expression Literal() throws ParseException:
1525{
vinayakb38b7ca42012-03-05 05:44:15 +00001526 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001527 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001528}
1529{
Till Westmann7d535322013-05-09 00:40:02 -07001530 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001531 {
Till Westmann7d535322013-05-09 00:40:02 -07001532 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001533 }
1534 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001535 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001536 try {
1537 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1538 } catch(NumberFormatException ex) {
1539 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1540 }
1541 }
1542 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001543 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001544 lit.setValue(new FloatLiteral(new Float(token.image)));
1545 }
1546 | <DOUBLE_LITERAL>
1547 {
1548 lit.setValue(new DoubleLiteral(new Double(token.image)));
1549 }
1550 | <NULL>
1551 {
1552 lit.setValue(NullLiteral.INSTANCE);
1553 }
1554 | <TRUE>
1555 {
1556 lit.setValue(TrueLiteral.INSTANCE);
1557 }
1558 | <FALSE>
1559 {
1560 lit.setValue(FalseLiteral.INSTANCE);
1561 }
1562 )
vinayakb38b7ca42012-03-05 05:44:15 +00001563 {
1564 return lit;
1565 }
1566}
1567
1568
1569VariableExpr VariableRef() 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 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001578 Identifier ident = lookupSymbol(varName);
1579 if (isInForbiddenScopes(varName)) {
1580 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.");
1581 }
1582 if(ident != null) { // exist such ident
1583 varExp.setIsNewVar(false);
1584 varExp.setVar((VarIdentifier)ident);
1585 } else {
1586 varExp.setVar(var);
1587 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001588 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001589 return varExp;
1590 }
1591}
1592
1593
1594VariableExpr Variable() throws ParseException:
1595{
1596 VariableExpr varExp = new VariableExpr();
1597 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001598}
1599{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001600 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001601 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001602 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001603 if(ident != null) { // exist such ident
1604 varExp.setIsNewVar(false);
1605 }
1606 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001607 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001608 return varExp;
1609 }
1610}
1611
1612Expression ListConstructor() throws ParseException:
1613{
1614 Expression expr = null;
1615}
1616{
1617 (
1618 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1619 )
1620
1621 {
1622 return expr;
1623 }
1624}
1625
1626
1627ListConstructor OrderedListConstructor() throws ParseException:
1628{
1629 ListConstructor expr = new ListConstructor();
1630 Expression tmp = null;
1631 List<Expression> exprList = new ArrayList<Expression>();
1632 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1633}
1634{
1635
Till Westmann96c1f172013-08-01 02:05:48 -07001636 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001637 ( tmp = Expression()
1638 {
1639 exprList.add(tmp);
1640 }
1641
Till Westmann96c1f172013-08-01 02:05:48 -07001642 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001643 )?
1644
Till Westmann96c1f172013-08-01 02:05:48 -07001645 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001646
1647 {
1648 expr.setExprList(exprList);
1649 return expr;
1650 }
1651}
1652
1653ListConstructor UnorderedListConstructor() throws ParseException:
1654{
1655 ListConstructor expr = new ListConstructor();
1656 Expression tmp = null;
1657 List<Expression> exprList = new ArrayList<Expression>();
1658 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1659}
1660{
1661
Till Westmann96c1f172013-08-01 02:05:48 -07001662 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001663 {
1664 exprList.add(tmp);
1665 }
Till Westmann96c1f172013-08-01 02:05:48 -07001666 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001667 {
1668 expr.setExprList(exprList);
1669 return expr;
1670 }
1671}
1672
1673RecordConstructor RecordConstructor() throws ParseException:
1674{
1675 RecordConstructor expr = new RecordConstructor();
1676 FieldBinding tmp = null;
1677 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1678}
1679{
Till Westmann96c1f172013-08-01 02:05:48 -07001680 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001681 {
1682 fbList.add(tmp);
1683 }
Till Westmann96c1f172013-08-01 02:05:48 -07001684 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001685 {
1686 expr.setFbList(fbList);
1687 return expr;
1688 }
1689}
1690
1691FieldBinding FieldBinding() throws ParseException:
1692{
1693 FieldBinding fb = new FieldBinding();
1694 Expression left, right;
1695}
1696{
Till Westmann96c1f172013-08-01 02:05:48 -07001697 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001698 {
1699 fb.setLeftExpr(left);
1700 fb.setRightExpr(right);
1701 return fb;
1702 }
1703}
1704
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001705
vinayakb38b7ca42012-03-05 05:44:15 +00001706Expression FunctionCallExpr() throws ParseException:
1707{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001708 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001709 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001710 Expression tmp;
1711 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001712 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001713 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001714}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001715{
ramangrover299f76a5e2013-06-18 10:25:17 -07001716 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001717 {
Till Westmann31c21f92013-05-08 09:21:53 -07001718 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001719 }
Till Westmann31c21f92013-05-08 09:21:53 -07001720 <LEFTPAREN> (tmp = Expression()
1721 {
1722 argList.add(tmp);
1723 arity ++;
1724 }
Till Westmann96c1f172013-08-01 02:05:48 -07001725 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001726 {
1727 argList.add(tmp);
1728 arity++;
1729 }
1730 )*)? <RIGHTPAREN>
1731 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001732 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001733 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001734 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001735 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001736 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001737 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001738 }
1739 callExpr = new CallExpr(signature,argList);
1740 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1741 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1742 }
1743 return callExpr;
1744 }
vinayakb38b7ca42012-03-05 05:44:15 +00001745}
1746
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001747
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001748Expression DatasetAccessExpression() throws ParseException:
1749{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001750 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001751 String arg1 = null;
1752 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001753 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001754}
1755{
Till Westmann14a20a72013-05-09 00:06:24 -07001756 <DATASET>
1757 {
Till Westmann14a20a72013-05-09 00:06:24 -07001758 funcName = token.image;
1759 }
Till Westmann96c1f172013-08-01 02:05:48 -07001760 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001761 {
1762 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001763 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001764 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001765 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001766 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001767 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001768 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001769 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1770 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1771 if (signature == null) {
1772 signature = new FunctionSignature(dataverse, funcName, 1);
1773 }
1774 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001775 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001776 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001777 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001778}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001779
vinayakb38b7ca42012-03-05 05:44:15 +00001780Expression ParenthesizedExpression() throws ParseException:
1781{
1782 Expression expr;
1783}
1784{
1785 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1786 {
1787 return expr;
1788 }
1789}
1790
1791Expression IfThenElse() throws ParseException:
1792{
1793 Expression condExpr;
1794 Expression thenExpr;
1795 Expression elseExpr;
1796 IfExpr ifExpr = new IfExpr();
1797}
1798{
Till Westmann96c1f172013-08-01 02:05:48 -07001799 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001800
1801 {
1802 ifExpr.setCondExpr(condExpr);
1803 ifExpr.setThenExpr(thenExpr);
1804 ifExpr.setElseExpr(elseExpr);
1805 return ifExpr;
1806 }
1807}
1808
1809Expression FLWOGR() throws ParseException:
1810{
1811 FLWOGRExpression flworg = new FLWOGRExpression();
1812 List<Clause> clauseList = new ArrayList<Clause>();
1813 Expression returnExpr;
1814 Clause tmp;
1815 createNewScope();
1816}
1817{
1818 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001819 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001820
1821 {
1822 flworg.setClauseList(clauseList);
1823 flworg.setReturnExpr(returnExpr);
1824 removeCurrentScope();
1825 return flworg;
1826 }
1827}
1828
1829Clause Clause()throws ParseException :
1830{
1831 Clause clause;
1832}
1833{
1834 (
1835 clause = ForClause()
1836 | clause = LetClause()
1837 | clause = WhereClause()
1838 | clause = OrderbyClause()
1839 | clause = GroupClause()
1840 | clause = LimitClause()
1841 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001842 )
1843 {
1844 return clause;
1845 }
1846}
1847
1848Clause ForClause()throws ParseException :
1849{
1850 ForClause fc = new ForClause();
1851 VariableExpr varExp;
1852 VariableExpr varPos = null;
1853 Expression inExp;
1854 extendCurrentScope();
1855}
1856{
Till Westmann96c1f172013-08-01 02:05:48 -07001857 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001858 {
1859 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001860 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001861 fc.setInExpr(inExp);
1862 if (varPos != null) {
1863 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001864 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001865 }
1866 return fc;
1867 }
1868}
1869
1870Clause LetClause() throws ParseException:
1871{
1872 LetClause lc = new LetClause();
1873 VariableExpr varExp;
1874 Expression beExp;
1875 extendCurrentScope();
1876}
1877{
Till Westmann96c1f172013-08-01 02:05:48 -07001878 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001879 {
1880 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001881 lc.setVarExpr(varExp);
1882 lc.setBeExpr(beExp);
1883 return lc;
1884 }
1885}
1886
1887Clause WhereClause()throws ParseException :
1888{
1889 WhereClause wc = new WhereClause();
1890 Expression whereExpr;
1891}
1892{
Till Westmann96c1f172013-08-01 02:05:48 -07001893 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001894 {
1895 wc.setWhereExpr(whereExpr);
1896 return wc;
1897 }
1898}
1899
1900Clause OrderbyClause()throws ParseException :
1901{
1902 OrderbyClause oc = new OrderbyClause();
1903 Expression orderbyExpr;
1904 List<Expression> orderbyList = new ArrayList<Expression>();
1905 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1906 int numOfOrderby = 0;
1907}
1908{
1909 (
Till Westmann96c1f172013-08-01 02:05:48 -07001910 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001911 {
1912 String hint = getHint(token);
1913 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1914 String splits[] = hint.split(" +");
1915 int numFrames = Integer.parseInt(splits[1]);
1916 int numTuples = Integer.parseInt(splits[2]);
1917 oc.setNumFrames(numFrames);
1918 oc.setNumTuples(numTuples);
1919 }
1920 }
Till Westmann96c1f172013-08-01 02:05:48 -07001921 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001922 {
1923 orderbyList.add(orderbyExpr);
1924 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1925 }
Till Westmann96c1f172013-08-01 02:05:48 -07001926 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1927 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001928 {
1929 modifierList.add(modif);
1930 }
1931
Till Westmann96c1f172013-08-01 02:05:48 -07001932 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001933 {
1934 orderbyList.add(orderbyExpr);
1935 modif = OrderbyClause.OrderModifier.ASC;
1936 }
Till Westmann96c1f172013-08-01 02:05:48 -07001937 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1938 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001939 {
1940 modifierList.add(modif);
1941 }
1942 )*
1943)
1944 {
1945 oc.setModifierList(modifierList);
1946 oc.setOrderbyList(orderbyList);
1947 return oc;
1948 }
1949}
1950Clause GroupClause()throws ParseException :
1951{
1952 GroupbyClause gbc = new GroupbyClause();
1953 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1954 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1955 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1956 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1957 VariableExpr var = null;
1958 VariableExpr withVar = null;
1959 Expression expr = null;
1960 VariableExpr decorVar = null;
1961 Expression decorExpr = null;
1962}
1963{
1964 {
1965 Scope newScope = extendCurrentScopeNoPush(true);
1966 // extendCurrentScope(true);
1967 }
Till Westmann96c1f172013-08-01 02:05:48 -07001968 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00001969 {
1970 String hint = getHint(token);
1971 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1972 gbc.setHashGroupByHint(true);
1973 }
1974 }
Till Westmann96c1f172013-08-01 02:05:48 -07001975 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001976 {
1977 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001978 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001979 expr = Expression()
1980 {
1981 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1982 vePairList.add(pair1);
1983 }
Till Westmann96c1f172013-08-01 02:05:48 -07001984 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001985 {
1986 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001987 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001988 expr = Expression()
1989 {
1990 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1991 vePairList.add(pair2);
1992 }
1993 )*
Till Westmann96c1f172013-08-01 02:05:48 -07001994 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001995 {
1996 newScope.addNewVarSymbolToScope(decorVar.getVar());
1997 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1998 decorPairList.add(pair3);
1999 }
Till Westmann96c1f172013-08-01 02:05:48 -07002000 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002001 {
2002 newScope.addNewVarSymbolToScope(decorVar.getVar());
2003 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2004 decorPairList.add(pair4);
2005 }
2006 )*
2007 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002008 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002009 {
2010 if(withVar.getIsNewVar()==true)
2011 throw new ParseException("can't find variable " + withVar.getVar());
2012 withVarList.add(withVar);
2013 newScope.addNewVarSymbolToScope(withVar.getVar());
2014 }
Till Westmann96c1f172013-08-01 02:05:48 -07002015 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002016 {
2017 if(withVar.getIsNewVar()==true)
2018 throw new ParseException("can't find variable " + withVar.getVar());
2019 withVarList.add(withVar);
2020 newScope.addNewVarSymbolToScope(withVar.getVar());
2021 })*
2022 {
2023 gbc.setGbyPairList(vePairList);
2024 gbc.setDecorPairList(decorPairList);
2025 gbc.setWithVarList(withVarList);
2026 replaceCurrentScope(newScope);
2027 return gbc;
2028 }
2029}
2030
2031
2032LimitClause LimitClause() throws ParseException:
2033{
2034 LimitClause lc = new LimitClause();
2035 Expression expr;
2036 pushForbiddenScope(getCurrentScope());
2037}
2038{
Till Westmann96c1f172013-08-01 02:05:48 -07002039 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2040 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002041
2042 {
2043 popForbiddenScope();
2044 return lc;
2045 }
2046}
2047
2048DistinctClause DistinctClause() throws ParseException:
2049{
2050 List<Expression> exprs = new ArrayList<Expression>();
2051 Expression expr;
2052}
2053{
Till Westmann96c1f172013-08-01 02:05:48 -07002054 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002055 {
2056 exprs.add(expr);
2057 }
Till Westmann96c1f172013-08-01 02:05:48 -07002058 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002059 {
2060 exprs.add(expr);
2061 }
2062 )*
2063 {
2064 return new DistinctClause(exprs);
2065 }
2066}
2067
vinayakb38b7ca42012-03-05 05:44:15 +00002068QuantifiedExpression QuantifiedExpression()throws ParseException:
2069{
2070 QuantifiedExpression qc = new QuantifiedExpression();
2071 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2072 Expression satisfiesExpr;
2073 VariableExpr var;
2074 Expression inExpr;
2075 QuantifiedPair pair;
2076}
2077{
2078 {
2079 createNewScope();
2080 }
2081
Till Westmann96c1f172013-08-01 02:05:48 -07002082 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2083 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2084 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002085 {
2086 pair = new QuantifiedPair(var, inExpr);
2087 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2088 quantifiedList.add(pair);
2089 }
2090 (
Till Westmann96c1f172013-08-01 02:05:48 -07002091 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002092 {
2093 pair = new QuantifiedPair(var, inExpr);
2094 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2095 quantifiedList.add(pair);
2096 }
2097 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002098 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002099 {
2100 qc.setSatisfiesExpr(satisfiesExpr);
2101 qc.setQuantifiedList(quantifiedList);
2102 removeCurrentScope();
2103 return qc;
2104 }
2105}
2106
2107TOKEN_MGR_DECLS:
2108{
Till Westmann96c1f172013-08-01 02:05:48 -07002109 public int commentDepth = 0;
2110 public IntStack lexerStateStack = new IntStack();
2111
2112 public void pushState() {
2113 lexerStateStack.push( curLexState );
2114 }
2115
2116 public void popState() {
2117 if (lexerStateStack.size() > 0) {
2118 SwitchTo( lexerStateStack.pop() );
2119 } else {
2120 throw new RuntimeException();
2121 }
2122 }
vinayakb38b7ca42012-03-05 05:44:15 +00002123}
2124
Till Westmann96c1f172013-08-01 02:05:48 -07002125<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002126TOKEN :
2127{
Till Westmann5df7b452013-08-02 13:07:16 -07002128 <ASC : "asc">
2129 | <AT : "at">
2130 | <BY : "by">
2131 | <DATASET : "dataset">
2132 | <DECOR : "decor">
2133 | <DESC : "desc">
2134 | <DISTINCT : "distinct">
2135 | <ELSE : "else">
2136 | <EVERY : "every">
2137 | <FOR : "for">
2138 | <GROUP : "group">
2139 | <IF : "if">
2140 | <IN : "in">
2141 | <LET : "let">
2142 | <LIMIT : "limit">
2143 | <OFFSET : "offset">
2144 | <ORDER : "order">
2145 | <RETURN : "return">
2146 | <SATISFIES : "satisfies">
2147 | <SOME : "some">
2148 | <THEN : "then">
2149 | <UNION : "union">
2150 | <WHERE : "where">
2151 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002152}
2153
Till Westmann96c1f172013-08-01 02:05:48 -07002154<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002155TOKEN :
2156{
Till Westmann5df7b452013-08-02 13:07:16 -07002157 <CARET : "^">
2158 | <DIV : "/">
2159 | <IDIV : "idiv">
2160 | <MINUS : "-">
2161 | <MOD : "%">
2162 | <MUL : "*">
2163 | <PLUS : "+">
2164
2165 | <LEFTPAREN : "(">
2166 | <RIGHTPAREN : ")">
2167 | <LEFTBRACKET : "[">
2168 | <RIGHTBRACKET : "]">
2169
2170 | <COLON : ":">
2171 | <COMMA : ",">
2172 | <DOT : ".">
2173 | <QUES : "?">
2174
2175 | <LT : "<">
2176 | <GT : ">">
2177 | <LE : "<=">
2178 | <GE : ">=">
2179 | <EQ : "=">
2180 | <NE : "!=">
2181 | <SIMILAR : "~=">
2182 | <ASSIGN : ":=">
2183
2184 | <AND : "and">
2185 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002186}
2187
Till Westmann96c1f172013-08-01 02:05:48 -07002188<DEFAULT,IN_DBL_BRACE>
2189TOKEN :
2190{
Till Westmann5df7b452013-08-02 13:07:16 -07002191 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002192}
2193
2194<DEFAULT>
2195TOKEN :
2196{
Till Westmann5df7b452013-08-02 13:07:16 -07002197 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002198}
2199
Till Westmann96c1f172013-08-01 02:05:48 -07002200<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002201TOKEN :
2202{
Till Westmann5df7b452013-08-02 13:07:16 -07002203 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002204}
2205
Till Westmann96c1f172013-08-01 02:05:48 -07002206<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002207TOKEN :
2208{
Till Westmann5df7b452013-08-02 13:07:16 -07002209 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002210}
2211
Till Westmann96c1f172013-08-01 02:05:48 -07002212<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002213TOKEN :
2214{
Till Westmann5df7b452013-08-02 13:07:16 -07002215 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002216}
2217
Till Westmann96c1f172013-08-01 02:05:48 -07002218<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002219TOKEN :
2220{
Till Westmann5df7b452013-08-02 13:07:16 -07002221 <NULL : "null">
2222 | <TRUE : "true">
2223 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002224}
2225
Till Westmann96c1f172013-08-01 02:05:48 -07002226<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002227TOKEN :
2228{
Till Westmann5df7b452013-08-02 13:07:16 -07002229 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002230}
2231
Till Westmann96c1f172013-08-01 02:05:48 -07002232<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002233TOKEN:
2234{
Till Westmann5df7b452013-08-02 13:07:16 -07002235 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002236 | <DIGITS> ( "." <DIGITS> )?
2237 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002238 >
2239 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002240 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2241 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002242 >
2243 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002244}
2245
Till Westmann96c1f172013-08-01 02:05:48 -07002246<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002247TOKEN :
2248{
Till Westmann5df7b452013-08-02 13:07:16 -07002249 <#LETTER : ["A" - "Z", "a" - "z"]>
2250 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002251}
2252
Till Westmann96c1f172013-08-01 02:05:48 -07002253<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002254TOKEN :
2255{
Till Westmann5df7b452013-08-02 13:07:16 -07002256 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2257 | < #EscapeQuot: "\\\"" >
2258 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002259}
2260
Till Westmann96c1f172013-08-01 02:05:48 -07002261<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002262TOKEN :
2263{
Till Westmann5df7b452013-08-02 13:07:16 -07002264 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002265}
2266
Till Westmann96c1f172013-08-01 02:05:48 -07002267<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002268TOKEN :
2269{
Till Westmann5df7b452013-08-02 13:07:16 -07002270 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002271}
2272
Till Westmann96c1f172013-08-01 02:05:48 -07002273<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002274SKIP:
2275{
2276 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002277 | "\t"
2278 | "\r"
2279 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002280}
2281
Till Westmann96c1f172013-08-01 02:05:48 -07002282<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002283SKIP:
2284{
Till Westmann5df7b452013-08-02 13:07:16 -07002285 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002286}
2287
Till Westmann96c1f172013-08-01 02:05:48 -07002288<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002289SKIP:
2290{
Till Westmann5df7b452013-08-02 13:07:16 -07002291 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002292}
2293
Till Westmann96c1f172013-08-01 02:05:48 -07002294<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002295SKIP:
2296{
Till Westmann96c1f172013-08-01 02:05:48 -07002297 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002298}
2299
2300<INSIDE_COMMENT>
2301SPECIAL_TOKEN:
2302{
Till Westmann5df7b452013-08-02 13:07:16 -07002303 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002304}
2305
2306<INSIDE_COMMENT>
2307SKIP:
2308{
Till Westmann96c1f172013-08-01 02:05:48 -07002309 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002310}
2311
2312<INSIDE_COMMENT>
2313SKIP:
2314{
Till Westmann96c1f172013-08-01 02:05:48 -07002315 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002316 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002317}