blob: 2e1bc6b6f7bc2adec847b0361b7403d0571cf45e [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{
555 FunctionSignature funcSig = null;
556}
557{
558 "apply" "function" funcSig = FunctionSignature()
559 {
560 return funcSig;
561 }
562}
563
ramangrover29566b3a92013-05-28 09:07:10 -0700564String GetPolicy() throws ParseException:
565{
566 String policy = null;
567}
568{
569 "using" "policy" policy = Identifier()
570 {
571 return policy;
572 }
573
574}
575
Till Westmann31c21f92013-05-08 09:21:53 -0700576FunctionSignature FunctionSignature() throws ParseException:
577{
ramangrover299f76a5e2013-06-18 10:25:17 -0700578 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700579 int arity = 0;
580}
581{
ramangrover299f76a5e2013-06-18 10:25:17 -0700582 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700583 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700584 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700585 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
586 throw new ParseException(" invalid arity:" + arity);
587 }
588
ramangrover299f76a5e2013-06-18 10:25:17 -0700589 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700590 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
591 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700592 }
593}
594
595List<String> PrimaryKey() throws ParseException:
596{
Till Westmann14a20a72013-05-09 00:06:24 -0700597 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700598 List<String> primaryKeyFields = new ArrayList<String>();
599}
600{
Till Westmann14a20a72013-05-09 00:06:24 -0700601 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700602 {
Till Westmann14a20a72013-05-09 00:06:24 -0700603 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700604 }
Till Westmann96c1f172013-08-01 02:05:48 -0700605 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700606 {
Till Westmann14a20a72013-05-09 00:06:24 -0700607 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700608 }
609 )*
610 {
611 return primaryKeyFields;
612 }
613}
614
615Statement DropStatement() throws ParseException:
616{
Till Westmann14a20a72013-05-09 00:06:24 -0700617 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700618 Pair<Identifier,Identifier> pairId = null;
619 Triple<Identifier,Identifier,Identifier> tripleId = null;
620 FunctionSignature funcSig = null;
621 boolean ifExists = false;
622 Statement stmt = null;
623}
624{
625 "drop"
626 (
627 <DATASET> pairId = QualifiedName() ifExists = IfExists()
628 {
629 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
630 }
631 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
632 {
633 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
634 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700635 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700636 {
Till Westmann14a20a72013-05-09 00:06:24 -0700637 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700638 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700639 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700640 {
641 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
642 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700643 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700644 {
Till Westmann14a20a72013-05-09 00:06:24 -0700645 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700646 }
647 | "function" funcSig = FunctionSignature() ifExists = IfExists()
648 {
649 stmt = new FunctionDropStatement(funcSig, ifExists);
650 }
ramangrover29a774ef22013-07-17 09:29:18 -0700651 | "feed" pairId = QualifiedName() ifExists = IfExists()
652 {
653 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
654 }
Till Westmann31c21f92013-05-08 09:21:53 -0700655 )
656 {
657 return stmt;
658 }
659}
660
661boolean IfExists() throws ParseException :
662{
663}
664{
Till Westmann96c1f172013-08-01 02:05:48 -0700665 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700666 {
667 return true;
668 }
669 )?
670 {
671 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000672 }
673}
674
675InsertStatement InsertStatement() throws ParseException:
676{
Till Westmann31c21f92013-05-08 09:21:53 -0700677 Pair<Identifier,Identifier> nameComponents = null;
678 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000679}
680{
Till Westmann31c21f92013-05-08 09:21:53 -0700681 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
682 {
683 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
684 }
vinayakb38b7ca42012-03-05 05:44:15 +0000685}
686
687DeleteStatement DeleteStatement() throws ParseException:
688{
Till Westmann31c21f92013-05-08 09:21:53 -0700689 VariableExpr var = null;
690 Expression condition = null;
691 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000692}
693{
Till Westmann31c21f92013-05-08 09:21:53 -0700694 "delete" var = Variable()
695 {
696 getCurrentScope().addNewVarSymbolToScope(var.getVar());
697 }
698 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700699 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700700 {
701 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
702 }
vinayakb38b7ca42012-03-05 05:44:15 +0000703}
704
705UpdateStatement UpdateStatement() throws ParseException:
706{
Till Westmann31c21f92013-05-08 09:21:53 -0700707 VariableExpr vars;
708 Expression target;
709 Expression condition;
710 UpdateClause uc;
711 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000712}
713{
Till Westmann96c1f172013-08-01 02:05:48 -0700714 "update" vars = Variable() <IN> target = Expression()
715 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700716 <LEFTPAREN> (uc = UpdateClause()
717 {
718 ucs.add(uc);
719 }
Till Westmann96c1f172013-08-01 02:05:48 -0700720 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700721 {
722 ucs.add(uc);
723 }
724 )*) <RIGHTPAREN>
725 {
726 return new UpdateStatement(vars, target, condition, ucs);
727 }
vinayakb38b7ca42012-03-05 05:44:15 +0000728}
729
vinayakb38b7ca42012-03-05 05:44:15 +0000730UpdateClause UpdateClause() throws ParseException:
731{
Till Westmann31c21f92013-05-08 09:21:53 -0700732 Expression target = null;
733 Expression value = null ;
734 InsertStatement is = null;
735 DeleteStatement ds = null;
736 UpdateStatement us = null;
737 Expression condition = null;
738 UpdateClause ifbranch = null;
739 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000740}
741{
Till Westmann96c1f172013-08-01 02:05:48 -0700742 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700743 | is = InsertStatement()
744 | ds = DeleteStatement()
745 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700746 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
747 <THEN> ifbranch = UpdateClause()
748 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700749 {
750 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
751 }
vinayakb38b7ca42012-03-05 05:44:15 +0000752}
753
vinayakb38b7ca42012-03-05 05:44:15 +0000754Statement SetStatement() throws ParseException:
755{
756 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700757 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000758}
759{
Till Westmann7d535322013-05-09 00:40:02 -0700760 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700761 {
Till Westmann31c21f92013-05-08 09:21:53 -0700762 return new SetStatement(pn, pv);
763 }
vinayakb38b7ca42012-03-05 05:44:15 +0000764}
765
766Statement WriteStatement() throws ParseException:
767{
Till Westmann14a20a72013-05-09 00:06:24 -0700768 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000769 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000770 Query query;
771 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000772 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000773}
774{
Till Westmann96c1f172013-08-01 02:05:48 -0700775 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700776 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700777 {
778 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000779 }
780}
781
vinayakb38b7ca42012-03-05 05:44:15 +0000782LoadFromFileStatement LoadStatement() throws ParseException:
783{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000784 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000785 Identifier datasetName = null;
786 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000787 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000788 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000789 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000790}
791{
Till Westmann31c21f92013-05-08 09:21:53 -0700792 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000793 {
Till Westmann31c21f92013-05-08 09:21:53 -0700794 dataverseName = nameComponents.first;
795 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000796 }
Till Westmann31c21f92013-05-08 09:21:53 -0700797 "using" adapterName = AdapterName() properties = Configuration()
798 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000799 {
Till Westmann31c21f92013-05-08 09:21:53 -0700800 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000801 }
802 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700803 {
804 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
805 }
vinayakb38b7ca42012-03-05 05:44:15 +0000806}
807
vinayakb38b7ca42012-03-05 05:44:15 +0000808
Till Westmann31c21f92013-05-08 09:21:53 -0700809String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000810{
ramangrover29669d8f62013-02-11 06:03:32 +0000811 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000812}
813{
Till Westmann68d99652013-05-09 11:15:21 -0700814 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000815 {
Till Westmann7d535322013-05-09 00:40:02 -0700816 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000817 }
vinayakb38b7ca42012-03-05 05:44:15 +0000818}
819
salsubaiee0b423fa2013-09-19 19:16:48 -0700820Statement CompactStatement() throws ParseException:
821{
822 Pair<Identifier,Identifier> nameComponents = null;
823 Statement stmt = null;
824}
825{
826 "compact" <DATASET> nameComponents = QualifiedName()
827 {
828 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
829 }
830 {
831 return stmt;
832 }
833}
834
Till Westmann31c21f92013-05-08 09:21:53 -0700835Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000836{
ramangrover29a774ef22013-07-17 09:29:18 -0700837 Pair<Identifier,Identifier> feedNameComponents = null;
838 Pair<Identifier,Identifier> datasetNameComponents = null;
839
Till Westmann31c21f92013-05-08 09:21:53 -0700840 Map<String,String> configuration = null;
841 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700842 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000843}
844{
Till Westmann31c21f92013-05-08 09:21:53 -0700845 (
ramangrover29a774ef22013-07-17 09:29:18 -0700846 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700847 {
ramangrover29a774ef22013-07-17 09:29:18 -0700848 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700849 }
ramangrover29a774ef22013-07-17 09:29:18 -0700850 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700851 {
ramangrover29a774ef22013-07-17 09:29:18 -0700852 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700853 }
854 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000855 {
Till Westmann31c21f92013-05-08 09:21:53 -0700856 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000857 }
858}
859
Till Westmann31c21f92013-05-08 09:21:53 -0700860Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000861{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000862 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700863 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000864}
865{
Till Westmann31c21f92013-05-08 09:21:53 -0700866 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000867 {
Till Westmann31c21f92013-05-08 09:21:53 -0700868 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000869 }
Till Westmann96c1f172013-08-01 02:05:48 -0700870 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000871 {
Till Westmann31c21f92013-05-08 09:21:53 -0700872 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000873 }
Till Westmann31c21f92013-05-08 09:21:53 -0700874 )* )? <RIGHTPAREN>
875 {
876 return configuration;
877 }
878}
879
880Pair<String, String> KeyValuePair() throws ParseException:
881{
882 String key;
883 String value;
884}
885{
Till Westmann96c1f172013-08-01 02:05:48 -0700886 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700887 {
888 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000889 }
Till Westmann31c21f92013-05-08 09:21:53 -0700890}
891
892Map<String,String> Properties() throws ParseException:
893{
894 Map<String,String> properties = new HashMap<String,String>();
895 Pair<String, String> property;
896}
897{
898 ( <LEFTPAREN> property = Property()
899 {
900 properties.put(property.first, property.second);
901 }
Till Westmann96c1f172013-08-01 02:05:48 -0700902 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700903 {
904 properties.put(property.first, property.second);
905 }
906 )* <RIGHTPAREN> )?
907 {
908 return properties;
909 }
910}
911
912Pair<String, String> Property() throws ParseException:
913{
914 String key;
915 String value;
916}
917{
Till Westmann96c1f172013-08-01 02:05:48 -0700918 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700919 {
920 try {
921 value = "" + Long.valueOf(token.image);
922 } catch (NumberFormatException nfe) {
923 throw new ParseException("inapproriate value: " + token.image);
924 }
925 }
926 )
927 {
928 return new Pair<String, String>(key.toUpperCase(), value);
929 }
vinayakb38b7ca42012-03-05 05:44:15 +0000930}
931
932TypeExpression TypeExpr() throws ParseException:
933{
934 TypeExpression typeExpr = null;
935}
936{
937 (
938 typeExpr = RecordTypeDef()
939 | typeExpr = TypeReference()
940 | typeExpr = OrderedListTypeDef()
941 | typeExpr = UnorderedListTypeDef()
942 )
943 {
944 return typeExpr;
945 }
946}
947
948RecordTypeDefinition RecordTypeDef() throws ParseException:
949{
950 RecordTypeDefinition recType = new RecordTypeDefinition();
951 RecordTypeDefinition.RecordKind recordKind = null;
952}
953{
954 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
955 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700956 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000957 {
958 String hint = getHint(token);
959 if (hint != null) {
960 String splits[] = hint.split(" +");
961 if (splits[0].equals(GEN_FIELDS_HINT)) {
962 if (splits.length != 5) {
963 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
964 }
965 if (!splits[1].equals("int")) {
966 throw new ParseException("The only supported type for gen-fields is int.");
967 }
968 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
969 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
970 recType.setUndeclaredFieldsDataGen(ufdg);
971 }
972 }
973
974 }
975 (
976 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700977 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000978 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700979 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000980 {
981 if (recordKind == null) {
982 recordKind = RecordTypeDefinition.RecordKind.OPEN;
983 }
984 recType.setRecordKind(recordKind);
985 return recType;
986 }
987}
988
989void RecordField(RecordTypeDefinition recType) throws ParseException:
990{
Till Westmann77cb2f42013-07-15 16:44:19 -0700991 String fieldName;
992 TypeExpression type = null;
993 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000994}
995{
Till Westmann77cb2f42013-07-15 16:44:19 -0700996 fieldName = Identifier()
997 {
998 String hint = getHint(token);
999 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1000 }
Till Westmann96c1f172013-08-01 02:05:48 -07001001 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001002 {
1003 recType.addField(fieldName, type, nullable, rfdg);
1004 }
vinayakb38b7ca42012-03-05 05:44:15 +00001005}
1006
1007TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001008{
Till Westmann14a20a72013-05-09 00:06:24 -07001009 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001010}
1011{
1012 id = Identifier()
1013 {
Till Westmann14a20a72013-05-09 00:06:24 -07001014 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001015 }
vinayakb38b7ca42012-03-05 05:44:15 +00001016}
1017
1018OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1019{
1020 TypeExpression type = null;
1021}
1022{
Till Westmann96c1f172013-08-01 02:05:48 -07001023 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001024 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001025 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001026 {
1027 return new OrderedListTypeDefinition(type);
1028 }
1029}
1030
1031
1032UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1033{
1034 TypeExpression type = null;
1035}
1036{
Till Westmann96c1f172013-08-01 02:05:48 -07001037 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001038 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001039 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001040 {
1041 return new UnorderedListTypeDefinition(type);
1042 }
1043}
1044
ramangrover299f76a5e2013-06-18 10:25:17 -07001045FunctionName FunctionName() throws ParseException:
1046{
1047 String first = null;
1048 String second = null;
1049 String third = null;
1050 boolean secondAfterDot = false;
1051}
1052{
Raman Groverd6780902013-09-24 16:57:32 +05301053 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001054 {
1055 secondAfterDot = true;
1056 }
1057 ("#" third = Identifier())? | "#" second = Identifier() )?
1058 {
1059 FunctionName result = new FunctionName();
1060 if (second == null) {
1061 result.dataverse = defaultDataverse;
1062 result.library = null;
1063 result.function = first;
1064 } else if (third == null) {
1065 if (secondAfterDot) {
1066 result.dataverse = first;
1067 result.library = null;
1068 result.function = second;
1069 } else {
1070 result.dataverse = defaultDataverse;
1071 result.library = first;
1072 result.function = second;
1073 }
1074 } else {
1075 result.dataverse = first;
1076 result.library = second;
1077 result.function = third;
1078 }
1079 return result;
1080 }
1081}
Till Westmann31c21f92013-05-08 09:21:53 -07001082
ramangrover299f76a5e2013-06-18 10:25:17 -07001083
1084Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001085{
Till Westmann31c21f92013-05-08 09:21:53 -07001086 Pair<Identifier,Identifier> name = null;
1087}
1088{
1089 name = QualifiedName()
1090 {
1091 if (name.first == null) {
1092 name.first = new Identifier(defaultDataverse);
1093 }
1094 return name;
1095 }
1096}
1097
Till Westmann14a20a72013-05-09 00:06:24 -07001098String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001099{
Till Westmann68d99652013-05-09 11:15:21 -07001100 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001101}
1102{
1103 <IDENTIFIER>
1104 {
Till Westmann14a20a72013-05-09 00:06:24 -07001105 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001106 }
Till Westmann68d99652013-05-09 11:15:21 -07001107 | lit = StringLiteral()
1108 {
1109 return lit;
1110 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001111}
1112
Till Westmann7d535322013-05-09 00:40:02 -07001113String StringLiteral() throws ParseException:
1114{
1115}
1116{
1117 <STRING_LITERAL>
1118 {
1119 return removeQuotesAndEscapes(token.image);
1120 }
1121}
1122
Till Westmann31c21f92013-05-08 09:21:53 -07001123Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1124{
Till Westmann14a20a72013-05-09 00:06:24 -07001125 String first = null;
1126 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001127}
1128{
Till Westmann96c1f172013-08-01 02:05:48 -07001129 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001130 {
Till Westmann14a20a72013-05-09 00:06:24 -07001131 Identifier id1 = null;
1132 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001133 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001134 id2 = new Identifier(first);
1135 } else
1136 {
1137 id1 = new Identifier(first);
1138 id2 = new Identifier(second);
1139 }
1140 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001141 }
1142}
1143
Till Westmann31c21f92013-05-08 09:21:53 -07001144Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001145{
Till Westmann14a20a72013-05-09 00:06:24 -07001146 String first = null;
1147 String second = null;
1148 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001149}
1150{
Till Westmann96c1f172013-08-01 02:05:48 -07001151 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001152 {
Till Westmann14a20a72013-05-09 00:06:24 -07001153 Identifier id1 = null;
1154 Identifier id2 = null;
1155 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001156 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001157 id2 = new Identifier(first);
1158 id3 = new Identifier(second);
1159 } else {
1160 id1 = new Identifier(first);
1161 id2 = new Identifier(second);
1162 id3 = new Identifier(third);
1163 }
1164 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001165 }
1166}
1167
vinayakb38b7ca42012-03-05 05:44:15 +00001168FunctionDecl FunctionDeclaration() throws ParseException:
1169{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001170 FunctionDecl funcDecl;
1171 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001172 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001173 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1174 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001175 createNewScope();
1176}
1177{
Till Westmannd7dcb122013-05-16 13:19:09 -07001178 "declare" "function" functionName = Identifier()
1179 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001180 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001181 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001182 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001183 getCurrentScope().addFunctionDescriptor(signature, false);
1184 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001185 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001186 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001187 }
1188}
1189
vinayakb38b7ca42012-03-05 05:44:15 +00001190
Till Westmann31c21f92013-05-08 09:21:53 -07001191Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001192{
1193 Query query = new Query();
1194 Expression expr;
1195}
1196{
Till Westmann31c21f92013-05-08 09:21:53 -07001197 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001198 {
1199 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001200 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001201 return query;
1202 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001203
vinayakb38b7ca42012-03-05 05:44:15 +00001204}
1205
1206
1207
1208Expression Expression():
1209{
1210 Expression expr = null;
1211 Expression exprP = null;
1212}
1213{
1214(
1215
1216//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1217 expr = OperatorExpr()
1218 | expr = IfThenElse()
1219 | expr = FLWOGR()
1220 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001221
vinayakb38b7ca42012-03-05 05:44:15 +00001222
1223)
1224 {
1225 return (exprP==null) ? expr : exprP;
1226 }
1227}
1228
1229
1230
1231Expression OperatorExpr()throws ParseException:
1232{
1233 OperatorExpr op = null;
1234 Expression operand = null;
1235}
1236{
1237 operand = AndExpr()
1238 (
1239
Till Westmann96c1f172013-08-01 02:05:48 -07001240 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001241 {
1242 if (op == null) {
1243 op = new OperatorExpr();
1244 op.addOperand(operand);
1245 op.setCurrentop(true);
1246 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001247 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001248 }
1249
1250 operand = AndExpr()
1251 {
1252 op.addOperand(operand);
1253 }
1254
1255 )*
1256
1257 {
1258 return op==null? operand: op;
1259 }
1260}
1261
1262Expression AndExpr()throws ParseException:
1263{
1264 OperatorExpr op = null;
1265 Expression operand = null;
1266}
1267{
1268 operand = RelExpr()
1269 (
1270
Till Westmann96c1f172013-08-01 02:05:48 -07001271 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001272 {
1273 if (op == null) {
1274 op = new OperatorExpr();
1275 op.addOperand(operand);
1276 op.setCurrentop(true);
1277 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001278 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001279 }
1280
1281 operand = RelExpr()
1282 {
1283 op.addOperand(operand);
1284 }
1285
1286 )*
1287
1288 {
1289 return op==null? operand: op;
1290 }
1291}
1292
1293
1294
1295Expression RelExpr()throws ParseException:
1296{
1297 OperatorExpr op = null;
1298 Expression operand = null;
1299 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001300 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001301}
1302{
1303 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001304 {
1305 if (operand instanceof VariableExpr) {
1306 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001307 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001308 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001309 }
1310 }
1311 }
1312
1313 (
Till Westmann96c1f172013-08-01 02:05:48 -07001314 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001315 {
alexander.behm07617fd2012-07-25 10:13:50 +00001316 String mhint = getHint(token);
1317 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1318 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1319 }
vinayakb38b7ca42012-03-05 05:44:15 +00001320 if (op == null) {
1321 op = new OperatorExpr();
1322 op.addOperand(operand, broadcast);
1323 op.setCurrentop(true);
1324 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001325 }
1326 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001327 }
1328
1329 operand = AddExpr()
1330 {
alexander.behm07617fd2012-07-25 10:13:50 +00001331 broadcast = false;
1332 if (operand instanceof VariableExpr) {
1333 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001334 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1335 broadcast = true;
1336 }
alexander.behm07617fd2012-07-25 10:13:50 +00001337 }
vinayakb38b7ca42012-03-05 05:44:15 +00001338 op.addOperand(operand, broadcast);
1339 }
1340 )?
1341
1342 {
alexander.behm07617fd2012-07-25 10:13:50 +00001343 if (annotation != null) {
1344 op.addHint(annotation);
1345 }
vinayakb38b7ca42012-03-05 05:44:15 +00001346 return op==null? operand: op;
1347 }
1348}
1349
1350Expression AddExpr()throws ParseException:
1351{
1352 OperatorExpr op = null;
1353 Expression operand = null;
1354}
1355{
1356 operand = MultExpr()
1357
Till Westmann96c1f172013-08-01 02:05:48 -07001358 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001359 {
1360 if (op == null) {
1361 op = new OperatorExpr();
1362 op.addOperand(operand);
1363 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001364 }
1365 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001366 }
1367
1368 operand = MultExpr()
1369 {
1370 op.addOperand(operand);
1371 }
1372 )*
1373
1374 {
1375 return op==null? operand: op;
1376 }
1377}
1378
1379Expression MultExpr()throws ParseException:
1380{
1381 OperatorExpr op = null;
1382 Expression operand = null;
1383}
1384{
1385 operand = UnionExpr()
1386
Till Westmann96c1f172013-08-01 02:05:48 -07001387 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001388 {
1389 if (op == null) {
1390 op = new OperatorExpr();
1391 op.addOperand(operand);
1392 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001393 }
1394 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001395 }
1396 operand = UnionExpr()
1397 {
1398 op.addOperand(operand);
1399 }
1400 )*
1401
1402 {
1403 return op==null?operand:op;
1404 }
1405}
1406
1407Expression UnionExpr() throws ParseException:
1408{
1409 UnionExpr union = null;
1410 Expression operand1 = null;
1411 Expression operand2 = null;
1412}
1413{
1414 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001415 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001416 (operand2 = UnaryExpr()) {
1417 if (union == null) {
1418 union = new UnionExpr();
1419 union.addExpr(operand1);
1420 }
1421 union.addExpr(operand2);
1422 } )*
1423 {
1424 return (union == null)? operand1: union;
1425 }
1426}
1427
1428Expression UnaryExpr() throws ParseException:
1429{
1430 Expression uexpr = null;
1431 Expression expr = null;
1432}
1433{
Till Westmann96c1f172013-08-01 02:05:48 -07001434 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001435 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001436 uexpr = new UnaryExpr();
1437 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001438 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001439 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001440 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1441 else
1442 throw new ParseException();
1443 }
1444 )?
1445
1446 expr = ValueExpr()
1447 {
1448 if(uexpr!=null){
1449 ((UnaryExpr)uexpr).setExpr(expr);
1450 return uexpr;
1451 }
1452 else{
1453 return expr;
1454 }
1455 }
1456}
1457
Till Westmann04478e72013-05-13 23:01:34 -07001458Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001459{
1460 Expression expr = null;
1461 Identifier ident = null;
1462 AbstractAccessor fa = null;
1463 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001464}
1465{
Till Westmann04478e72013-05-13 23:01:34 -07001466 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001467 {
Till Westmann04478e72013-05-13 23:01:34 -07001468 fa = (fa == null ? new FieldAccessor(expr, ident)
1469 : new FieldAccessor(fa, ident));
1470 }
1471 | index = Index()
1472 {
1473 fa = (fa == null ? new IndexAccessor(expr, index)
1474 : new IndexAccessor(fa, index));
1475 }
1476 )*
1477 {
1478 return fa == null ? expr : fa;
1479 }
vinayakb38b7ca42012-03-05 05:44:15 +00001480}
1481
1482Identifier Field() throws ParseException:
1483{
Till Westmann14a20a72013-05-09 00:06:24 -07001484 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001485}
1486{
Till Westmann96c1f172013-08-01 02:05:48 -07001487 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001488 {
Till Westmann14a20a72013-05-09 00:06:24 -07001489 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001490 }
vinayakb38b7ca42012-03-05 05:44:15 +00001491}
1492
1493int Index() throws ParseException:
1494{
1495 Expression expr = null;
1496 int idx = -2;
1497}
1498{
Till Westmann96c1f172013-08-01 02:05:48 -07001499 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001500 {
1501 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1502 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001503 Literal lit = ((LiteralExpr)expr).getValue();
1504 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1505 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001506 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001507 }
vinayakb38b7ca42012-03-05 05:44:15 +00001508 else {
1509 throw new ParseException("Index should be an INTEGER");
1510 }
1511 }
1512
1513 }
1514
Till Westmann96c1f172013-08-01 02:05:48 -07001515 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001516 {
1517 idx = IndexAccessor.ANY;
1518 // ANY
1519 }
1520
1521 )
1522
Till Westmann96c1f172013-08-01 02:05:48 -07001523 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001524 {
1525 return idx;
1526 }
1527}
1528
1529
1530Expression PrimaryExpr()throws ParseException:
1531{
1532 Expression expr = null;
1533}
1534{
Till Westmann68d99652013-05-09 11:15:21 -07001535 ( LOOKAHEAD(2)
1536 expr = FunctionCallExpr()
1537 | expr = Literal()
1538 | expr = DatasetAccessExpression()
1539 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001540 {
1541 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001542 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001543 }
Till Westmann68d99652013-05-09 11:15:21 -07001544 | expr = ListConstructor()
1545 | expr = RecordConstructor()
1546 | expr = ParenthesizedExpression()
1547 )
1548 {
1549 return expr;
1550 }
vinayakb38b7ca42012-03-05 05:44:15 +00001551}
1552
1553Expression Literal() throws ParseException:
1554{
vinayakb38b7ca42012-03-05 05:44:15 +00001555 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001556 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001557}
1558{
Till Westmann7d535322013-05-09 00:40:02 -07001559 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001560 {
Till Westmann7d535322013-05-09 00:40:02 -07001561 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001562 }
1563 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001564 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001565 try {
1566 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1567 } catch(NumberFormatException ex) {
1568 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1569 }
1570 }
1571 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001572 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001573 lit.setValue(new FloatLiteral(new Float(token.image)));
1574 }
1575 | <DOUBLE_LITERAL>
1576 {
1577 lit.setValue(new DoubleLiteral(new Double(token.image)));
1578 }
1579 | <NULL>
1580 {
1581 lit.setValue(NullLiteral.INSTANCE);
1582 }
1583 | <TRUE>
1584 {
1585 lit.setValue(TrueLiteral.INSTANCE);
1586 }
1587 | <FALSE>
1588 {
1589 lit.setValue(FalseLiteral.INSTANCE);
1590 }
1591 )
vinayakb38b7ca42012-03-05 05:44:15 +00001592 {
1593 return lit;
1594 }
1595}
1596
1597
1598VariableExpr VariableRef() throws ParseException:
1599{
1600 VariableExpr varExp = new VariableExpr();
1601 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001602}
1603{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001604 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001605 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001606 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001607 Identifier ident = lookupSymbol(varName);
1608 if (isInForbiddenScopes(varName)) {
1609 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.");
1610 }
1611 if(ident != null) { // exist such ident
1612 varExp.setIsNewVar(false);
1613 varExp.setVar((VarIdentifier)ident);
1614 } else {
1615 varExp.setVar(var);
1616 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001617 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001618 return varExp;
1619 }
1620}
1621
1622
1623VariableExpr Variable() throws ParseException:
1624{
1625 VariableExpr varExp = new VariableExpr();
1626 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001627}
1628{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001629 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001630 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001631 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001632 if(ident != null) { // exist such ident
1633 varExp.setIsNewVar(false);
1634 }
1635 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001636 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001637 return varExp;
1638 }
1639}
1640
1641Expression ListConstructor() throws ParseException:
1642{
1643 Expression expr = null;
1644}
1645{
1646 (
1647 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1648 )
1649
1650 {
1651 return expr;
1652 }
1653}
1654
1655
1656ListConstructor OrderedListConstructor() throws ParseException:
1657{
1658 ListConstructor expr = new ListConstructor();
1659 Expression tmp = null;
1660 List<Expression> exprList = new ArrayList<Expression>();
1661 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1662}
1663{
1664
Till Westmann96c1f172013-08-01 02:05:48 -07001665 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001666 ( tmp = Expression()
1667 {
1668 exprList.add(tmp);
1669 }
1670
Till Westmann96c1f172013-08-01 02:05:48 -07001671 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001672 )?
1673
Till Westmann96c1f172013-08-01 02:05:48 -07001674 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001675
1676 {
1677 expr.setExprList(exprList);
1678 return expr;
1679 }
1680}
1681
1682ListConstructor UnorderedListConstructor() throws ParseException:
1683{
1684 ListConstructor expr = new ListConstructor();
1685 Expression tmp = null;
1686 List<Expression> exprList = new ArrayList<Expression>();
1687 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1688}
1689{
1690
Till Westmann96c1f172013-08-01 02:05:48 -07001691 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001692 {
1693 exprList.add(tmp);
1694 }
Till Westmann96c1f172013-08-01 02:05:48 -07001695 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001696 {
1697 expr.setExprList(exprList);
1698 return expr;
1699 }
1700}
1701
1702RecordConstructor RecordConstructor() throws ParseException:
1703{
1704 RecordConstructor expr = new RecordConstructor();
1705 FieldBinding tmp = null;
1706 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1707}
1708{
Till Westmann96c1f172013-08-01 02:05:48 -07001709 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001710 {
1711 fbList.add(tmp);
1712 }
Till Westmann96c1f172013-08-01 02:05:48 -07001713 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001714 {
1715 expr.setFbList(fbList);
1716 return expr;
1717 }
1718}
1719
1720FieldBinding FieldBinding() throws ParseException:
1721{
1722 FieldBinding fb = new FieldBinding();
1723 Expression left, right;
1724}
1725{
Till Westmann96c1f172013-08-01 02:05:48 -07001726 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001727 {
1728 fb.setLeftExpr(left);
1729 fb.setRightExpr(right);
1730 return fb;
1731 }
1732}
1733
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001734
vinayakb38b7ca42012-03-05 05:44:15 +00001735Expression FunctionCallExpr() throws ParseException:
1736{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001737 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001738 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001739 Expression tmp;
1740 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001741 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001742 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001743}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001744{
ramangrover299f76a5e2013-06-18 10:25:17 -07001745 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001746 {
Till Westmann31c21f92013-05-08 09:21:53 -07001747 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001748 }
Till Westmann31c21f92013-05-08 09:21:53 -07001749 <LEFTPAREN> (tmp = Expression()
1750 {
1751 argList.add(tmp);
1752 arity ++;
1753 }
Till Westmann96c1f172013-08-01 02:05:48 -07001754 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001755 {
1756 argList.add(tmp);
1757 arity++;
1758 }
1759 )*)? <RIGHTPAREN>
1760 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001761 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001762 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001763 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001764 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001765 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001766 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001767 }
1768 callExpr = new CallExpr(signature,argList);
1769 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1770 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1771 }
1772 return callExpr;
1773 }
vinayakb38b7ca42012-03-05 05:44:15 +00001774}
1775
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001776
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001777Expression DatasetAccessExpression() throws ParseException:
1778{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001779 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001780 String arg1 = null;
1781 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001782 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001783}
1784{
Till Westmann14a20a72013-05-09 00:06:24 -07001785 <DATASET>
1786 {
Till Westmann14a20a72013-05-09 00:06:24 -07001787 funcName = token.image;
1788 }
Till Westmann96c1f172013-08-01 02:05:48 -07001789 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001790 {
1791 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001792 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001793 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001794 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001795 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001796 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001797 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001798 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1799 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1800 if (signature == null) {
1801 signature = new FunctionSignature(dataverse, funcName, 1);
1802 }
1803 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001804 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001805 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001806 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001807}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001808
vinayakb38b7ca42012-03-05 05:44:15 +00001809Expression ParenthesizedExpression() throws ParseException:
1810{
1811 Expression expr;
1812}
1813{
1814 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1815 {
1816 return expr;
1817 }
1818}
1819
1820Expression IfThenElse() throws ParseException:
1821{
1822 Expression condExpr;
1823 Expression thenExpr;
1824 Expression elseExpr;
1825 IfExpr ifExpr = new IfExpr();
1826}
1827{
Till Westmann96c1f172013-08-01 02:05:48 -07001828 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001829
1830 {
1831 ifExpr.setCondExpr(condExpr);
1832 ifExpr.setThenExpr(thenExpr);
1833 ifExpr.setElseExpr(elseExpr);
1834 return ifExpr;
1835 }
1836}
1837
1838Expression FLWOGR() throws ParseException:
1839{
1840 FLWOGRExpression flworg = new FLWOGRExpression();
1841 List<Clause> clauseList = new ArrayList<Clause>();
1842 Expression returnExpr;
1843 Clause tmp;
1844 createNewScope();
1845}
1846{
1847 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001848 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001849
1850 {
1851 flworg.setClauseList(clauseList);
1852 flworg.setReturnExpr(returnExpr);
1853 removeCurrentScope();
1854 return flworg;
1855 }
1856}
1857
1858Clause Clause()throws ParseException :
1859{
1860 Clause clause;
1861}
1862{
1863 (
1864 clause = ForClause()
1865 | clause = LetClause()
1866 | clause = WhereClause()
1867 | clause = OrderbyClause()
1868 | clause = GroupClause()
1869 | clause = LimitClause()
1870 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001871 )
1872 {
1873 return clause;
1874 }
1875}
1876
1877Clause ForClause()throws ParseException :
1878{
1879 ForClause fc = new ForClause();
1880 VariableExpr varExp;
1881 VariableExpr varPos = null;
1882 Expression inExp;
1883 extendCurrentScope();
1884}
1885{
Till Westmann96c1f172013-08-01 02:05:48 -07001886 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001887 {
1888 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001889 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001890 fc.setInExpr(inExp);
1891 if (varPos != null) {
1892 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001893 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001894 }
1895 return fc;
1896 }
1897}
1898
1899Clause LetClause() throws ParseException:
1900{
1901 LetClause lc = new LetClause();
1902 VariableExpr varExp;
1903 Expression beExp;
1904 extendCurrentScope();
1905}
1906{
Till Westmann96c1f172013-08-01 02:05:48 -07001907 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001908 {
1909 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001910 lc.setVarExpr(varExp);
1911 lc.setBeExpr(beExp);
1912 return lc;
1913 }
1914}
1915
1916Clause WhereClause()throws ParseException :
1917{
1918 WhereClause wc = new WhereClause();
1919 Expression whereExpr;
1920}
1921{
Till Westmann96c1f172013-08-01 02:05:48 -07001922 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001923 {
1924 wc.setWhereExpr(whereExpr);
1925 return wc;
1926 }
1927}
1928
1929Clause OrderbyClause()throws ParseException :
1930{
1931 OrderbyClause oc = new OrderbyClause();
1932 Expression orderbyExpr;
1933 List<Expression> orderbyList = new ArrayList<Expression>();
1934 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1935 int numOfOrderby = 0;
1936}
1937{
1938 (
Till Westmann96c1f172013-08-01 02:05:48 -07001939 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001940 {
1941 String hint = getHint(token);
1942 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1943 String splits[] = hint.split(" +");
1944 int numFrames = Integer.parseInt(splits[1]);
1945 int numTuples = Integer.parseInt(splits[2]);
1946 oc.setNumFrames(numFrames);
1947 oc.setNumTuples(numTuples);
1948 }
1949 }
Till Westmann96c1f172013-08-01 02:05:48 -07001950 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001951 {
1952 orderbyList.add(orderbyExpr);
1953 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1954 }
Till Westmann96c1f172013-08-01 02:05:48 -07001955 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1956 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001957 {
1958 modifierList.add(modif);
1959 }
1960
Till Westmann96c1f172013-08-01 02:05:48 -07001961 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001962 {
1963 orderbyList.add(orderbyExpr);
1964 modif = OrderbyClause.OrderModifier.ASC;
1965 }
Till Westmann96c1f172013-08-01 02:05:48 -07001966 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1967 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001968 {
1969 modifierList.add(modif);
1970 }
1971 )*
1972)
1973 {
1974 oc.setModifierList(modifierList);
1975 oc.setOrderbyList(orderbyList);
1976 return oc;
1977 }
1978}
1979Clause GroupClause()throws ParseException :
1980{
1981 GroupbyClause gbc = new GroupbyClause();
1982 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1983 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1984 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1985 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1986 VariableExpr var = null;
1987 VariableExpr withVar = null;
1988 Expression expr = null;
1989 VariableExpr decorVar = null;
1990 Expression decorExpr = null;
1991}
1992{
1993 {
1994 Scope newScope = extendCurrentScopeNoPush(true);
1995 // extendCurrentScope(true);
1996 }
Till Westmann96c1f172013-08-01 02:05:48 -07001997 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00001998 {
1999 String hint = getHint(token);
2000 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2001 gbc.setHashGroupByHint(true);
2002 }
2003 }
Till Westmann96c1f172013-08-01 02:05:48 -07002004 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002005 {
2006 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002007 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002008 expr = Expression()
2009 {
2010 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2011 vePairList.add(pair1);
2012 }
Till Westmann96c1f172013-08-01 02:05:48 -07002013 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002014 {
2015 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002016 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002017 expr = Expression()
2018 {
2019 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2020 vePairList.add(pair2);
2021 }
2022 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002023 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002024 {
2025 newScope.addNewVarSymbolToScope(decorVar.getVar());
2026 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2027 decorPairList.add(pair3);
2028 }
Till Westmann96c1f172013-08-01 02:05:48 -07002029 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002030 {
2031 newScope.addNewVarSymbolToScope(decorVar.getVar());
2032 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2033 decorPairList.add(pair4);
2034 }
2035 )*
2036 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002037 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002038 {
2039 if(withVar.getIsNewVar()==true)
2040 throw new ParseException("can't find variable " + withVar.getVar());
2041 withVarList.add(withVar);
2042 newScope.addNewVarSymbolToScope(withVar.getVar());
2043 }
Till Westmann96c1f172013-08-01 02:05:48 -07002044 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002045 {
2046 if(withVar.getIsNewVar()==true)
2047 throw new ParseException("can't find variable " + withVar.getVar());
2048 withVarList.add(withVar);
2049 newScope.addNewVarSymbolToScope(withVar.getVar());
2050 })*
2051 {
2052 gbc.setGbyPairList(vePairList);
2053 gbc.setDecorPairList(decorPairList);
2054 gbc.setWithVarList(withVarList);
2055 replaceCurrentScope(newScope);
2056 return gbc;
2057 }
2058}
2059
2060
2061LimitClause LimitClause() throws ParseException:
2062{
2063 LimitClause lc = new LimitClause();
2064 Expression expr;
2065 pushForbiddenScope(getCurrentScope());
2066}
2067{
Till Westmann96c1f172013-08-01 02:05:48 -07002068 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2069 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002070
2071 {
2072 popForbiddenScope();
2073 return lc;
2074 }
2075}
2076
2077DistinctClause DistinctClause() throws ParseException:
2078{
2079 List<Expression> exprs = new ArrayList<Expression>();
2080 Expression expr;
2081}
2082{
Till Westmann96c1f172013-08-01 02:05:48 -07002083 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002084 {
2085 exprs.add(expr);
2086 }
Till Westmann96c1f172013-08-01 02:05:48 -07002087 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002088 {
2089 exprs.add(expr);
2090 }
2091 )*
2092 {
2093 return new DistinctClause(exprs);
2094 }
2095}
2096
vinayakb38b7ca42012-03-05 05:44:15 +00002097QuantifiedExpression QuantifiedExpression()throws ParseException:
2098{
2099 QuantifiedExpression qc = new QuantifiedExpression();
2100 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2101 Expression satisfiesExpr;
2102 VariableExpr var;
2103 Expression inExpr;
2104 QuantifiedPair pair;
2105}
2106{
2107 {
2108 createNewScope();
2109 }
2110
Till Westmann96c1f172013-08-01 02:05:48 -07002111 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2112 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2113 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002114 {
2115 pair = new QuantifiedPair(var, inExpr);
2116 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2117 quantifiedList.add(pair);
2118 }
2119 (
Till Westmann96c1f172013-08-01 02:05:48 -07002120 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002121 {
2122 pair = new QuantifiedPair(var, inExpr);
2123 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2124 quantifiedList.add(pair);
2125 }
2126 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002127 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002128 {
2129 qc.setSatisfiesExpr(satisfiesExpr);
2130 qc.setQuantifiedList(quantifiedList);
2131 removeCurrentScope();
2132 return qc;
2133 }
2134}
2135
2136TOKEN_MGR_DECLS:
2137{
Till Westmann96c1f172013-08-01 02:05:48 -07002138 public int commentDepth = 0;
2139 public IntStack lexerStateStack = new IntStack();
2140
2141 public void pushState() {
2142 lexerStateStack.push( curLexState );
2143 }
2144
2145 public void popState() {
2146 if (lexerStateStack.size() > 0) {
2147 SwitchTo( lexerStateStack.pop() );
2148 } else {
2149 throw new RuntimeException();
2150 }
2151 }
vinayakb38b7ca42012-03-05 05:44:15 +00002152}
2153
Till Westmann96c1f172013-08-01 02:05:48 -07002154<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002155TOKEN :
2156{
Till Westmann5df7b452013-08-02 13:07:16 -07002157 <ASC : "asc">
2158 | <AT : "at">
2159 | <BY : "by">
2160 | <DATASET : "dataset">
2161 | <DECOR : "decor">
2162 | <DESC : "desc">
2163 | <DISTINCT : "distinct">
2164 | <ELSE : "else">
2165 | <EVERY : "every">
2166 | <FOR : "for">
2167 | <GROUP : "group">
2168 | <IF : "if">
2169 | <IN : "in">
2170 | <LET : "let">
2171 | <LIMIT : "limit">
2172 | <OFFSET : "offset">
2173 | <ORDER : "order">
2174 | <RETURN : "return">
2175 | <SATISFIES : "satisfies">
2176 | <SOME : "some">
2177 | <THEN : "then">
2178 | <UNION : "union">
2179 | <WHERE : "where">
2180 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002181}
2182
Till Westmann96c1f172013-08-01 02:05:48 -07002183<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002184TOKEN :
2185{
Till Westmann5df7b452013-08-02 13:07:16 -07002186 <CARET : "^">
2187 | <DIV : "/">
2188 | <IDIV : "idiv">
2189 | <MINUS : "-">
2190 | <MOD : "%">
2191 | <MUL : "*">
2192 | <PLUS : "+">
2193
2194 | <LEFTPAREN : "(">
2195 | <RIGHTPAREN : ")">
2196 | <LEFTBRACKET : "[">
2197 | <RIGHTBRACKET : "]">
2198
2199 | <COLON : ":">
2200 | <COMMA : ",">
2201 | <DOT : ".">
2202 | <QUES : "?">
2203
2204 | <LT : "<">
2205 | <GT : ">">
2206 | <LE : "<=">
2207 | <GE : ">=">
2208 | <EQ : "=">
2209 | <NE : "!=">
2210 | <SIMILAR : "~=">
2211 | <ASSIGN : ":=">
2212
2213 | <AND : "and">
2214 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002215}
2216
Till Westmann96c1f172013-08-01 02:05:48 -07002217<DEFAULT,IN_DBL_BRACE>
2218TOKEN :
2219{
Till Westmann5df7b452013-08-02 13:07:16 -07002220 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222
2223<DEFAULT>
2224TOKEN :
2225{
Till Westmann5df7b452013-08-02 13:07:16 -07002226 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002227}
2228
Till Westmann96c1f172013-08-01 02:05:48 -07002229<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002230TOKEN :
2231{
Till Westmann5df7b452013-08-02 13:07:16 -07002232 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002233}
2234
Till Westmann96c1f172013-08-01 02:05:48 -07002235<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002236TOKEN :
2237{
Till Westmann5df7b452013-08-02 13:07:16 -07002238 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002239}
2240
Till Westmann96c1f172013-08-01 02:05:48 -07002241<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002242TOKEN :
2243{
Till Westmann5df7b452013-08-02 13:07:16 -07002244 <INTEGER_LITERAL : (<DIGIT>)+ >
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 <NULL : "null">
2251 | <TRUE : "true">
2252 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002253}
2254
Till Westmann96c1f172013-08-01 02:05:48 -07002255<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002256TOKEN :
2257{
Till Westmann5df7b452013-08-02 13:07:16 -07002258 <#DIGIT : ["0" - "9"]>
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 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002265 | <DIGITS> ( "." <DIGITS> )?
2266 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002267 >
2268 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002269 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2270 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002271 >
2272 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002273}
2274
Till Westmann96c1f172013-08-01 02:05:48 -07002275<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002276TOKEN :
2277{
Till Westmann5df7b452013-08-02 13:07:16 -07002278 <#LETTER : ["A" - "Z", "a" - "z"]>
2279 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002280}
2281
Till Westmann96c1f172013-08-01 02:05:48 -07002282<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002283TOKEN :
2284{
Till Westmann5df7b452013-08-02 13:07:16 -07002285 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2286 | < #EscapeQuot: "\\\"" >
2287 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002288}
2289
Till Westmann96c1f172013-08-01 02:05:48 -07002290<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002291TOKEN :
2292{
Till Westmann5df7b452013-08-02 13:07:16 -07002293 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
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 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
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 +00002303SKIP:
2304{
2305 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002306 | "\t"
2307 | "\r"
2308 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002309}
2310
Till Westmann96c1f172013-08-01 02:05:48 -07002311<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002312SKIP:
2313{
Till Westmann5df7b452013-08-02 13:07:16 -07002314 <"//" (~["\n"])* "\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","\r"])* ("\n"|"\r"|"\r\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 Westmann96c1f172013-08-01 02:05:48 -07002326 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002327}
2328
2329<INSIDE_COMMENT>
2330SPECIAL_TOKEN:
2331{
Till Westmann5df7b452013-08-02 13:07:16 -07002332 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002333}
2334
2335<INSIDE_COMMENT>
2336SKIP:
2337{
Till Westmann96c1f172013-08-01 02:05:48 -07002338 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002339}
2340
2341<INSIDE_COMMENT>
2342SKIP:
2343{
Till Westmann96c1f172013-08-01 02:05:48 -07002344 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002345 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002346}