blob: 022a5a27cab65c1aafc09aac9ff3dcce8d0f527e [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()
salsubaiee0b423fa2013-09-19 19:16:48 -0700202 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700203 | stmt = Query()
204 )
205 {
206 return stmt;
207 }
208}
209
210DataverseDecl DataverseDeclaration() throws ParseException:
211{
Till Westmann14a20a72013-05-09 00:06:24 -0700212 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700213}
214{
Till Westmanna4242bc2013-05-08 17:49:55 -0700215 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700216 {
Till Westmann14a20a72013-05-09 00:06:24 -0700217 defaultDataverse = dvName;
218 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700219 }
220}
221
222Statement CreateStatement() throws ParseException:
223{
224 String hint = null;
225 boolean dgen = false;
226 Statement stmt = null;
227}
228{
229 "create"
230 (
231 {
232 hint = getHint(token);
233 if (hint != null && hint.startsWith(DGEN_HINT)) {
234 dgen = true;
235 }
236 }
237 stmt = TypeSpecification(hint, dgen)
238 | stmt = NodegroupSpecification()
239 | stmt = DatasetSpecification()
240 | stmt = IndexSpecification()
241 | stmt = DataverseSpecification()
242 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700243 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700244 )
245 {
246 return stmt;
247 }
248}
249
250TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
251{
252 Pair<Identifier,Identifier> nameComponents = null;
253 boolean ifNotExists = false;
254 TypeExpression typeExpr = null;
255}
256{
ramangrover299f76a5e2013-06-18 10:25:17 -0700257 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700258 "as" typeExpr = TypeExpr()
259 {
260 long numValues = -1;
261 String filename = null;
262 if (dgen) {
263 String splits[] = hint.split(" +");
264 if (splits.length != 3) {
265 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
266 }
267 filename = splits[1];
268 numValues = Long.parseLong(splits[2]);
269 }
270 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
271 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
272 }
273}
274
275
276NodegroupDecl NodegroupSpecification() throws ParseException:
277{
Till Westmann14a20a72013-05-09 00:06:24 -0700278 String name = null;
279 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700280 boolean ifNotExists = false;
281 List<Identifier>ncNames = null;
282}
283{
Till Westmanna4242bc2013-05-08 17:49:55 -0700284 "nodegroup" name = Identifier()
285 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700286 {
287 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700288 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700289 }
Till Westmann96c1f172013-08-01 02:05:48 -0700290 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700291 {
Till Westmann14a20a72013-05-09 00:06:24 -0700292 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700293 }
294 )*
295 {
Till Westmann14a20a72013-05-09 00:06:24 -0700296 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700297 }
298}
299
300DatasetDecl DatasetSpecification() throws ParseException:
301{
302 Pair<Identifier,Identifier> nameComponents = null;
303 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700304 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700305 String adapterName = null;
306 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700307 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700308 FunctionSignature appliedFunction = null;
309 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700310 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700311 Map<String,String> hints = new HashMap<String,String>();
312 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700313 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700314 String compactionPolicy = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700315}
316{
317 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700318 "external" <DATASET> nameComponents = QualifiedName()
319 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
320 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700321 "using" adapterName = AdapterName() properties = Configuration()
322 ( "hints" hints = Properties() )?
323 {
324 ExternalDetailsDecl edd = new ExternalDetailsDecl();
325 edd.setAdapter(adapterName);
326 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700327 dsetDecl = new DatasetDecl(nameComponents.first,
328 nameComponents.second,
329 new Identifier(typeName),
330 hints,
331 DatasetType.EXTERNAL,
332 edd,
333 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700334 }
335
Till Westmannd7dcb122013-05-16 13:19:09 -0700336 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700337 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
338 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700339 primaryKeyFields = PrimaryKey()
340 ("autogenerated" { autogenerated = true; } )?
341 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700342 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700343 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700344 {
Till Westmann14a20a72013-05-09 00:06:24 -0700345 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
346 ? new Identifier(nodeGroupName)
347 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700348 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700349 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700350 compactionPolicy,
351 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700352 dsetDecl = new DatasetDecl(nameComponents.first,
353 nameComponents.second,
354 new Identifier(typeName),
355 hints,
356 DatasetType.INTERNAL,
357 idd,
358 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700359 }
360 )
361 {
362 return dsetDecl;
363 }
364}
365
366CreateIndexStatement IndexSpecification() throws ParseException:
367{
368 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700369 String indexName = null;
370 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700371 boolean ifNotExists = false;
372 Pair<Identifier,Identifier> nameComponents = null;
373 IndexParams indexType = null;
374}
375{
Till Westmanna4242bc2013-05-08 17:49:55 -0700376 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700377 ifNotExists = IfNotExists()
378 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700379 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700380 {
Till Westmann14a20a72013-05-09 00:06:24 -0700381 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700382 }
Till Westmann96c1f172013-08-01 02:05:48 -0700383 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700384 {
Till Westmann14a20a72013-05-09 00:06:24 -0700385 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700386 }
387 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
388 {
Till Westmann14a20a72013-05-09 00:06:24 -0700389 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700390 cis.setIfNotExists(ifNotExists);
391 cis.setDataverseName(nameComponents.first);
392 cis.setDatasetName(nameComponents.second);
393 if (indexType != null) {
394 cis.setIndexType(indexType.type);
395 cis.setGramLength(indexType.gramLength);
396 }
397 return cis;
398 }
399}
400
salsubaiee0b423fa2013-09-19 19:16:48 -0700401String CompactionPolicy() throws ParseException :
402{
403 String compactionPolicy = null;
404}
405{
406 compactionPolicy = Identifier()
407 {
408 return compactionPolicy;
409 }
410}
411
Till Westmann31c21f92013-05-08 09:21:53 -0700412IndexParams IndexType() throws ParseException:
413{
414 IndexType type = null;
415 int gramLength = 0;
416}
417{
418 ("btree"
419 {
420 type = IndexType.BTREE;
421 }
422 | "rtree"
423 {
424 type = IndexType.RTREE;
425 }
426 | "keyword"
427 {
JIMAHNb75446d2013-06-03 08:35:27 -0700428 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700429 }
430 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
431 {
JIMAHNb75446d2013-06-03 08:35:27 -0700432 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700433 gramLength = Integer.valueOf(token.image);
434 }
435 <RIGHTPAREN>)
436 {
437 return new IndexParams(type, gramLength);
438 }
439}
440
441CreateDataverseStatement DataverseSpecification() throws ParseException :
442{
Till Westmann14a20a72013-05-09 00:06:24 -0700443 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700444 boolean ifNotExists = false;
445 String format = null;
446}
447{
Till Westmanna4242bc2013-05-08 17:49:55 -0700448 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700449 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700450 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700451 {
Till Westmann14a20a72013-05-09 00:06:24 -0700452 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700453 }
454}
455
456CreateFunctionStatement FunctionSpecification() throws ParseException:
457{
458 FunctionSignature signature;
459 boolean ifNotExists = false;
460 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
461 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700462 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700463 Expression functionBodyExpr;
464 Token beginPos;
465 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700466 FunctionName fctName = null;
467
Till Westmann31c21f92013-05-08 09:21:53 -0700468 createNewScope();
469}
470{
ramangrover299f76a5e2013-06-18 10:25:17 -0700471 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700472 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700473 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700474 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530475 {
476 beginPos = token;
477 }
Till Westmann96c1f172013-08-01 02:05:48 -0700478 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700479 {
480 endPos = token;
481 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700482 // TODO use fctName.library
483 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700484 getCurrentScope().addFunctionDescriptor(signature, false);
485 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
486 }
487}
488
ramangrover29a774ef22013-07-17 09:29:18 -0700489CreateFeedStatement FeedSpecification() throws ParseException:
490{
491 Pair<Identifier,Identifier> nameComponents = null;
492 boolean ifNotExists = false;
493 String adaptorName = null;
494 Map<String,String> properties = null;
495 FunctionSignature appliedFunction = null;
496 CreateFeedStatement cfs = null;
497}
498{
499 (
500 "feed" nameComponents = QualifiedName()
501 ifNotExists = IfNotExists()
502 "using" adaptorName = AdapterName() properties = Configuration()
503 (appliedFunction = ApplyFunction())?
504 {
505 cfs = new CreateFeedStatement(nameComponents.first,
506 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
507 }
508
509 )
510 {
511 return cfs;
512 }
513}
514
515
516
Till Westmannd7dcb122013-05-16 13:19:09 -0700517List<VarIdentifier> ParameterList() throws ParseException:
518{
519 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
520 VarIdentifier var = null;
521}
522{
Till Westmann31c21f92013-05-08 09:21:53 -0700523 <LEFTPAREN> (<VARIABLE>
524 {
525 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700526 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700527 paramList.add(var);
528 getCurrentScope().addNewVarSymbolToScope(var);
529 }
Till Westmann96c1f172013-08-01 02:05:48 -0700530 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700531 {
532 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700533 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700534 paramList.add(var);
535 getCurrentScope().addNewVarSymbolToScope(var);
536 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700537 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700538 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700539 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700540 }
541}
542
543boolean IfNotExists() throws ParseException:
544{
545}
546{
547 ( "if not exists"
548 {
549 return true;
550 }
551 )?
552 {
553 return false;
554 }
555}
556
557FunctionSignature ApplyFunction() throws ParseException:
558{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530559 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700560 FunctionSignature funcSig = null;
561}
562{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530563 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700564 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530565 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
566 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700567 }
568}
569
ramangrover29566b3a92013-05-28 09:07:10 -0700570String GetPolicy() throws ParseException:
571{
572 String policy = null;
573}
574{
575 "using" "policy" policy = Identifier()
576 {
577 return policy;
578 }
579
580}
581
Till Westmann31c21f92013-05-08 09:21:53 -0700582FunctionSignature FunctionSignature() throws ParseException:
583{
ramangrover299f76a5e2013-06-18 10:25:17 -0700584 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700585 int arity = 0;
586}
587{
ramangrover299f76a5e2013-06-18 10:25:17 -0700588 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700589 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700590 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700591 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
592 throw new ParseException(" invalid arity:" + arity);
593 }
594
ramangrover299f76a5e2013-06-18 10:25:17 -0700595 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700596 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
597 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700598 }
599}
600
601List<String> PrimaryKey() throws ParseException:
602{
Till Westmann14a20a72013-05-09 00:06:24 -0700603 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700604 List<String> primaryKeyFields = new ArrayList<String>();
605}
606{
Till Westmann14a20a72013-05-09 00:06:24 -0700607 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700608 {
Till Westmann14a20a72013-05-09 00:06:24 -0700609 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700610 }
Till Westmann96c1f172013-08-01 02:05:48 -0700611 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700612 {
Till Westmann14a20a72013-05-09 00:06:24 -0700613 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700614 }
615 )*
616 {
617 return primaryKeyFields;
618 }
619}
620
621Statement DropStatement() throws ParseException:
622{
Till Westmann14a20a72013-05-09 00:06:24 -0700623 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700624 Pair<Identifier,Identifier> pairId = null;
625 Triple<Identifier,Identifier,Identifier> tripleId = null;
626 FunctionSignature funcSig = null;
627 boolean ifExists = false;
628 Statement stmt = null;
629}
630{
631 "drop"
632 (
633 <DATASET> pairId = QualifiedName() ifExists = IfExists()
634 {
635 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
636 }
637 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
638 {
639 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
640 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700641 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700642 {
Till Westmann14a20a72013-05-09 00:06:24 -0700643 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700644 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700645 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700646 {
647 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
648 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700649 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700650 {
Till Westmann14a20a72013-05-09 00:06:24 -0700651 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700652 }
653 | "function" funcSig = FunctionSignature() ifExists = IfExists()
654 {
655 stmt = new FunctionDropStatement(funcSig, ifExists);
656 }
ramangrover29a774ef22013-07-17 09:29:18 -0700657 | "feed" pairId = QualifiedName() ifExists = IfExists()
658 {
659 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
660 }
Till Westmann31c21f92013-05-08 09:21:53 -0700661 )
662 {
663 return stmt;
664 }
665}
666
667boolean IfExists() throws ParseException :
668{
669}
670{
Till Westmann96c1f172013-08-01 02:05:48 -0700671 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700672 {
673 return true;
674 }
675 )?
676 {
677 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000678 }
679}
680
681InsertStatement InsertStatement() throws ParseException:
682{
Till Westmann31c21f92013-05-08 09:21:53 -0700683 Pair<Identifier,Identifier> nameComponents = null;
684 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000685}
686{
Till Westmann31c21f92013-05-08 09:21:53 -0700687 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
688 {
689 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
690 }
vinayakb38b7ca42012-03-05 05:44:15 +0000691}
692
693DeleteStatement DeleteStatement() throws ParseException:
694{
Till Westmann31c21f92013-05-08 09:21:53 -0700695 VariableExpr var = null;
696 Expression condition = null;
697 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000698}
699{
Till Westmann31c21f92013-05-08 09:21:53 -0700700 "delete" var = Variable()
701 {
702 getCurrentScope().addNewVarSymbolToScope(var.getVar());
703 }
704 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700705 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700706 {
707 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
708 }
vinayakb38b7ca42012-03-05 05:44:15 +0000709}
710
711UpdateStatement UpdateStatement() throws ParseException:
712{
Till Westmann31c21f92013-05-08 09:21:53 -0700713 VariableExpr vars;
714 Expression target;
715 Expression condition;
716 UpdateClause uc;
717 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000718}
719{
Till Westmann96c1f172013-08-01 02:05:48 -0700720 "update" vars = Variable() <IN> target = Expression()
721 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700722 <LEFTPAREN> (uc = UpdateClause()
723 {
724 ucs.add(uc);
725 }
Till Westmann96c1f172013-08-01 02:05:48 -0700726 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700727 {
728 ucs.add(uc);
729 }
730 )*) <RIGHTPAREN>
731 {
732 return new UpdateStatement(vars, target, condition, ucs);
733 }
vinayakb38b7ca42012-03-05 05:44:15 +0000734}
735
vinayakb38b7ca42012-03-05 05:44:15 +0000736UpdateClause UpdateClause() throws ParseException:
737{
Till Westmann31c21f92013-05-08 09:21:53 -0700738 Expression target = null;
739 Expression value = null ;
740 InsertStatement is = null;
741 DeleteStatement ds = null;
742 UpdateStatement us = null;
743 Expression condition = null;
744 UpdateClause ifbranch = null;
745 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000746}
747{
Till Westmann96c1f172013-08-01 02:05:48 -0700748 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700749 | is = InsertStatement()
750 | ds = DeleteStatement()
751 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700752 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
753 <THEN> ifbranch = UpdateClause()
754 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700755 {
756 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
757 }
vinayakb38b7ca42012-03-05 05:44:15 +0000758}
759
vinayakb38b7ca42012-03-05 05:44:15 +0000760Statement SetStatement() throws ParseException:
761{
762 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700763 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000764}
765{
Till Westmann7d535322013-05-09 00:40:02 -0700766 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700767 {
Till Westmann31c21f92013-05-08 09:21:53 -0700768 return new SetStatement(pn, pv);
769 }
vinayakb38b7ca42012-03-05 05:44:15 +0000770}
771
772Statement WriteStatement() throws ParseException:
773{
Till Westmann14a20a72013-05-09 00:06:24 -0700774 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000775 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000776 Query query;
777 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000778 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000779}
780{
Till Westmann96c1f172013-08-01 02:05:48 -0700781 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700782 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700783 {
784 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000785 }
786}
787
vinayakb38b7ca42012-03-05 05:44:15 +0000788LoadFromFileStatement LoadStatement() throws ParseException:
789{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000790 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000791 Identifier datasetName = null;
792 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000793 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000794 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000795 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000796}
797{
Till Westmann31c21f92013-05-08 09:21:53 -0700798 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000799 {
Till Westmann31c21f92013-05-08 09:21:53 -0700800 dataverseName = nameComponents.first;
801 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000802 }
Till Westmann31c21f92013-05-08 09:21:53 -0700803 "using" adapterName = AdapterName() properties = Configuration()
804 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000805 {
Till Westmann31c21f92013-05-08 09:21:53 -0700806 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000807 }
808 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700809 {
810 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
811 }
vinayakb38b7ca42012-03-05 05:44:15 +0000812}
813
vinayakb38b7ca42012-03-05 05:44:15 +0000814
Till Westmann31c21f92013-05-08 09:21:53 -0700815String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000816{
ramangrover29669d8f62013-02-11 06:03:32 +0000817 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000818}
819{
Till Westmann68d99652013-05-09 11:15:21 -0700820 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000821 {
Till Westmann7d535322013-05-09 00:40:02 -0700822 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000823 }
vinayakb38b7ca42012-03-05 05:44:15 +0000824}
825
salsubaiee0b423fa2013-09-19 19:16:48 -0700826Statement CompactStatement() throws ParseException:
827{
828 Pair<Identifier,Identifier> nameComponents = null;
829 Statement stmt = null;
830}
831{
832 "compact" <DATASET> nameComponents = QualifiedName()
833 {
834 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
835 }
836 {
837 return stmt;
838 }
839}
840
Till Westmann31c21f92013-05-08 09:21:53 -0700841Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000842{
ramangrover29a774ef22013-07-17 09:29:18 -0700843 Pair<Identifier,Identifier> feedNameComponents = null;
844 Pair<Identifier,Identifier> datasetNameComponents = null;
845
Till Westmann31c21f92013-05-08 09:21:53 -0700846 Map<String,String> configuration = null;
847 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700848 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000849}
850{
Till Westmann31c21f92013-05-08 09:21:53 -0700851 (
ramangrover29a774ef22013-07-17 09:29:18 -0700852 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700853 {
ramangrover29a774ef22013-07-17 09:29:18 -0700854 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700855 }
ramangrover29a774ef22013-07-17 09:29:18 -0700856 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700857 {
ramangrover29a774ef22013-07-17 09:29:18 -0700858 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700859 }
860 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000861 {
Till Westmann31c21f92013-05-08 09:21:53 -0700862 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000863 }
864}
865
Till Westmann31c21f92013-05-08 09:21:53 -0700866Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000867{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000868 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700869 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000870}
871{
Till Westmann31c21f92013-05-08 09:21:53 -0700872 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000873 {
Till Westmann31c21f92013-05-08 09:21:53 -0700874 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000875 }
Till Westmann96c1f172013-08-01 02:05:48 -0700876 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000877 {
Till Westmann31c21f92013-05-08 09:21:53 -0700878 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000879 }
Till Westmann31c21f92013-05-08 09:21:53 -0700880 )* )? <RIGHTPAREN>
881 {
882 return configuration;
883 }
884}
885
886Pair<String, String> KeyValuePair() throws ParseException:
887{
888 String key;
889 String value;
890}
891{
Till Westmann96c1f172013-08-01 02:05:48 -0700892 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700893 {
894 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000895 }
Till Westmann31c21f92013-05-08 09:21:53 -0700896}
897
898Map<String,String> Properties() throws ParseException:
899{
900 Map<String,String> properties = new HashMap<String,String>();
901 Pair<String, String> property;
902}
903{
904 ( <LEFTPAREN> property = Property()
905 {
906 properties.put(property.first, property.second);
907 }
Till Westmann96c1f172013-08-01 02:05:48 -0700908 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700909 {
910 properties.put(property.first, property.second);
911 }
912 )* <RIGHTPAREN> )?
913 {
914 return properties;
915 }
916}
917
918Pair<String, String> Property() throws ParseException:
919{
920 String key;
921 String value;
922}
923{
Till Westmann96c1f172013-08-01 02:05:48 -0700924 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700925 {
926 try {
927 value = "" + Long.valueOf(token.image);
928 } catch (NumberFormatException nfe) {
929 throw new ParseException("inapproriate value: " + token.image);
930 }
931 }
932 )
933 {
934 return new Pair<String, String>(key.toUpperCase(), value);
935 }
vinayakb38b7ca42012-03-05 05:44:15 +0000936}
937
938TypeExpression TypeExpr() throws ParseException:
939{
940 TypeExpression typeExpr = null;
941}
942{
943 (
944 typeExpr = RecordTypeDef()
945 | typeExpr = TypeReference()
946 | typeExpr = OrderedListTypeDef()
947 | typeExpr = UnorderedListTypeDef()
948 )
949 {
950 return typeExpr;
951 }
952}
953
954RecordTypeDefinition RecordTypeDef() throws ParseException:
955{
956 RecordTypeDefinition recType = new RecordTypeDefinition();
957 RecordTypeDefinition.RecordKind recordKind = null;
958}
959{
960 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
961 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700962 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000963 {
964 String hint = getHint(token);
965 if (hint != null) {
966 String splits[] = hint.split(" +");
967 if (splits[0].equals(GEN_FIELDS_HINT)) {
968 if (splits.length != 5) {
969 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
970 }
971 if (!splits[1].equals("int")) {
972 throw new ParseException("The only supported type for gen-fields is int.");
973 }
974 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
975 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
976 recType.setUndeclaredFieldsDataGen(ufdg);
977 }
978 }
979
980 }
981 (
982 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700983 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000984 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700985 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000986 {
987 if (recordKind == null) {
988 recordKind = RecordTypeDefinition.RecordKind.OPEN;
989 }
990 recType.setRecordKind(recordKind);
991 return recType;
992 }
993}
994
995void RecordField(RecordTypeDefinition recType) throws ParseException:
996{
Till Westmann77cb2f42013-07-15 16:44:19 -0700997 String fieldName;
998 TypeExpression type = null;
999 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001000}
1001{
Till Westmann77cb2f42013-07-15 16:44:19 -07001002 fieldName = Identifier()
1003 {
1004 String hint = getHint(token);
1005 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1006 }
Till Westmann96c1f172013-08-01 02:05:48 -07001007 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001008 {
1009 recType.addField(fieldName, type, nullable, rfdg);
1010 }
vinayakb38b7ca42012-03-05 05:44:15 +00001011}
1012
1013TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001014{
Till Westmann14a20a72013-05-09 00:06:24 -07001015 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001016}
1017{
1018 id = Identifier()
1019 {
Till Westmann14a20a72013-05-09 00:06:24 -07001020 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001021 }
vinayakb38b7ca42012-03-05 05:44:15 +00001022}
1023
1024OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1025{
1026 TypeExpression type = null;
1027}
1028{
Till Westmann96c1f172013-08-01 02:05:48 -07001029 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001030 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001031 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001032 {
1033 return new OrderedListTypeDefinition(type);
1034 }
1035}
1036
1037
1038UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1039{
1040 TypeExpression type = null;
1041}
1042{
Till Westmann96c1f172013-08-01 02:05:48 -07001043 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001044 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001045 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001046 {
1047 return new UnorderedListTypeDefinition(type);
1048 }
1049}
1050
ramangrover299f76a5e2013-06-18 10:25:17 -07001051FunctionName FunctionName() throws ParseException:
1052{
1053 String first = null;
1054 String second = null;
1055 String third = null;
1056 boolean secondAfterDot = false;
1057}
1058{
zheilbron555dc9d2013-08-14 19:58:00 -07001059 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001060 {
1061 secondAfterDot = true;
1062 }
1063 ("#" third = Identifier())? | "#" second = Identifier() )?
1064 {
1065 FunctionName result = new FunctionName();
1066 if (second == null) {
1067 result.dataverse = defaultDataverse;
1068 result.library = null;
1069 result.function = first;
1070 } else if (third == null) {
1071 if (secondAfterDot) {
1072 result.dataverse = first;
1073 result.library = null;
1074 result.function = second;
1075 } else {
1076 result.dataverse = defaultDataverse;
1077 result.library = first;
1078 result.function = second;
1079 }
1080 } else {
1081 result.dataverse = first;
1082 result.library = second;
1083 result.function = third;
1084 }
1085 return result;
1086 }
1087}
Till Westmann31c21f92013-05-08 09:21:53 -07001088
ramangrover299f76a5e2013-06-18 10:25:17 -07001089
1090Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001091{
Till Westmann31c21f92013-05-08 09:21:53 -07001092 Pair<Identifier,Identifier> name = null;
1093}
1094{
1095 name = QualifiedName()
1096 {
1097 if (name.first == null) {
1098 name.first = new Identifier(defaultDataverse);
1099 }
1100 return name;
1101 }
1102}
1103
Till Westmann14a20a72013-05-09 00:06:24 -07001104String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001105{
Till Westmann68d99652013-05-09 11:15:21 -07001106 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001107}
1108{
1109 <IDENTIFIER>
1110 {
Till Westmann14a20a72013-05-09 00:06:24 -07001111 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001112 }
Till Westmann68d99652013-05-09 11:15:21 -07001113 | lit = StringLiteral()
1114 {
1115 return lit;
1116 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001117}
1118
Till Westmann7d535322013-05-09 00:40:02 -07001119String StringLiteral() throws ParseException:
1120{
1121}
1122{
1123 <STRING_LITERAL>
1124 {
1125 return removeQuotesAndEscapes(token.image);
1126 }
1127}
1128
Till Westmann31c21f92013-05-08 09:21:53 -07001129Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1130{
Till Westmann14a20a72013-05-09 00:06:24 -07001131 String first = null;
1132 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001133}
1134{
Till Westmann96c1f172013-08-01 02:05:48 -07001135 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001136 {
Till Westmann14a20a72013-05-09 00:06:24 -07001137 Identifier id1 = null;
1138 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001139 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001140 id2 = new Identifier(first);
1141 } else
1142 {
1143 id1 = new Identifier(first);
1144 id2 = new Identifier(second);
1145 }
1146 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001147 }
1148}
1149
Till Westmann31c21f92013-05-08 09:21:53 -07001150Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001151{
Till Westmann14a20a72013-05-09 00:06:24 -07001152 String first = null;
1153 String second = null;
1154 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001155}
1156{
Till Westmann96c1f172013-08-01 02:05:48 -07001157 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001158 {
Till Westmann14a20a72013-05-09 00:06:24 -07001159 Identifier id1 = null;
1160 Identifier id2 = null;
1161 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001162 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001163 id2 = new Identifier(first);
1164 id3 = new Identifier(second);
1165 } else {
1166 id1 = new Identifier(first);
1167 id2 = new Identifier(second);
1168 id3 = new Identifier(third);
1169 }
1170 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001171 }
1172}
1173
vinayakb38b7ca42012-03-05 05:44:15 +00001174FunctionDecl FunctionDeclaration() throws ParseException:
1175{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001176 FunctionDecl funcDecl;
1177 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001178 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001179 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1180 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001181 createNewScope();
1182}
1183{
Till Westmannd7dcb122013-05-16 13:19:09 -07001184 "declare" "function" functionName = Identifier()
1185 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001186 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001187 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001188 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001189 getCurrentScope().addFunctionDescriptor(signature, false);
1190 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001191 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001192 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001193 }
1194}
1195
vinayakb38b7ca42012-03-05 05:44:15 +00001196
Till Westmann31c21f92013-05-08 09:21:53 -07001197Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001198{
1199 Query query = new Query();
1200 Expression expr;
1201}
1202{
Till Westmann31c21f92013-05-08 09:21:53 -07001203 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001204 {
1205 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001206 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001207 return query;
1208 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001209
vinayakb38b7ca42012-03-05 05:44:15 +00001210}
1211
1212
1213
1214Expression Expression():
1215{
1216 Expression expr = null;
1217 Expression exprP = null;
1218}
1219{
1220(
1221
1222//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1223 expr = OperatorExpr()
1224 | expr = IfThenElse()
1225 | expr = FLWOGR()
1226 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001227
vinayakb38b7ca42012-03-05 05:44:15 +00001228
1229)
1230 {
1231 return (exprP==null) ? expr : exprP;
1232 }
1233}
1234
1235
1236
1237Expression OperatorExpr()throws ParseException:
1238{
1239 OperatorExpr op = null;
1240 Expression operand = null;
1241}
1242{
1243 operand = AndExpr()
1244 (
1245
Till Westmann96c1f172013-08-01 02:05:48 -07001246 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001247 {
1248 if (op == null) {
1249 op = new OperatorExpr();
1250 op.addOperand(operand);
1251 op.setCurrentop(true);
1252 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001253 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001254 }
1255
1256 operand = AndExpr()
1257 {
1258 op.addOperand(operand);
1259 }
1260
1261 )*
1262
1263 {
1264 return op==null? operand: op;
1265 }
1266}
1267
1268Expression AndExpr()throws ParseException:
1269{
1270 OperatorExpr op = null;
1271 Expression operand = null;
1272}
1273{
1274 operand = RelExpr()
1275 (
1276
Till Westmann96c1f172013-08-01 02:05:48 -07001277 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001278 {
1279 if (op == null) {
1280 op = new OperatorExpr();
1281 op.addOperand(operand);
1282 op.setCurrentop(true);
1283 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001284 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001285 }
1286
1287 operand = RelExpr()
1288 {
1289 op.addOperand(operand);
1290 }
1291
1292 )*
1293
1294 {
1295 return op==null? operand: op;
1296 }
1297}
1298
1299
1300
1301Expression RelExpr()throws ParseException:
1302{
1303 OperatorExpr op = null;
1304 Expression operand = null;
1305 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001306 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001307}
1308{
1309 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001310 {
1311 if (operand instanceof VariableExpr) {
1312 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001313 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001314 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001315 }
1316 }
1317 }
1318
1319 (
Till Westmann96c1f172013-08-01 02:05:48 -07001320 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001321 {
alexander.behm07617fd2012-07-25 10:13:50 +00001322 String mhint = getHint(token);
1323 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1324 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1325 }
vinayakb38b7ca42012-03-05 05:44:15 +00001326 if (op == null) {
1327 op = new OperatorExpr();
1328 op.addOperand(operand, broadcast);
1329 op.setCurrentop(true);
1330 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001331 }
1332 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001333 }
1334
1335 operand = AddExpr()
1336 {
alexander.behm07617fd2012-07-25 10:13:50 +00001337 broadcast = false;
1338 if (operand instanceof VariableExpr) {
1339 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001340 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1341 broadcast = true;
1342 }
alexander.behm07617fd2012-07-25 10:13:50 +00001343 }
vinayakb38b7ca42012-03-05 05:44:15 +00001344 op.addOperand(operand, broadcast);
1345 }
1346 )?
1347
1348 {
alexander.behm07617fd2012-07-25 10:13:50 +00001349 if (annotation != null) {
1350 op.addHint(annotation);
1351 }
vinayakb38b7ca42012-03-05 05:44:15 +00001352 return op==null? operand: op;
1353 }
1354}
1355
1356Expression AddExpr()throws ParseException:
1357{
1358 OperatorExpr op = null;
1359 Expression operand = null;
1360}
1361{
1362 operand = MultExpr()
1363
Till Westmann96c1f172013-08-01 02:05:48 -07001364 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001365 {
1366 if (op == null) {
1367 op = new OperatorExpr();
1368 op.addOperand(operand);
1369 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001370 }
1371 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001372 }
1373
1374 operand = MultExpr()
1375 {
1376 op.addOperand(operand);
1377 }
1378 )*
1379
1380 {
1381 return op==null? operand: op;
1382 }
1383}
1384
1385Expression MultExpr()throws ParseException:
1386{
1387 OperatorExpr op = null;
1388 Expression operand = null;
1389}
1390{
1391 operand = UnionExpr()
1392
Till Westmann96c1f172013-08-01 02:05:48 -07001393 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001394 {
1395 if (op == null) {
1396 op = new OperatorExpr();
1397 op.addOperand(operand);
1398 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001399 }
1400 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001401 }
1402 operand = UnionExpr()
1403 {
1404 op.addOperand(operand);
1405 }
1406 )*
1407
1408 {
1409 return op==null?operand:op;
1410 }
1411}
1412
1413Expression UnionExpr() throws ParseException:
1414{
1415 UnionExpr union = null;
1416 Expression operand1 = null;
1417 Expression operand2 = null;
1418}
1419{
1420 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001421 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001422 (operand2 = UnaryExpr()) {
1423 if (union == null) {
1424 union = new UnionExpr();
1425 union.addExpr(operand1);
1426 }
1427 union.addExpr(operand2);
1428 } )*
1429 {
1430 return (union == null)? operand1: union;
1431 }
1432}
1433
1434Expression UnaryExpr() throws ParseException:
1435{
1436 Expression uexpr = null;
1437 Expression expr = null;
1438}
1439{
Till Westmann96c1f172013-08-01 02:05:48 -07001440 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001441 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001442 uexpr = new UnaryExpr();
1443 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001444 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001445 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001446 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1447 else
1448 throw new ParseException();
1449 }
1450 )?
1451
1452 expr = ValueExpr()
1453 {
1454 if(uexpr!=null){
1455 ((UnaryExpr)uexpr).setExpr(expr);
1456 return uexpr;
1457 }
1458 else{
1459 return expr;
1460 }
1461 }
1462}
1463
Till Westmann04478e72013-05-13 23:01:34 -07001464Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001465{
1466 Expression expr = null;
1467 Identifier ident = null;
1468 AbstractAccessor fa = null;
1469 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001470}
1471{
Till Westmann04478e72013-05-13 23:01:34 -07001472 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001473 {
Till Westmann04478e72013-05-13 23:01:34 -07001474 fa = (fa == null ? new FieldAccessor(expr, ident)
1475 : new FieldAccessor(fa, ident));
1476 }
1477 | index = Index()
1478 {
1479 fa = (fa == null ? new IndexAccessor(expr, index)
1480 : new IndexAccessor(fa, index));
1481 }
1482 )*
1483 {
1484 return fa == null ? expr : fa;
1485 }
vinayakb38b7ca42012-03-05 05:44:15 +00001486}
1487
1488Identifier Field() throws ParseException:
1489{
Till Westmann14a20a72013-05-09 00:06:24 -07001490 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001491}
1492{
Till Westmann96c1f172013-08-01 02:05:48 -07001493 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001494 {
Till Westmann14a20a72013-05-09 00:06:24 -07001495 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001496 }
vinayakb38b7ca42012-03-05 05:44:15 +00001497}
1498
1499int Index() throws ParseException:
1500{
1501 Expression expr = null;
1502 int idx = -2;
1503}
1504{
Till Westmann96c1f172013-08-01 02:05:48 -07001505 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001506 {
1507 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1508 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001509 Literal lit = ((LiteralExpr)expr).getValue();
1510 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1511 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001512 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001513 }
vinayakb38b7ca42012-03-05 05:44:15 +00001514 else {
1515 throw new ParseException("Index should be an INTEGER");
1516 }
1517 }
1518
1519 }
1520
Till Westmann96c1f172013-08-01 02:05:48 -07001521 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001522 {
1523 idx = IndexAccessor.ANY;
1524 // ANY
1525 }
1526
1527 )
1528
Till Westmann96c1f172013-08-01 02:05:48 -07001529 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001530 {
1531 return idx;
1532 }
1533}
1534
1535
1536Expression PrimaryExpr()throws ParseException:
1537{
1538 Expression expr = null;
1539}
1540{
Till Westmann68d99652013-05-09 11:15:21 -07001541 ( LOOKAHEAD(2)
1542 expr = FunctionCallExpr()
1543 | expr = Literal()
1544 | expr = DatasetAccessExpression()
1545 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001546 {
1547 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001548 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001549 }
Till Westmann68d99652013-05-09 11:15:21 -07001550 | expr = ListConstructor()
1551 | expr = RecordConstructor()
1552 | expr = ParenthesizedExpression()
1553 )
1554 {
1555 return expr;
1556 }
vinayakb38b7ca42012-03-05 05:44:15 +00001557}
1558
1559Expression Literal() throws ParseException:
1560{
vinayakb38b7ca42012-03-05 05:44:15 +00001561 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001562 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001563}
1564{
Till Westmann7d535322013-05-09 00:40:02 -07001565 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001566 {
Till Westmann7d535322013-05-09 00:40:02 -07001567 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001568 }
1569 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001570 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001571 try {
1572 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1573 } catch(NumberFormatException ex) {
1574 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1575 }
1576 }
1577 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001578 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001579 lit.setValue(new FloatLiteral(new Float(token.image)));
1580 }
1581 | <DOUBLE_LITERAL>
1582 {
1583 lit.setValue(new DoubleLiteral(new Double(token.image)));
1584 }
1585 | <NULL>
1586 {
1587 lit.setValue(NullLiteral.INSTANCE);
1588 }
1589 | <TRUE>
1590 {
1591 lit.setValue(TrueLiteral.INSTANCE);
1592 }
1593 | <FALSE>
1594 {
1595 lit.setValue(FalseLiteral.INSTANCE);
1596 }
1597 )
vinayakb38b7ca42012-03-05 05:44:15 +00001598 {
1599 return lit;
1600 }
1601}
1602
1603
1604VariableExpr VariableRef() throws ParseException:
1605{
1606 VariableExpr varExp = new VariableExpr();
1607 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001608}
1609{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001610 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001611 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001612 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001613 Identifier ident = lookupSymbol(varName);
1614 if (isInForbiddenScopes(varName)) {
1615 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.");
1616 }
1617 if(ident != null) { // exist such ident
1618 varExp.setIsNewVar(false);
1619 varExp.setVar((VarIdentifier)ident);
1620 } else {
1621 varExp.setVar(var);
1622 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001623 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001624 return varExp;
1625 }
1626}
1627
1628
1629VariableExpr Variable() throws ParseException:
1630{
1631 VariableExpr varExp = new VariableExpr();
1632 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001633}
1634{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001635 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001636 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001637 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001638 if(ident != null) { // exist such ident
1639 varExp.setIsNewVar(false);
1640 }
1641 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001642 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001643 return varExp;
1644 }
1645}
1646
1647Expression ListConstructor() throws ParseException:
1648{
1649 Expression expr = null;
1650}
1651{
1652 (
1653 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1654 )
1655
1656 {
1657 return expr;
1658 }
1659}
1660
1661
1662ListConstructor OrderedListConstructor() throws ParseException:
1663{
1664 ListConstructor expr = new ListConstructor();
1665 Expression tmp = null;
1666 List<Expression> exprList = new ArrayList<Expression>();
1667 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1668}
1669{
1670
Till Westmann96c1f172013-08-01 02:05:48 -07001671 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001672 ( tmp = Expression()
1673 {
1674 exprList.add(tmp);
1675 }
1676
Till Westmann96c1f172013-08-01 02:05:48 -07001677 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001678 )?
1679
Till Westmann96c1f172013-08-01 02:05:48 -07001680 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001681
1682 {
1683 expr.setExprList(exprList);
1684 return expr;
1685 }
1686}
1687
1688ListConstructor UnorderedListConstructor() throws ParseException:
1689{
1690 ListConstructor expr = new ListConstructor();
1691 Expression tmp = null;
1692 List<Expression> exprList = new ArrayList<Expression>();
1693 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1694}
1695{
1696
Till Westmann96c1f172013-08-01 02:05:48 -07001697 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001698 {
1699 exprList.add(tmp);
1700 }
Till Westmann96c1f172013-08-01 02:05:48 -07001701 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001702 {
1703 expr.setExprList(exprList);
1704 return expr;
1705 }
1706}
1707
1708RecordConstructor RecordConstructor() throws ParseException:
1709{
1710 RecordConstructor expr = new RecordConstructor();
1711 FieldBinding tmp = null;
1712 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1713}
1714{
Till Westmann96c1f172013-08-01 02:05:48 -07001715 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001716 {
1717 fbList.add(tmp);
1718 }
Till Westmann96c1f172013-08-01 02:05:48 -07001719 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001720 {
1721 expr.setFbList(fbList);
1722 return expr;
1723 }
1724}
1725
1726FieldBinding FieldBinding() throws ParseException:
1727{
1728 FieldBinding fb = new FieldBinding();
1729 Expression left, right;
1730}
1731{
Till Westmann96c1f172013-08-01 02:05:48 -07001732 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001733 {
1734 fb.setLeftExpr(left);
1735 fb.setRightExpr(right);
1736 return fb;
1737 }
1738}
1739
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001740
vinayakb38b7ca42012-03-05 05:44:15 +00001741Expression FunctionCallExpr() throws ParseException:
1742{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001743 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001744 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001745 Expression tmp;
1746 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001747 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001748 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001749}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001750{
ramangrover299f76a5e2013-06-18 10:25:17 -07001751 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001752 {
Till Westmann31c21f92013-05-08 09:21:53 -07001753 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001754 }
Till Westmann31c21f92013-05-08 09:21:53 -07001755 <LEFTPAREN> (tmp = Expression()
1756 {
1757 argList.add(tmp);
1758 arity ++;
1759 }
Till Westmann96c1f172013-08-01 02:05:48 -07001760 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001761 {
1762 argList.add(tmp);
1763 arity++;
1764 }
1765 )*)? <RIGHTPAREN>
1766 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001767 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001768 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001769 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001770 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001771 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001772 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001773 }
1774 callExpr = new CallExpr(signature,argList);
1775 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1776 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1777 }
1778 return callExpr;
1779 }
vinayakb38b7ca42012-03-05 05:44:15 +00001780}
1781
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001782
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001783Expression DatasetAccessExpression() throws ParseException:
1784{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001785 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001786 String arg1 = null;
1787 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001788 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001789}
1790{
Till Westmann14a20a72013-05-09 00:06:24 -07001791 <DATASET>
1792 {
Till Westmann14a20a72013-05-09 00:06:24 -07001793 funcName = token.image;
1794 }
Till Westmann96c1f172013-08-01 02:05:48 -07001795 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001796 {
1797 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001798 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001799 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001800 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001801 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001802 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001803 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001804 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1805 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1806 if (signature == null) {
1807 signature = new FunctionSignature(dataverse, funcName, 1);
1808 }
1809 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001810 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001811 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001812 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001813}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001814
vinayakb38b7ca42012-03-05 05:44:15 +00001815Expression ParenthesizedExpression() throws ParseException:
1816{
1817 Expression expr;
1818}
1819{
1820 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1821 {
1822 return expr;
1823 }
1824}
1825
1826Expression IfThenElse() throws ParseException:
1827{
1828 Expression condExpr;
1829 Expression thenExpr;
1830 Expression elseExpr;
1831 IfExpr ifExpr = new IfExpr();
1832}
1833{
Till Westmann96c1f172013-08-01 02:05:48 -07001834 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001835
1836 {
1837 ifExpr.setCondExpr(condExpr);
1838 ifExpr.setThenExpr(thenExpr);
1839 ifExpr.setElseExpr(elseExpr);
1840 return ifExpr;
1841 }
1842}
1843
1844Expression FLWOGR() throws ParseException:
1845{
1846 FLWOGRExpression flworg = new FLWOGRExpression();
1847 List<Clause> clauseList = new ArrayList<Clause>();
1848 Expression returnExpr;
1849 Clause tmp;
1850 createNewScope();
1851}
1852{
1853 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001854 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001855
1856 {
1857 flworg.setClauseList(clauseList);
1858 flworg.setReturnExpr(returnExpr);
1859 removeCurrentScope();
1860 return flworg;
1861 }
1862}
1863
1864Clause Clause()throws ParseException :
1865{
1866 Clause clause;
1867}
1868{
1869 (
1870 clause = ForClause()
1871 | clause = LetClause()
1872 | clause = WhereClause()
1873 | clause = OrderbyClause()
1874 | clause = GroupClause()
1875 | clause = LimitClause()
1876 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001877 )
1878 {
1879 return clause;
1880 }
1881}
1882
1883Clause ForClause()throws ParseException :
1884{
1885 ForClause fc = new ForClause();
1886 VariableExpr varExp;
1887 VariableExpr varPos = null;
1888 Expression inExp;
1889 extendCurrentScope();
1890}
1891{
Till Westmann96c1f172013-08-01 02:05:48 -07001892 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001893 {
1894 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001895 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001896 fc.setInExpr(inExp);
1897 if (varPos != null) {
1898 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001899 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001900 }
1901 return fc;
1902 }
1903}
1904
1905Clause LetClause() throws ParseException:
1906{
1907 LetClause lc = new LetClause();
1908 VariableExpr varExp;
1909 Expression beExp;
1910 extendCurrentScope();
1911}
1912{
Till Westmann96c1f172013-08-01 02:05:48 -07001913 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001914 {
1915 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001916 lc.setVarExpr(varExp);
1917 lc.setBeExpr(beExp);
1918 return lc;
1919 }
1920}
1921
1922Clause WhereClause()throws ParseException :
1923{
1924 WhereClause wc = new WhereClause();
1925 Expression whereExpr;
1926}
1927{
Till Westmann96c1f172013-08-01 02:05:48 -07001928 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001929 {
1930 wc.setWhereExpr(whereExpr);
1931 return wc;
1932 }
1933}
1934
1935Clause OrderbyClause()throws ParseException :
1936{
1937 OrderbyClause oc = new OrderbyClause();
1938 Expression orderbyExpr;
1939 List<Expression> orderbyList = new ArrayList<Expression>();
1940 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1941 int numOfOrderby = 0;
1942}
1943{
1944 (
Till Westmann96c1f172013-08-01 02:05:48 -07001945 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001946 {
1947 String hint = getHint(token);
1948 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1949 String splits[] = hint.split(" +");
1950 int numFrames = Integer.parseInt(splits[1]);
1951 int numTuples = Integer.parseInt(splits[2]);
1952 oc.setNumFrames(numFrames);
1953 oc.setNumTuples(numTuples);
1954 }
1955 }
Till Westmann96c1f172013-08-01 02:05:48 -07001956 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001957 {
1958 orderbyList.add(orderbyExpr);
1959 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1960 }
Till Westmann96c1f172013-08-01 02:05:48 -07001961 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1962 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001963 {
1964 modifierList.add(modif);
1965 }
1966
Till Westmann96c1f172013-08-01 02:05:48 -07001967 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001968 {
1969 orderbyList.add(orderbyExpr);
1970 modif = OrderbyClause.OrderModifier.ASC;
1971 }
Till Westmann96c1f172013-08-01 02:05:48 -07001972 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1973 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001974 {
1975 modifierList.add(modif);
1976 }
1977 )*
1978)
1979 {
1980 oc.setModifierList(modifierList);
1981 oc.setOrderbyList(orderbyList);
1982 return oc;
1983 }
1984}
1985Clause GroupClause()throws ParseException :
1986{
1987 GroupbyClause gbc = new GroupbyClause();
1988 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1989 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1990 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1991 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1992 VariableExpr var = null;
1993 VariableExpr withVar = null;
1994 Expression expr = null;
1995 VariableExpr decorVar = null;
1996 Expression decorExpr = null;
1997}
1998{
1999 {
2000 Scope newScope = extendCurrentScopeNoPush(true);
2001 // extendCurrentScope(true);
2002 }
Till Westmann96c1f172013-08-01 02:05:48 -07002003 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002004 {
2005 String hint = getHint(token);
2006 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2007 gbc.setHashGroupByHint(true);
2008 }
2009 }
Till Westmann96c1f172013-08-01 02:05:48 -07002010 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002011 {
2012 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002013 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002014 expr = Expression()
2015 {
2016 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2017 vePairList.add(pair1);
2018 }
Till Westmann96c1f172013-08-01 02:05:48 -07002019 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002020 {
2021 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002022 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002023 expr = Expression()
2024 {
2025 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2026 vePairList.add(pair2);
2027 }
2028 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002029 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002030 {
2031 newScope.addNewVarSymbolToScope(decorVar.getVar());
2032 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2033 decorPairList.add(pair3);
2034 }
Till Westmann96c1f172013-08-01 02:05:48 -07002035 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002036 {
2037 newScope.addNewVarSymbolToScope(decorVar.getVar());
2038 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2039 decorPairList.add(pair4);
2040 }
2041 )*
2042 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002043 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002044 {
2045 if(withVar.getIsNewVar()==true)
2046 throw new ParseException("can't find variable " + withVar.getVar());
2047 withVarList.add(withVar);
2048 newScope.addNewVarSymbolToScope(withVar.getVar());
2049 }
Till Westmann96c1f172013-08-01 02:05:48 -07002050 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002051 {
2052 if(withVar.getIsNewVar()==true)
2053 throw new ParseException("can't find variable " + withVar.getVar());
2054 withVarList.add(withVar);
2055 newScope.addNewVarSymbolToScope(withVar.getVar());
2056 })*
2057 {
2058 gbc.setGbyPairList(vePairList);
2059 gbc.setDecorPairList(decorPairList);
2060 gbc.setWithVarList(withVarList);
2061 replaceCurrentScope(newScope);
2062 return gbc;
2063 }
2064}
2065
2066
2067LimitClause LimitClause() throws ParseException:
2068{
2069 LimitClause lc = new LimitClause();
2070 Expression expr;
2071 pushForbiddenScope(getCurrentScope());
2072}
2073{
Till Westmann96c1f172013-08-01 02:05:48 -07002074 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2075 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002076
2077 {
2078 popForbiddenScope();
2079 return lc;
2080 }
2081}
2082
2083DistinctClause DistinctClause() throws ParseException:
2084{
2085 List<Expression> exprs = new ArrayList<Expression>();
2086 Expression expr;
2087}
2088{
Till Westmann96c1f172013-08-01 02:05:48 -07002089 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002090 {
2091 exprs.add(expr);
2092 }
Till Westmann96c1f172013-08-01 02:05:48 -07002093 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002094 {
2095 exprs.add(expr);
2096 }
2097 )*
2098 {
2099 return new DistinctClause(exprs);
2100 }
2101}
2102
vinayakb38b7ca42012-03-05 05:44:15 +00002103QuantifiedExpression QuantifiedExpression()throws ParseException:
2104{
2105 QuantifiedExpression qc = new QuantifiedExpression();
2106 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2107 Expression satisfiesExpr;
2108 VariableExpr var;
2109 Expression inExpr;
2110 QuantifiedPair pair;
2111}
2112{
2113 {
2114 createNewScope();
2115 }
2116
Till Westmann96c1f172013-08-01 02:05:48 -07002117 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2118 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2119 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002120 {
2121 pair = new QuantifiedPair(var, inExpr);
2122 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2123 quantifiedList.add(pair);
2124 }
2125 (
Till Westmann96c1f172013-08-01 02:05:48 -07002126 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002127 {
2128 pair = new QuantifiedPair(var, inExpr);
2129 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2130 quantifiedList.add(pair);
2131 }
2132 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002133 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002134 {
2135 qc.setSatisfiesExpr(satisfiesExpr);
2136 qc.setQuantifiedList(quantifiedList);
2137 removeCurrentScope();
2138 return qc;
2139 }
2140}
2141
2142TOKEN_MGR_DECLS:
2143{
Till Westmann96c1f172013-08-01 02:05:48 -07002144 public int commentDepth = 0;
2145 public IntStack lexerStateStack = new IntStack();
2146
2147 public void pushState() {
2148 lexerStateStack.push( curLexState );
2149 }
2150
2151 public void popState() {
2152 if (lexerStateStack.size() > 0) {
2153 SwitchTo( lexerStateStack.pop() );
2154 } else {
2155 throw new RuntimeException();
2156 }
2157 }
vinayakb38b7ca42012-03-05 05:44:15 +00002158}
2159
Till Westmann96c1f172013-08-01 02:05:48 -07002160<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002161TOKEN :
2162{
Till Westmann5df7b452013-08-02 13:07:16 -07002163 <ASC : "asc">
2164 | <AT : "at">
2165 | <BY : "by">
2166 | <DATASET : "dataset">
2167 | <DECOR : "decor">
2168 | <DESC : "desc">
2169 | <DISTINCT : "distinct">
2170 | <ELSE : "else">
2171 | <EVERY : "every">
2172 | <FOR : "for">
2173 | <GROUP : "group">
2174 | <IF : "if">
2175 | <IN : "in">
2176 | <LET : "let">
2177 | <LIMIT : "limit">
2178 | <OFFSET : "offset">
2179 | <ORDER : "order">
2180 | <RETURN : "return">
2181 | <SATISFIES : "satisfies">
2182 | <SOME : "some">
2183 | <THEN : "then">
2184 | <UNION : "union">
2185 | <WHERE : "where">
2186 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002187}
2188
Till Westmann96c1f172013-08-01 02:05:48 -07002189<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002190TOKEN :
2191{
Till Westmann5df7b452013-08-02 13:07:16 -07002192 <CARET : "^">
2193 | <DIV : "/">
2194 | <IDIV : "idiv">
2195 | <MINUS : "-">
2196 | <MOD : "%">
2197 | <MUL : "*">
2198 | <PLUS : "+">
2199
2200 | <LEFTPAREN : "(">
2201 | <RIGHTPAREN : ")">
2202 | <LEFTBRACKET : "[">
2203 | <RIGHTBRACKET : "]">
2204
2205 | <COLON : ":">
2206 | <COMMA : ",">
2207 | <DOT : ".">
2208 | <QUES : "?">
2209
2210 | <LT : "<">
2211 | <GT : ">">
2212 | <LE : "<=">
2213 | <GE : ">=">
2214 | <EQ : "=">
2215 | <NE : "!=">
2216 | <SIMILAR : "~=">
2217 | <ASSIGN : ":=">
2218
2219 | <AND : "and">
2220 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222
Till Westmann96c1f172013-08-01 02:05:48 -07002223<DEFAULT,IN_DBL_BRACE>
2224TOKEN :
2225{
Till Westmann5df7b452013-08-02 13:07:16 -07002226 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002227}
2228
2229<DEFAULT>
2230TOKEN :
2231{
Till Westmann5df7b452013-08-02 13:07:16 -07002232 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002233}
2234
Till Westmann96c1f172013-08-01 02:05:48 -07002235<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002236TOKEN :
2237{
Till Westmann5df7b452013-08-02 13:07:16 -07002238 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002239}
2240
Till Westmann96c1f172013-08-01 02:05:48 -07002241<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002242TOKEN :
2243{
Till Westmann5df7b452013-08-02 13:07:16 -07002244 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002245}
2246
Till Westmann96c1f172013-08-01 02:05:48 -07002247<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002248TOKEN :
2249{
Till Westmann5df7b452013-08-02 13:07:16 -07002250 <INTEGER_LITERAL : (<DIGIT>)+ >
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 <NULL : "null">
2257 | <TRUE : "true">
2258 | <FALSE : "false">
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 <#DIGIT : ["0" - "9"]>
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 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002271 | <DIGITS> ( "." <DIGITS> )?
2272 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002273 >
2274 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002275 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2276 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002277 >
2278 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002279}
2280
Till Westmann96c1f172013-08-01 02:05:48 -07002281<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002282TOKEN :
2283{
Till Westmann5df7b452013-08-02 13:07:16 -07002284 <#LETTER : ["A" - "Z", "a" - "z"]>
2285 | <SPECIALCHARS : ["$", "_", "-"]>
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 +00002289TOKEN :
2290{
Till Westmann5df7b452013-08-02 13:07:16 -07002291 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2292 | < #EscapeQuot: "\\\"" >
2293 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002294}
2295
Till Westmann96c1f172013-08-01 02:05:48 -07002296<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002297TOKEN :
2298{
Till Westmann5df7b452013-08-02 13:07:16 -07002299 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002300}
2301
Till Westmann96c1f172013-08-01 02:05:48 -07002302<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002303TOKEN :
2304{
Till Westmann5df7b452013-08-02 13:07:16 -07002305 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002306}
2307
Till Westmann96c1f172013-08-01 02:05:48 -07002308<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002309SKIP:
2310{
2311 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002312 | "\t"
2313 | "\r"
2314 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002315}
2316
Till Westmann96c1f172013-08-01 02:05:48 -07002317<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002318SKIP:
2319{
Till Westmann5df7b452013-08-02 13:07:16 -07002320 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002321}
2322
Till Westmann96c1f172013-08-01 02:05:48 -07002323<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002324SKIP:
2325{
Till Westmann5df7b452013-08-02 13:07:16 -07002326 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002327}
2328
Till Westmann96c1f172013-08-01 02:05:48 -07002329<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002330SKIP:
2331{
Till Westmann96c1f172013-08-01 02:05:48 -07002332 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002333}
2334
2335<INSIDE_COMMENT>
2336SPECIAL_TOKEN:
2337{
Till Westmann5df7b452013-08-02 13:07:16 -07002338 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002339}
2340
2341<INSIDE_COMMENT>
2342SKIP:
2343{
Till Westmann96c1f172013-08-01 02:05:48 -07002344 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002345}
2346
2347<INSIDE_COMMENT>
2348SKIP:
2349{
Till Westmann96c1f172013-08-01 02:05:48 -07002350 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002351 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002352}