blob: 93c636585bf576ad52c062e627c2b04ca1c58cd3 [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;
salsubaiee0b423fa2013-09-19 19:16:48 -0700313 String compactionPolicy = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700314}
315{
316 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700317 "external" <DATASET> nameComponents = QualifiedName()
318 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
319 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700320 "using" adapterName = AdapterName() properties = Configuration()
321 ( "hints" hints = Properties() )?
322 {
323 ExternalDetailsDecl edd = new ExternalDetailsDecl();
324 edd.setAdapter(adapterName);
325 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700326 dsetDecl = new DatasetDecl(nameComponents.first,
327 nameComponents.second,
328 new Identifier(typeName),
329 hints,
330 DatasetType.EXTERNAL,
331 edd,
332 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700333 }
334
Till Westmannd7dcb122013-05-16 13:19:09 -0700335 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700336 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
337 ifNotExists = IfNotExists()
338 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700339 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700340 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700341 {
Till Westmann14a20a72013-05-09 00:06:24 -0700342 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
343 ? new Identifier(nodeGroupName)
344 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700345 primaryKeyFields,
346 compactionPolicy,
347 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700348 dsetDecl = new DatasetDecl(nameComponents.first,
349 nameComponents.second,
350 new Identifier(typeName),
351 hints,
352 DatasetType.INTERNAL,
353 idd,
354 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700355 }
356 )
357 {
358 return dsetDecl;
359 }
360}
361
362CreateIndexStatement IndexSpecification() throws ParseException:
363{
364 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700365 String indexName = null;
366 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700367 boolean ifNotExists = false;
368 Pair<Identifier,Identifier> nameComponents = null;
369 IndexParams indexType = null;
370}
371{
Till Westmanna4242bc2013-05-08 17:49:55 -0700372 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700373 ifNotExists = IfNotExists()
374 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700375 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700376 {
Till Westmann14a20a72013-05-09 00:06:24 -0700377 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700378 }
Till Westmann96c1f172013-08-01 02:05:48 -0700379 ) (<COMMA> 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 }
383 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
384 {
Till Westmann14a20a72013-05-09 00:06:24 -0700385 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700386 cis.setIfNotExists(ifNotExists);
387 cis.setDataverseName(nameComponents.first);
388 cis.setDatasetName(nameComponents.second);
389 if (indexType != null) {
390 cis.setIndexType(indexType.type);
391 cis.setGramLength(indexType.gramLength);
392 }
393 return cis;
394 }
395}
396
salsubaiee0b423fa2013-09-19 19:16:48 -0700397String CompactionPolicy() throws ParseException :
398{
399 String compactionPolicy = null;
400}
401{
402 compactionPolicy = Identifier()
403 {
404 return compactionPolicy;
405 }
406}
407
Till Westmann31c21f92013-05-08 09:21:53 -0700408IndexParams IndexType() throws ParseException:
409{
410 IndexType type = null;
411 int gramLength = 0;
412}
413{
414 ("btree"
415 {
416 type = IndexType.BTREE;
417 }
418 | "rtree"
419 {
420 type = IndexType.RTREE;
421 }
422 | "keyword"
423 {
JIMAHNb75446d2013-06-03 08:35:27 -0700424 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700425 }
426 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
427 {
JIMAHNb75446d2013-06-03 08:35:27 -0700428 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700429 gramLength = Integer.valueOf(token.image);
430 }
431 <RIGHTPAREN>)
432 {
433 return new IndexParams(type, gramLength);
434 }
435}
436
437CreateDataverseStatement DataverseSpecification() throws ParseException :
438{
Till Westmann14a20a72013-05-09 00:06:24 -0700439 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700440 boolean ifNotExists = false;
441 String format = null;
442}
443{
Till Westmanna4242bc2013-05-08 17:49:55 -0700444 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700445 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700446 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700447 {
Till Westmann14a20a72013-05-09 00:06:24 -0700448 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700449 }
450}
451
452CreateFunctionStatement FunctionSpecification() throws ParseException:
453{
454 FunctionSignature signature;
455 boolean ifNotExists = false;
456 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
457 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700458 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700459 Expression functionBodyExpr;
460 Token beginPos;
461 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700462 FunctionName fctName = null;
463
Till Westmann31c21f92013-05-08 09:21:53 -0700464 createNewScope();
465}
466{
ramangrover299f76a5e2013-06-18 10:25:17 -0700467 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700468 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700469 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700470 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530471 {
472 beginPos = token;
473 }
Till Westmann96c1f172013-08-01 02:05:48 -0700474 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700475 {
476 endPos = token;
477 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700478 // TODO use fctName.library
479 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700480 getCurrentScope().addFunctionDescriptor(signature, false);
481 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
482 }
483}
484
ramangrover29a774ef22013-07-17 09:29:18 -0700485CreateFeedStatement FeedSpecification() throws ParseException:
486{
487 Pair<Identifier,Identifier> nameComponents = null;
488 boolean ifNotExists = false;
489 String adaptorName = null;
490 Map<String,String> properties = null;
491 FunctionSignature appliedFunction = null;
492 CreateFeedStatement cfs = null;
493}
494{
495 (
496 "feed" nameComponents = QualifiedName()
497 ifNotExists = IfNotExists()
498 "using" adaptorName = AdapterName() properties = Configuration()
499 (appliedFunction = ApplyFunction())?
500 {
501 cfs = new CreateFeedStatement(nameComponents.first,
502 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
503 }
504
505 )
506 {
507 return cfs;
508 }
509}
510
511
512
Till Westmannd7dcb122013-05-16 13:19:09 -0700513List<VarIdentifier> ParameterList() throws ParseException:
514{
515 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
516 VarIdentifier var = null;
517}
518{
Till Westmann31c21f92013-05-08 09:21:53 -0700519 <LEFTPAREN> (<VARIABLE>
520 {
521 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700522 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700523 paramList.add(var);
524 getCurrentScope().addNewVarSymbolToScope(var);
525 }
Till Westmann96c1f172013-08-01 02:05:48 -0700526 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700527 {
528 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700529 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700530 paramList.add(var);
531 getCurrentScope().addNewVarSymbolToScope(var);
532 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700533 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700534 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700535 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700536 }
537}
538
539boolean IfNotExists() throws ParseException:
540{
541}
542{
543 ( "if not exists"
544 {
545 return true;
546 }
547 )?
548 {
549 return false;
550 }
551}
552
553FunctionSignature ApplyFunction() throws ParseException:
554{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530555 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700556 FunctionSignature funcSig = null;
557}
558{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530559 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700560 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530561 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
562 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700563 }
564}
565
ramangrover29566b3a92013-05-28 09:07:10 -0700566String GetPolicy() throws ParseException:
567{
568 String policy = null;
569}
570{
571 "using" "policy" policy = Identifier()
572 {
573 return policy;
574 }
575
576}
577
Till Westmann31c21f92013-05-08 09:21:53 -0700578FunctionSignature FunctionSignature() throws ParseException:
579{
ramangrover299f76a5e2013-06-18 10:25:17 -0700580 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700581 int arity = 0;
582}
583{
ramangrover299f76a5e2013-06-18 10:25:17 -0700584 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700585 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700586 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700587 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
588 throw new ParseException(" invalid arity:" + arity);
589 }
590
ramangrover299f76a5e2013-06-18 10:25:17 -0700591 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700592 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
593 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700594 }
595}
596
597List<String> PrimaryKey() throws ParseException:
598{
Till Westmann14a20a72013-05-09 00:06:24 -0700599 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700600 List<String> primaryKeyFields = new ArrayList<String>();
601}
602{
Till Westmann14a20a72013-05-09 00:06:24 -0700603 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700604 {
Till Westmann14a20a72013-05-09 00:06:24 -0700605 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700606 }
Till Westmann96c1f172013-08-01 02:05:48 -0700607 ( <COMMA> 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 }
611 )*
612 {
613 return primaryKeyFields;
614 }
615}
616
617Statement DropStatement() throws ParseException:
618{
Till Westmann14a20a72013-05-09 00:06:24 -0700619 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700620 Pair<Identifier,Identifier> pairId = null;
621 Triple<Identifier,Identifier,Identifier> tripleId = null;
622 FunctionSignature funcSig = null;
623 boolean ifExists = false;
624 Statement stmt = null;
625}
626{
627 "drop"
628 (
629 <DATASET> pairId = QualifiedName() ifExists = IfExists()
630 {
631 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
632 }
633 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
634 {
635 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
636 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700637 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700638 {
Till Westmann14a20a72013-05-09 00:06:24 -0700639 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700640 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700641 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700642 {
643 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
644 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700645 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700646 {
Till Westmann14a20a72013-05-09 00:06:24 -0700647 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700648 }
649 | "function" funcSig = FunctionSignature() ifExists = IfExists()
650 {
651 stmt = new FunctionDropStatement(funcSig, ifExists);
652 }
ramangrover29a774ef22013-07-17 09:29:18 -0700653 | "feed" pairId = QualifiedName() ifExists = IfExists()
654 {
655 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
656 }
Till Westmann31c21f92013-05-08 09:21:53 -0700657 )
658 {
659 return stmt;
660 }
661}
662
663boolean IfExists() throws ParseException :
664{
665}
666{
Till Westmann96c1f172013-08-01 02:05:48 -0700667 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700668 {
669 return true;
670 }
671 )?
672 {
673 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000674 }
675}
676
677InsertStatement InsertStatement() throws ParseException:
678{
Till Westmann31c21f92013-05-08 09:21:53 -0700679 Pair<Identifier,Identifier> nameComponents = null;
680 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000681}
682{
Till Westmann31c21f92013-05-08 09:21:53 -0700683 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
684 {
685 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
686 }
vinayakb38b7ca42012-03-05 05:44:15 +0000687}
688
689DeleteStatement DeleteStatement() throws ParseException:
690{
Till Westmann31c21f92013-05-08 09:21:53 -0700691 VariableExpr var = null;
692 Expression condition = null;
693 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000694}
695{
Till Westmann31c21f92013-05-08 09:21:53 -0700696 "delete" var = Variable()
697 {
698 getCurrentScope().addNewVarSymbolToScope(var.getVar());
699 }
700 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700701 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700702 {
703 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
704 }
vinayakb38b7ca42012-03-05 05:44:15 +0000705}
706
707UpdateStatement UpdateStatement() throws ParseException:
708{
Till Westmann31c21f92013-05-08 09:21:53 -0700709 VariableExpr vars;
710 Expression target;
711 Expression condition;
712 UpdateClause uc;
713 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000714}
715{
Till Westmann96c1f172013-08-01 02:05:48 -0700716 "update" vars = Variable() <IN> target = Expression()
717 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700718 <LEFTPAREN> (uc = UpdateClause()
719 {
720 ucs.add(uc);
721 }
Till Westmann96c1f172013-08-01 02:05:48 -0700722 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700723 {
724 ucs.add(uc);
725 }
726 )*) <RIGHTPAREN>
727 {
728 return new UpdateStatement(vars, target, condition, ucs);
729 }
vinayakb38b7ca42012-03-05 05:44:15 +0000730}
731
vinayakb38b7ca42012-03-05 05:44:15 +0000732UpdateClause UpdateClause() throws ParseException:
733{
Till Westmann31c21f92013-05-08 09:21:53 -0700734 Expression target = null;
735 Expression value = null ;
736 InsertStatement is = null;
737 DeleteStatement ds = null;
738 UpdateStatement us = null;
739 Expression condition = null;
740 UpdateClause ifbranch = null;
741 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000742}
743{
Till Westmann96c1f172013-08-01 02:05:48 -0700744 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700745 | is = InsertStatement()
746 | ds = DeleteStatement()
747 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700748 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
749 <THEN> ifbranch = UpdateClause()
750 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700751 {
752 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
753 }
vinayakb38b7ca42012-03-05 05:44:15 +0000754}
755
vinayakb38b7ca42012-03-05 05:44:15 +0000756Statement SetStatement() throws ParseException:
757{
758 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700759 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000760}
761{
Till Westmann7d535322013-05-09 00:40:02 -0700762 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700763 {
Till Westmann31c21f92013-05-08 09:21:53 -0700764 return new SetStatement(pn, pv);
765 }
vinayakb38b7ca42012-03-05 05:44:15 +0000766}
767
768Statement WriteStatement() throws ParseException:
769{
Till Westmann14a20a72013-05-09 00:06:24 -0700770 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000771 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000772 Query query;
773 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000774 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000775}
776{
Till Westmann96c1f172013-08-01 02:05:48 -0700777 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700778 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700779 {
780 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000781 }
782}
783
vinayakb38b7ca42012-03-05 05:44:15 +0000784LoadFromFileStatement LoadStatement() throws ParseException:
785{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000786 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000787 Identifier datasetName = null;
788 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000789 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000790 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000791 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000792}
793{
Till Westmann31c21f92013-05-08 09:21:53 -0700794 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000795 {
Till Westmann31c21f92013-05-08 09:21:53 -0700796 dataverseName = nameComponents.first;
797 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000798 }
Till Westmann31c21f92013-05-08 09:21:53 -0700799 "using" adapterName = AdapterName() properties = Configuration()
800 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000801 {
Till Westmann31c21f92013-05-08 09:21:53 -0700802 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000803 }
804 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700805 {
806 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
807 }
vinayakb38b7ca42012-03-05 05:44:15 +0000808}
809
vinayakb38b7ca42012-03-05 05:44:15 +0000810
Till Westmann31c21f92013-05-08 09:21:53 -0700811String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000812{
ramangrover29669d8f62013-02-11 06:03:32 +0000813 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000814}
815{
Till Westmann68d99652013-05-09 11:15:21 -0700816 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000817 {
Till Westmann7d535322013-05-09 00:40:02 -0700818 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000819 }
vinayakb38b7ca42012-03-05 05:44:15 +0000820}
821
salsubaiee0b423fa2013-09-19 19:16:48 -0700822Statement CompactStatement() throws ParseException:
823{
824 Pair<Identifier,Identifier> nameComponents = null;
825 Statement stmt = null;
826}
827{
828 "compact" <DATASET> nameComponents = QualifiedName()
829 {
830 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
831 }
832 {
833 return stmt;
834 }
835}
836
Till Westmann31c21f92013-05-08 09:21:53 -0700837Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000838{
ramangrover29a774ef22013-07-17 09:29:18 -0700839 Pair<Identifier,Identifier> feedNameComponents = null;
840 Pair<Identifier,Identifier> datasetNameComponents = null;
841
Till Westmann31c21f92013-05-08 09:21:53 -0700842 Map<String,String> configuration = null;
843 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700844 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000845}
846{
Till Westmann31c21f92013-05-08 09:21:53 -0700847 (
ramangrover29a774ef22013-07-17 09:29:18 -0700848 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700849 {
ramangrover29a774ef22013-07-17 09:29:18 -0700850 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700851 }
ramangrover29a774ef22013-07-17 09:29:18 -0700852 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700853 {
ramangrover29a774ef22013-07-17 09:29:18 -0700854 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700855 }
856 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000857 {
Till Westmann31c21f92013-05-08 09:21:53 -0700858 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000859 }
860}
861
Till Westmann31c21f92013-05-08 09:21:53 -0700862Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000863{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000864 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700865 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000866}
867{
Till Westmann31c21f92013-05-08 09:21:53 -0700868 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000869 {
Till Westmann31c21f92013-05-08 09:21:53 -0700870 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000871 }
Till Westmann96c1f172013-08-01 02:05:48 -0700872 ( <COMMA> 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 Westmann31c21f92013-05-08 09:21:53 -0700876 )* )? <RIGHTPAREN>
877 {
878 return configuration;
879 }
880}
881
882Pair<String, String> KeyValuePair() throws ParseException:
883{
884 String key;
885 String value;
886}
887{
Till Westmann96c1f172013-08-01 02:05:48 -0700888 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700889 {
890 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000891 }
Till Westmann31c21f92013-05-08 09:21:53 -0700892}
893
894Map<String,String> Properties() throws ParseException:
895{
896 Map<String,String> properties = new HashMap<String,String>();
897 Pair<String, String> property;
898}
899{
900 ( <LEFTPAREN> property = Property()
901 {
902 properties.put(property.first, property.second);
903 }
Till Westmann96c1f172013-08-01 02:05:48 -0700904 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700905 {
906 properties.put(property.first, property.second);
907 }
908 )* <RIGHTPAREN> )?
909 {
910 return properties;
911 }
912}
913
914Pair<String, String> Property() throws ParseException:
915{
916 String key;
917 String value;
918}
919{
Till Westmann96c1f172013-08-01 02:05:48 -0700920 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700921 {
922 try {
923 value = "" + Long.valueOf(token.image);
924 } catch (NumberFormatException nfe) {
925 throw new ParseException("inapproriate value: " + token.image);
926 }
927 }
928 )
929 {
930 return new Pair<String, String>(key.toUpperCase(), value);
931 }
vinayakb38b7ca42012-03-05 05:44:15 +0000932}
933
934TypeExpression TypeExpr() throws ParseException:
935{
936 TypeExpression typeExpr = null;
937}
938{
939 (
940 typeExpr = RecordTypeDef()
941 | typeExpr = TypeReference()
942 | typeExpr = OrderedListTypeDef()
943 | typeExpr = UnorderedListTypeDef()
944 )
945 {
946 return typeExpr;
947 }
948}
949
950RecordTypeDefinition RecordTypeDef() throws ParseException:
951{
952 RecordTypeDefinition recType = new RecordTypeDefinition();
953 RecordTypeDefinition.RecordKind recordKind = null;
954}
955{
956 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
957 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700958 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000959 {
960 String hint = getHint(token);
961 if (hint != null) {
962 String splits[] = hint.split(" +");
963 if (splits[0].equals(GEN_FIELDS_HINT)) {
964 if (splits.length != 5) {
965 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
966 }
967 if (!splits[1].equals("int")) {
968 throw new ParseException("The only supported type for gen-fields is int.");
969 }
970 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
971 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
972 recType.setUndeclaredFieldsDataGen(ufdg);
973 }
974 }
975
976 }
977 (
978 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700979 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000980 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700981 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000982 {
983 if (recordKind == null) {
984 recordKind = RecordTypeDefinition.RecordKind.OPEN;
985 }
986 recType.setRecordKind(recordKind);
987 return recType;
988 }
989}
990
991void RecordField(RecordTypeDefinition recType) throws ParseException:
992{
Till Westmann77cb2f42013-07-15 16:44:19 -0700993 String fieldName;
994 TypeExpression type = null;
995 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000996}
997{
Till Westmann77cb2f42013-07-15 16:44:19 -0700998 fieldName = Identifier()
999 {
1000 String hint = getHint(token);
1001 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1002 }
Till Westmann96c1f172013-08-01 02:05:48 -07001003 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001004 {
1005 recType.addField(fieldName, type, nullable, rfdg);
1006 }
vinayakb38b7ca42012-03-05 05:44:15 +00001007}
1008
1009TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001010{
Till Westmann14a20a72013-05-09 00:06:24 -07001011 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001012}
1013{
1014 id = Identifier()
1015 {
Till Westmann14a20a72013-05-09 00:06:24 -07001016 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001017 }
vinayakb38b7ca42012-03-05 05:44:15 +00001018}
1019
1020OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1021{
1022 TypeExpression type = null;
1023}
1024{
Till Westmann96c1f172013-08-01 02:05:48 -07001025 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001026 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001027 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001028 {
1029 return new OrderedListTypeDefinition(type);
1030 }
1031}
1032
1033
1034UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1035{
1036 TypeExpression type = null;
1037}
1038{
Till Westmann96c1f172013-08-01 02:05:48 -07001039 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001040 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001041 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001042 {
1043 return new UnorderedListTypeDefinition(type);
1044 }
1045}
1046
ramangrover299f76a5e2013-06-18 10:25:17 -07001047FunctionName FunctionName() throws ParseException:
1048{
1049 String first = null;
1050 String second = null;
1051 String third = null;
1052 boolean secondAfterDot = false;
1053}
1054{
Raman Groverd6780902013-09-24 16:57:32 +05301055 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001056 {
1057 secondAfterDot = true;
1058 }
1059 ("#" third = Identifier())? | "#" second = Identifier() )?
1060 {
1061 FunctionName result = new FunctionName();
1062 if (second == null) {
1063 result.dataverse = defaultDataverse;
1064 result.library = null;
1065 result.function = first;
1066 } else if (third == null) {
1067 if (secondAfterDot) {
1068 result.dataverse = first;
1069 result.library = null;
1070 result.function = second;
1071 } else {
1072 result.dataverse = defaultDataverse;
1073 result.library = first;
1074 result.function = second;
1075 }
1076 } else {
1077 result.dataverse = first;
1078 result.library = second;
1079 result.function = third;
1080 }
1081 return result;
1082 }
1083}
Till Westmann31c21f92013-05-08 09:21:53 -07001084
ramangrover299f76a5e2013-06-18 10:25:17 -07001085
1086Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001087{
Till Westmann31c21f92013-05-08 09:21:53 -07001088 Pair<Identifier,Identifier> name = null;
1089}
1090{
1091 name = QualifiedName()
1092 {
1093 if (name.first == null) {
1094 name.first = new Identifier(defaultDataverse);
1095 }
1096 return name;
1097 }
1098}
1099
Till Westmann14a20a72013-05-09 00:06:24 -07001100String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001101{
Till Westmann68d99652013-05-09 11:15:21 -07001102 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001103}
1104{
1105 <IDENTIFIER>
1106 {
Till Westmann14a20a72013-05-09 00:06:24 -07001107 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001108 }
Till Westmann68d99652013-05-09 11:15:21 -07001109 | lit = StringLiteral()
1110 {
1111 return lit;
1112 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001113}
1114
Till Westmann7d535322013-05-09 00:40:02 -07001115String StringLiteral() throws ParseException:
1116{
1117}
1118{
1119 <STRING_LITERAL>
1120 {
1121 return removeQuotesAndEscapes(token.image);
1122 }
1123}
1124
Till Westmann31c21f92013-05-08 09:21:53 -07001125Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1126{
Till Westmann14a20a72013-05-09 00:06:24 -07001127 String first = null;
1128 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001129}
1130{
Till Westmann96c1f172013-08-01 02:05:48 -07001131 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001132 {
Till Westmann14a20a72013-05-09 00:06:24 -07001133 Identifier id1 = null;
1134 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001135 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001136 id2 = new Identifier(first);
1137 } else
1138 {
1139 id1 = new Identifier(first);
1140 id2 = new Identifier(second);
1141 }
1142 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001143 }
1144}
1145
Till Westmann31c21f92013-05-08 09:21:53 -07001146Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001147{
Till Westmann14a20a72013-05-09 00:06:24 -07001148 String first = null;
1149 String second = null;
1150 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001151}
1152{
Till Westmann96c1f172013-08-01 02:05:48 -07001153 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001154 {
Till Westmann14a20a72013-05-09 00:06:24 -07001155 Identifier id1 = null;
1156 Identifier id2 = null;
1157 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001158 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001159 id2 = new Identifier(first);
1160 id3 = new Identifier(second);
1161 } else {
1162 id1 = new Identifier(first);
1163 id2 = new Identifier(second);
1164 id3 = new Identifier(third);
1165 }
1166 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001167 }
1168}
1169
vinayakb38b7ca42012-03-05 05:44:15 +00001170FunctionDecl FunctionDeclaration() throws ParseException:
1171{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001172 FunctionDecl funcDecl;
1173 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001174 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001175 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1176 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001177 createNewScope();
1178}
1179{
Till Westmannd7dcb122013-05-16 13:19:09 -07001180 "declare" "function" functionName = Identifier()
1181 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001182 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001183 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001184 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001185 getCurrentScope().addFunctionDescriptor(signature, false);
1186 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001187 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001188 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001189 }
1190}
1191
vinayakb38b7ca42012-03-05 05:44:15 +00001192
Till Westmann31c21f92013-05-08 09:21:53 -07001193Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001194{
1195 Query query = new Query();
1196 Expression expr;
1197}
1198{
Till Westmann31c21f92013-05-08 09:21:53 -07001199 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001200 {
1201 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001202 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001203 return query;
1204 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001205
vinayakb38b7ca42012-03-05 05:44:15 +00001206}
1207
1208
1209
1210Expression Expression():
1211{
1212 Expression expr = null;
1213 Expression exprP = null;
1214}
1215{
1216(
1217
1218//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1219 expr = OperatorExpr()
1220 | expr = IfThenElse()
1221 | expr = FLWOGR()
1222 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001223
vinayakb38b7ca42012-03-05 05:44:15 +00001224
1225)
1226 {
1227 return (exprP==null) ? expr : exprP;
1228 }
1229}
1230
1231
1232
1233Expression OperatorExpr()throws ParseException:
1234{
1235 OperatorExpr op = null;
1236 Expression operand = null;
1237}
1238{
1239 operand = AndExpr()
1240 (
1241
Till Westmann96c1f172013-08-01 02:05:48 -07001242 <OR>
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 = AndExpr()
1253 {
1254 op.addOperand(operand);
1255 }
1256
1257 )*
1258
1259 {
1260 return op==null? operand: op;
1261 }
1262}
1263
1264Expression AndExpr()throws ParseException:
1265{
1266 OperatorExpr op = null;
1267 Expression operand = null;
1268}
1269{
1270 operand = RelExpr()
1271 (
1272
Till Westmann96c1f172013-08-01 02:05:48 -07001273 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001274 {
1275 if (op == null) {
1276 op = new OperatorExpr();
1277 op.addOperand(operand);
1278 op.setCurrentop(true);
1279 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001280 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001281 }
1282
1283 operand = RelExpr()
1284 {
1285 op.addOperand(operand);
1286 }
1287
1288 )*
1289
1290 {
1291 return op==null? operand: op;
1292 }
1293}
1294
1295
1296
1297Expression RelExpr()throws ParseException:
1298{
1299 OperatorExpr op = null;
1300 Expression operand = null;
1301 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001302 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001303}
1304{
1305 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001306 {
1307 if (operand instanceof VariableExpr) {
1308 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001309 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001310 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001311 }
1312 }
1313 }
1314
1315 (
Till Westmann96c1f172013-08-01 02:05:48 -07001316 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001317 {
alexander.behm07617fd2012-07-25 10:13:50 +00001318 String mhint = getHint(token);
1319 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1320 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1321 }
vinayakb38b7ca42012-03-05 05:44:15 +00001322 if (op == null) {
1323 op = new OperatorExpr();
1324 op.addOperand(operand, broadcast);
1325 op.setCurrentop(true);
1326 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001327 }
1328 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001329 }
1330
1331 operand = AddExpr()
1332 {
alexander.behm07617fd2012-07-25 10:13:50 +00001333 broadcast = false;
1334 if (operand instanceof VariableExpr) {
1335 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001336 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1337 broadcast = true;
1338 }
alexander.behm07617fd2012-07-25 10:13:50 +00001339 }
vinayakb38b7ca42012-03-05 05:44:15 +00001340 op.addOperand(operand, broadcast);
1341 }
1342 )?
1343
1344 {
alexander.behm07617fd2012-07-25 10:13:50 +00001345 if (annotation != null) {
1346 op.addHint(annotation);
1347 }
vinayakb38b7ca42012-03-05 05:44:15 +00001348 return op==null? operand: op;
1349 }
1350}
1351
1352Expression AddExpr()throws ParseException:
1353{
1354 OperatorExpr op = null;
1355 Expression operand = null;
1356}
1357{
1358 operand = MultExpr()
1359
Till Westmann96c1f172013-08-01 02:05:48 -07001360 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001361 {
1362 if (op == null) {
1363 op = new OperatorExpr();
1364 op.addOperand(operand);
1365 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001366 }
1367 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001368 }
1369
1370 operand = MultExpr()
1371 {
1372 op.addOperand(operand);
1373 }
1374 )*
1375
1376 {
1377 return op==null? operand: op;
1378 }
1379}
1380
1381Expression MultExpr()throws ParseException:
1382{
1383 OperatorExpr op = null;
1384 Expression operand = null;
1385}
1386{
1387 operand = UnionExpr()
1388
Till Westmann96c1f172013-08-01 02:05:48 -07001389 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001390 {
1391 if (op == null) {
1392 op = new OperatorExpr();
1393 op.addOperand(operand);
1394 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001395 }
1396 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001397 }
1398 operand = UnionExpr()
1399 {
1400 op.addOperand(operand);
1401 }
1402 )*
1403
1404 {
1405 return op==null?operand:op;
1406 }
1407}
1408
1409Expression UnionExpr() throws ParseException:
1410{
1411 UnionExpr union = null;
1412 Expression operand1 = null;
1413 Expression operand2 = null;
1414}
1415{
1416 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001417 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001418 (operand2 = UnaryExpr()) {
1419 if (union == null) {
1420 union = new UnionExpr();
1421 union.addExpr(operand1);
1422 }
1423 union.addExpr(operand2);
1424 } )*
1425 {
1426 return (union == null)? operand1: union;
1427 }
1428}
1429
1430Expression UnaryExpr() throws ParseException:
1431{
1432 Expression uexpr = null;
1433 Expression expr = null;
1434}
1435{
Till Westmann96c1f172013-08-01 02:05:48 -07001436 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001437 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001438 uexpr = new UnaryExpr();
1439 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001440 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001441 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001442 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1443 else
1444 throw new ParseException();
1445 }
1446 )?
1447
1448 expr = ValueExpr()
1449 {
1450 if(uexpr!=null){
1451 ((UnaryExpr)uexpr).setExpr(expr);
1452 return uexpr;
1453 }
1454 else{
1455 return expr;
1456 }
1457 }
1458}
1459
Till Westmann04478e72013-05-13 23:01:34 -07001460Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001461{
1462 Expression expr = null;
1463 Identifier ident = null;
1464 AbstractAccessor fa = null;
1465 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001466}
1467{
Till Westmann04478e72013-05-13 23:01:34 -07001468 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001469 {
Till Westmann04478e72013-05-13 23:01:34 -07001470 fa = (fa == null ? new FieldAccessor(expr, ident)
1471 : new FieldAccessor(fa, ident));
1472 }
1473 | index = Index()
1474 {
1475 fa = (fa == null ? new IndexAccessor(expr, index)
1476 : new IndexAccessor(fa, index));
1477 }
1478 )*
1479 {
1480 return fa == null ? expr : fa;
1481 }
vinayakb38b7ca42012-03-05 05:44:15 +00001482}
1483
1484Identifier Field() throws ParseException:
1485{
Till Westmann14a20a72013-05-09 00:06:24 -07001486 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001487}
1488{
Till Westmann96c1f172013-08-01 02:05:48 -07001489 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001490 {
Till Westmann14a20a72013-05-09 00:06:24 -07001491 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001492 }
vinayakb38b7ca42012-03-05 05:44:15 +00001493}
1494
1495int Index() throws ParseException:
1496{
1497 Expression expr = null;
1498 int idx = -2;
1499}
1500{
Till Westmann96c1f172013-08-01 02:05:48 -07001501 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001502 {
1503 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1504 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001505 Literal lit = ((LiteralExpr)expr).getValue();
1506 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1507 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001508 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001509 }
vinayakb38b7ca42012-03-05 05:44:15 +00001510 else {
1511 throw new ParseException("Index should be an INTEGER");
1512 }
1513 }
1514
1515 }
1516
Till Westmann96c1f172013-08-01 02:05:48 -07001517 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001518 {
1519 idx = IndexAccessor.ANY;
1520 // ANY
1521 }
1522
1523 )
1524
Till Westmann96c1f172013-08-01 02:05:48 -07001525 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001526 {
1527 return idx;
1528 }
1529}
1530
1531
1532Expression PrimaryExpr()throws ParseException:
1533{
1534 Expression expr = null;
1535}
1536{
Till Westmann68d99652013-05-09 11:15:21 -07001537 ( LOOKAHEAD(2)
1538 expr = FunctionCallExpr()
1539 | expr = Literal()
1540 | expr = DatasetAccessExpression()
1541 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001542 {
1543 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001544 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001545 }
Till Westmann68d99652013-05-09 11:15:21 -07001546 | expr = ListConstructor()
1547 | expr = RecordConstructor()
1548 | expr = ParenthesizedExpression()
1549 )
1550 {
1551 return expr;
1552 }
vinayakb38b7ca42012-03-05 05:44:15 +00001553}
1554
1555Expression Literal() throws ParseException:
1556{
vinayakb38b7ca42012-03-05 05:44:15 +00001557 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001558 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001559}
1560{
Till Westmann7d535322013-05-09 00:40:02 -07001561 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001562 {
Till Westmann7d535322013-05-09 00:40:02 -07001563 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001564 }
1565 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001566 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001567 try {
1568 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1569 } catch(NumberFormatException ex) {
1570 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1571 }
1572 }
1573 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001574 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001575 lit.setValue(new FloatLiteral(new Float(token.image)));
1576 }
1577 | <DOUBLE_LITERAL>
1578 {
1579 lit.setValue(new DoubleLiteral(new Double(token.image)));
1580 }
1581 | <NULL>
1582 {
1583 lit.setValue(NullLiteral.INSTANCE);
1584 }
1585 | <TRUE>
1586 {
1587 lit.setValue(TrueLiteral.INSTANCE);
1588 }
1589 | <FALSE>
1590 {
1591 lit.setValue(FalseLiteral.INSTANCE);
1592 }
1593 )
vinayakb38b7ca42012-03-05 05:44:15 +00001594 {
1595 return lit;
1596 }
1597}
1598
1599
1600VariableExpr VariableRef() throws ParseException:
1601{
1602 VariableExpr varExp = new VariableExpr();
1603 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001604}
1605{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001606 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001607 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001608 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001609 Identifier ident = lookupSymbol(varName);
1610 if (isInForbiddenScopes(varName)) {
1611 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.");
1612 }
1613 if(ident != null) { // exist such ident
1614 varExp.setIsNewVar(false);
1615 varExp.setVar((VarIdentifier)ident);
1616 } else {
1617 varExp.setVar(var);
1618 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001619 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001620 return varExp;
1621 }
1622}
1623
1624
1625VariableExpr Variable() throws ParseException:
1626{
1627 VariableExpr varExp = new VariableExpr();
1628 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001629}
1630{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001631 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001632 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001633 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001634 if(ident != null) { // exist such ident
1635 varExp.setIsNewVar(false);
1636 }
1637 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001638 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001639 return varExp;
1640 }
1641}
1642
1643Expression ListConstructor() throws ParseException:
1644{
1645 Expression expr = null;
1646}
1647{
1648 (
1649 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1650 )
1651
1652 {
1653 return expr;
1654 }
1655}
1656
1657
1658ListConstructor OrderedListConstructor() throws ParseException:
1659{
1660 ListConstructor expr = new ListConstructor();
1661 Expression tmp = null;
1662 List<Expression> exprList = new ArrayList<Expression>();
1663 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1664}
1665{
1666
Till Westmann96c1f172013-08-01 02:05:48 -07001667 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001668 ( tmp = Expression()
1669 {
1670 exprList.add(tmp);
1671 }
1672
Till Westmann96c1f172013-08-01 02:05:48 -07001673 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001674 )?
1675
Till Westmann96c1f172013-08-01 02:05:48 -07001676 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001677
1678 {
1679 expr.setExprList(exprList);
1680 return expr;
1681 }
1682}
1683
1684ListConstructor UnorderedListConstructor() throws ParseException:
1685{
1686 ListConstructor expr = new ListConstructor();
1687 Expression tmp = null;
1688 List<Expression> exprList = new ArrayList<Expression>();
1689 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1690}
1691{
1692
Till Westmann96c1f172013-08-01 02:05:48 -07001693 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001694 {
1695 exprList.add(tmp);
1696 }
Till Westmann96c1f172013-08-01 02:05:48 -07001697 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001698 {
1699 expr.setExprList(exprList);
1700 return expr;
1701 }
1702}
1703
1704RecordConstructor RecordConstructor() throws ParseException:
1705{
1706 RecordConstructor expr = new RecordConstructor();
1707 FieldBinding tmp = null;
1708 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1709}
1710{
Till Westmann96c1f172013-08-01 02:05:48 -07001711 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001712 {
1713 fbList.add(tmp);
1714 }
Till Westmann96c1f172013-08-01 02:05:48 -07001715 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001716 {
1717 expr.setFbList(fbList);
1718 return expr;
1719 }
1720}
1721
1722FieldBinding FieldBinding() throws ParseException:
1723{
1724 FieldBinding fb = new FieldBinding();
1725 Expression left, right;
1726}
1727{
Till Westmann96c1f172013-08-01 02:05:48 -07001728 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001729 {
1730 fb.setLeftExpr(left);
1731 fb.setRightExpr(right);
1732 return fb;
1733 }
1734}
1735
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001736
vinayakb38b7ca42012-03-05 05:44:15 +00001737Expression FunctionCallExpr() throws ParseException:
1738{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001739 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001740 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001741 Expression tmp;
1742 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001743 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001744 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001745}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001746{
ramangrover299f76a5e2013-06-18 10:25:17 -07001747 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001748 {
Till Westmann31c21f92013-05-08 09:21:53 -07001749 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001750 }
Till Westmann31c21f92013-05-08 09:21:53 -07001751 <LEFTPAREN> (tmp = Expression()
1752 {
1753 argList.add(tmp);
1754 arity ++;
1755 }
Till Westmann96c1f172013-08-01 02:05:48 -07001756 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001757 {
1758 argList.add(tmp);
1759 arity++;
1760 }
1761 )*)? <RIGHTPAREN>
1762 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001763 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001764 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001765 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001766 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001767 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001768 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001769 }
1770 callExpr = new CallExpr(signature,argList);
1771 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1772 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1773 }
1774 return callExpr;
1775 }
vinayakb38b7ca42012-03-05 05:44:15 +00001776}
1777
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001778
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001779Expression DatasetAccessExpression() throws ParseException:
1780{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001781 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001782 String arg1 = null;
1783 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001784 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001785}
1786{
Till Westmann14a20a72013-05-09 00:06:24 -07001787 <DATASET>
1788 {
Till Westmann14a20a72013-05-09 00:06:24 -07001789 funcName = token.image;
1790 }
Till Westmann96c1f172013-08-01 02:05:48 -07001791 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001792 {
1793 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001794 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001795 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001796 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001797 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001798 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001799 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001800 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1801 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1802 if (signature == null) {
1803 signature = new FunctionSignature(dataverse, funcName, 1);
1804 }
1805 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001806 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001807 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001808 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001809}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001810
vinayakb38b7ca42012-03-05 05:44:15 +00001811Expression ParenthesizedExpression() throws ParseException:
1812{
1813 Expression expr;
1814}
1815{
1816 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1817 {
1818 return expr;
1819 }
1820}
1821
1822Expression IfThenElse() throws ParseException:
1823{
1824 Expression condExpr;
1825 Expression thenExpr;
1826 Expression elseExpr;
1827 IfExpr ifExpr = new IfExpr();
1828}
1829{
Till Westmann96c1f172013-08-01 02:05:48 -07001830 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001831
1832 {
1833 ifExpr.setCondExpr(condExpr);
1834 ifExpr.setThenExpr(thenExpr);
1835 ifExpr.setElseExpr(elseExpr);
1836 return ifExpr;
1837 }
1838}
1839
1840Expression FLWOGR() throws ParseException:
1841{
1842 FLWOGRExpression flworg = new FLWOGRExpression();
1843 List<Clause> clauseList = new ArrayList<Clause>();
1844 Expression returnExpr;
1845 Clause tmp;
1846 createNewScope();
1847}
1848{
1849 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001850 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001851
1852 {
1853 flworg.setClauseList(clauseList);
1854 flworg.setReturnExpr(returnExpr);
1855 removeCurrentScope();
1856 return flworg;
1857 }
1858}
1859
1860Clause Clause()throws ParseException :
1861{
1862 Clause clause;
1863}
1864{
1865 (
1866 clause = ForClause()
1867 | clause = LetClause()
1868 | clause = WhereClause()
1869 | clause = OrderbyClause()
1870 | clause = GroupClause()
1871 | clause = LimitClause()
1872 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001873 )
1874 {
1875 return clause;
1876 }
1877}
1878
1879Clause ForClause()throws ParseException :
1880{
1881 ForClause fc = new ForClause();
1882 VariableExpr varExp;
1883 VariableExpr varPos = null;
1884 Expression inExp;
1885 extendCurrentScope();
1886}
1887{
Till Westmann96c1f172013-08-01 02:05:48 -07001888 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001889 {
1890 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001891 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001892 fc.setInExpr(inExp);
1893 if (varPos != null) {
1894 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001895 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001896 }
1897 return fc;
1898 }
1899}
1900
1901Clause LetClause() throws ParseException:
1902{
1903 LetClause lc = new LetClause();
1904 VariableExpr varExp;
1905 Expression beExp;
1906 extendCurrentScope();
1907}
1908{
Till Westmann96c1f172013-08-01 02:05:48 -07001909 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001910 {
1911 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001912 lc.setVarExpr(varExp);
1913 lc.setBeExpr(beExp);
1914 return lc;
1915 }
1916}
1917
1918Clause WhereClause()throws ParseException :
1919{
1920 WhereClause wc = new WhereClause();
1921 Expression whereExpr;
1922}
1923{
Till Westmann96c1f172013-08-01 02:05:48 -07001924 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001925 {
1926 wc.setWhereExpr(whereExpr);
1927 return wc;
1928 }
1929}
1930
1931Clause OrderbyClause()throws ParseException :
1932{
1933 OrderbyClause oc = new OrderbyClause();
1934 Expression orderbyExpr;
1935 List<Expression> orderbyList = new ArrayList<Expression>();
1936 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1937 int numOfOrderby = 0;
1938}
1939{
1940 (
Till Westmann96c1f172013-08-01 02:05:48 -07001941 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001942 {
1943 String hint = getHint(token);
1944 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1945 String splits[] = hint.split(" +");
1946 int numFrames = Integer.parseInt(splits[1]);
1947 int numTuples = Integer.parseInt(splits[2]);
1948 oc.setNumFrames(numFrames);
1949 oc.setNumTuples(numTuples);
1950 }
1951 }
Till Westmann96c1f172013-08-01 02:05:48 -07001952 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001953 {
1954 orderbyList.add(orderbyExpr);
1955 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1956 }
Till Westmann96c1f172013-08-01 02:05:48 -07001957 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1958 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001959 {
1960 modifierList.add(modif);
1961 }
1962
Till Westmann96c1f172013-08-01 02:05:48 -07001963 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001964 {
1965 orderbyList.add(orderbyExpr);
1966 modif = OrderbyClause.OrderModifier.ASC;
1967 }
Till Westmann96c1f172013-08-01 02:05:48 -07001968 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1969 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001970 {
1971 modifierList.add(modif);
1972 }
1973 )*
1974)
1975 {
1976 oc.setModifierList(modifierList);
1977 oc.setOrderbyList(orderbyList);
1978 return oc;
1979 }
1980}
1981Clause GroupClause()throws ParseException :
1982{
1983 GroupbyClause gbc = new GroupbyClause();
1984 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1985 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1986 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1987 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1988 VariableExpr var = null;
1989 VariableExpr withVar = null;
1990 Expression expr = null;
1991 VariableExpr decorVar = null;
1992 Expression decorExpr = null;
1993}
1994{
1995 {
1996 Scope newScope = extendCurrentScopeNoPush(true);
1997 // extendCurrentScope(true);
1998 }
Till Westmann96c1f172013-08-01 02:05:48 -07001999 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002000 {
2001 String hint = getHint(token);
2002 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2003 gbc.setHashGroupByHint(true);
2004 }
2005 }
Till Westmann96c1f172013-08-01 02:05:48 -07002006 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002007 {
2008 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002009 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002010 expr = Expression()
2011 {
2012 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2013 vePairList.add(pair1);
2014 }
Till Westmann96c1f172013-08-01 02:05:48 -07002015 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002016 {
2017 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002018 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002019 expr = Expression()
2020 {
2021 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2022 vePairList.add(pair2);
2023 }
2024 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002025 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002026 {
2027 newScope.addNewVarSymbolToScope(decorVar.getVar());
2028 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2029 decorPairList.add(pair3);
2030 }
Till Westmann96c1f172013-08-01 02:05:48 -07002031 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002032 {
2033 newScope.addNewVarSymbolToScope(decorVar.getVar());
2034 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2035 decorPairList.add(pair4);
2036 }
2037 )*
2038 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002039 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002040 {
2041 if(withVar.getIsNewVar()==true)
2042 throw new ParseException("can't find variable " + withVar.getVar());
2043 withVarList.add(withVar);
2044 newScope.addNewVarSymbolToScope(withVar.getVar());
2045 }
Till Westmann96c1f172013-08-01 02:05:48 -07002046 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002047 {
2048 if(withVar.getIsNewVar()==true)
2049 throw new ParseException("can't find variable " + withVar.getVar());
2050 withVarList.add(withVar);
2051 newScope.addNewVarSymbolToScope(withVar.getVar());
2052 })*
2053 {
2054 gbc.setGbyPairList(vePairList);
2055 gbc.setDecorPairList(decorPairList);
2056 gbc.setWithVarList(withVarList);
2057 replaceCurrentScope(newScope);
2058 return gbc;
2059 }
2060}
2061
2062
2063LimitClause LimitClause() throws ParseException:
2064{
2065 LimitClause lc = new LimitClause();
2066 Expression expr;
2067 pushForbiddenScope(getCurrentScope());
2068}
2069{
Till Westmann96c1f172013-08-01 02:05:48 -07002070 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2071 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002072
2073 {
2074 popForbiddenScope();
2075 return lc;
2076 }
2077}
2078
2079DistinctClause DistinctClause() throws ParseException:
2080{
2081 List<Expression> exprs = new ArrayList<Expression>();
2082 Expression expr;
2083}
2084{
Till Westmann96c1f172013-08-01 02:05:48 -07002085 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002086 {
2087 exprs.add(expr);
2088 }
Till Westmann96c1f172013-08-01 02:05:48 -07002089 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002090 {
2091 exprs.add(expr);
2092 }
2093 )*
2094 {
2095 return new DistinctClause(exprs);
2096 }
2097}
2098
vinayakb38b7ca42012-03-05 05:44:15 +00002099QuantifiedExpression QuantifiedExpression()throws ParseException:
2100{
2101 QuantifiedExpression qc = new QuantifiedExpression();
2102 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2103 Expression satisfiesExpr;
2104 VariableExpr var;
2105 Expression inExpr;
2106 QuantifiedPair pair;
2107}
2108{
2109 {
2110 createNewScope();
2111 }
2112
Till Westmann96c1f172013-08-01 02:05:48 -07002113 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2114 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2115 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002116 {
2117 pair = new QuantifiedPair(var, inExpr);
2118 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2119 quantifiedList.add(pair);
2120 }
2121 (
Till Westmann96c1f172013-08-01 02:05:48 -07002122 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002123 {
2124 pair = new QuantifiedPair(var, inExpr);
2125 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2126 quantifiedList.add(pair);
2127 }
2128 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002129 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002130 {
2131 qc.setSatisfiesExpr(satisfiesExpr);
2132 qc.setQuantifiedList(quantifiedList);
2133 removeCurrentScope();
2134 return qc;
2135 }
2136}
2137
2138TOKEN_MGR_DECLS:
2139{
Till Westmann96c1f172013-08-01 02:05:48 -07002140 public int commentDepth = 0;
2141 public IntStack lexerStateStack = new IntStack();
2142
2143 public void pushState() {
2144 lexerStateStack.push( curLexState );
2145 }
2146
2147 public void popState() {
2148 if (lexerStateStack.size() > 0) {
2149 SwitchTo( lexerStateStack.pop() );
2150 } else {
2151 throw new RuntimeException();
2152 }
2153 }
vinayakb38b7ca42012-03-05 05:44:15 +00002154}
2155
Till Westmann96c1f172013-08-01 02:05:48 -07002156<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002157TOKEN :
2158{
Till Westmann5df7b452013-08-02 13:07:16 -07002159 <ASC : "asc">
2160 | <AT : "at">
2161 | <BY : "by">
2162 | <DATASET : "dataset">
2163 | <DECOR : "decor">
2164 | <DESC : "desc">
2165 | <DISTINCT : "distinct">
2166 | <ELSE : "else">
2167 | <EVERY : "every">
2168 | <FOR : "for">
2169 | <GROUP : "group">
2170 | <IF : "if">
2171 | <IN : "in">
2172 | <LET : "let">
2173 | <LIMIT : "limit">
2174 | <OFFSET : "offset">
2175 | <ORDER : "order">
2176 | <RETURN : "return">
2177 | <SATISFIES : "satisfies">
2178 | <SOME : "some">
2179 | <THEN : "then">
2180 | <UNION : "union">
2181 | <WHERE : "where">
2182 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002183}
2184
Till Westmann96c1f172013-08-01 02:05:48 -07002185<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002186TOKEN :
2187{
Till Westmann5df7b452013-08-02 13:07:16 -07002188 <CARET : "^">
2189 | <DIV : "/">
2190 | <IDIV : "idiv">
2191 | <MINUS : "-">
2192 | <MOD : "%">
2193 | <MUL : "*">
2194 | <PLUS : "+">
2195
2196 | <LEFTPAREN : "(">
2197 | <RIGHTPAREN : ")">
2198 | <LEFTBRACKET : "[">
2199 | <RIGHTBRACKET : "]">
2200
2201 | <COLON : ":">
2202 | <COMMA : ",">
2203 | <DOT : ".">
2204 | <QUES : "?">
2205
2206 | <LT : "<">
2207 | <GT : ">">
2208 | <LE : "<=">
2209 | <GE : ">=">
2210 | <EQ : "=">
2211 | <NE : "!=">
2212 | <SIMILAR : "~=">
2213 | <ASSIGN : ":=">
2214
2215 | <AND : "and">
2216 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002217}
2218
Till Westmann96c1f172013-08-01 02:05:48 -07002219<DEFAULT,IN_DBL_BRACE>
2220TOKEN :
2221{
Till Westmann5df7b452013-08-02 13:07:16 -07002222 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002223}
2224
2225<DEFAULT>
2226TOKEN :
2227{
Till Westmann5df7b452013-08-02 13:07:16 -07002228 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002229}
2230
Till Westmann96c1f172013-08-01 02:05:48 -07002231<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002232TOKEN :
2233{
Till Westmann5df7b452013-08-02 13:07:16 -07002234 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002235}
2236
Till Westmann96c1f172013-08-01 02:05:48 -07002237<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002238TOKEN :
2239{
Till Westmann5df7b452013-08-02 13:07:16 -07002240 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002241}
2242
Till Westmann96c1f172013-08-01 02:05:48 -07002243<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002244TOKEN :
2245{
Till Westmann5df7b452013-08-02 13:07:16 -07002246 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002247}
2248
Till Westmann96c1f172013-08-01 02:05:48 -07002249<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002250TOKEN :
2251{
Till Westmann5df7b452013-08-02 13:07:16 -07002252 <NULL : "null">
2253 | <TRUE : "true">
2254 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002255}
2256
Till Westmann96c1f172013-08-01 02:05:48 -07002257<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002258TOKEN :
2259{
Till Westmann5df7b452013-08-02 13:07:16 -07002260 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002261}
2262
Till Westmann96c1f172013-08-01 02:05:48 -07002263<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002264TOKEN:
2265{
Till Westmann5df7b452013-08-02 13:07:16 -07002266 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002267 | <DIGITS> ( "." <DIGITS> )?
2268 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002269 >
2270 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002271 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2272 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002273 >
2274 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002275}
2276
Till Westmann96c1f172013-08-01 02:05:48 -07002277<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002278TOKEN :
2279{
Till Westmann5df7b452013-08-02 13:07:16 -07002280 <#LETTER : ["A" - "Z", "a" - "z"]>
2281 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002282}
2283
Till Westmann96c1f172013-08-01 02:05:48 -07002284<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002285TOKEN :
2286{
Till Westmann5df7b452013-08-02 13:07:16 -07002287 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2288 | < #EscapeQuot: "\\\"" >
2289 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002290}
2291
Till Westmann96c1f172013-08-01 02:05:48 -07002292<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002293TOKEN :
2294{
Till Westmann5df7b452013-08-02 13:07:16 -07002295 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002296}
2297
Till Westmann96c1f172013-08-01 02:05:48 -07002298<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002299TOKEN :
2300{
Till Westmann5df7b452013-08-02 13:07:16 -07002301 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002302}
2303
Till Westmann96c1f172013-08-01 02:05:48 -07002304<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002305SKIP:
2306{
2307 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002308 | "\t"
2309 | "\r"
2310 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002311}
2312
Till Westmann96c1f172013-08-01 02:05:48 -07002313<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002314SKIP:
2315{
Till Westmann5df7b452013-08-02 13:07:16 -07002316 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002317}
2318
Till Westmann96c1f172013-08-01 02:05:48 -07002319<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002320SKIP:
2321{
Till Westmann5df7b452013-08-02 13:07:16 -07002322 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002323}
2324
Till Westmann96c1f172013-08-01 02:05:48 -07002325<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002326SKIP:
2327{
Till Westmann96c1f172013-08-01 02:05:48 -07002328 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002329}
2330
2331<INSIDE_COMMENT>
2332SPECIAL_TOKEN:
2333{
Till Westmann5df7b452013-08-02 13:07:16 -07002334 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002335}
2336
2337<INSIDE_COMMENT>
2338SKIP:
2339{
Till Westmann96c1f172013-08-01 02:05:48 -07002340 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002341}
2342
2343<INSIDE_COMMENT>
2344SKIP:
2345{
Till Westmann96c1f172013-08-01 02:05:48 -07002346 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002347 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002348}