blob: e00bb2c72a906a54af556c2a0678ebe726538d26 [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";
salsubaieebb167912013-12-21 12:55:52 -080059 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
vinayakb38b7ca42012-03-05 05:44:15 +000060 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000061 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000062 private static final String INMEMORY_HINT = "inmem";
63 private static final String VAL_FILE_HINT = "val-files";
64 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
65 private static final String INTERVAL_HINT = "interval";
66 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
67 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
68 private static final String LIST_VAL_FILE_HINT = "list-val-file";
69 private static final String LIST_HINT = "list";
70 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
71 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
72 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
73 private static final String AUTO_HINT = "auto";
74
75 private static final String GEN_FIELDS_HINT = "gen-fields";
76
77 // data generator hints
78 private static final String DGEN_HINT = "dgen";
Till Westmann31c21f92013-05-08 09:21:53 -070079
80 private static class IndexParams {
81 public IndexType type;
82 public int gramLength;
83
84 public IndexParams(IndexType type, int gramLength) {
85 this.type = type;
86 this.gramLength = gramLength;
87 }
88 };
vinayakb38b7ca42012-03-05 05:44:15 +000089
ramangrover299f76a5e2013-06-18 10:25:17 -070090 private static class FunctionName {
91 public String dataverse = null;
92 public String library = null;
93 public String function = null;
94 }
95
vinayakb38b7ca42012-03-05 05:44:15 +000096 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070097 if (t.specialToken == null) {
98 return null;
99 }
100 String s = t.specialToken.image;
101 int n = s.length();
102 if (n < 2) {
103 return null;
104 }
105 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000106 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700107
108 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
109 IRecordFieldDataGen rfdg = null;
110 String splits[] = hint.split(" +");
111 if (splits[0].equals(VAL_FILE_HINT)) {
112 File[] valFiles = new File[splits.length - 1];
113 for (int k=1; k<splits.length; k++) {
114 valFiles[k-1] = new File(splits[k]);
115 }
116 rfdg = new FieldValFileDataGen(valFiles);
117 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
118 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
119 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
120 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
121 } else if (splits[0].equals(LIST_HINT)) {
122 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
123 } else if (splits[0].equals(INTERVAL_HINT)) {
124 FieldIntervalDataGen.ValueType vt;
125 if (splits[1].equals("int")) {
126 vt = FieldIntervalDataGen.ValueType.INT;
127 } else if (splits[1].equals("long")) {
128 vt = FieldIntervalDataGen.ValueType.LONG;
129 } else if (splits[1].equals("float")) {
130 vt = FieldIntervalDataGen.ValueType.FLOAT;
131 } else if (splits[1].equals("double")) {
132 vt = FieldIntervalDataGen.ValueType.DOUBLE;
133 } else {
134 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
135 }
136 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
137 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
138 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
139 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
140 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
141 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
142 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
143 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
144 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
145 } else if (splits[0].equals(AUTO_HINT)) {
146 rfdg = new AutoDataGen(splits[1]);
147 }
148 return rfdg;
149 }
vinayakb38b7ca42012-03-05 05:44:15 +0000150
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000151 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700152 this(new StringReader(s));
153 super.setInput(s);
154 }
vinayakb38b7ca42012-03-05 05:44:15 +0000155
Till Westmann31c21f92013-05-08 09:21:53 -0700156 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
157 File file = new File(args[0]);
158 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
159 AQLParser parser = new AQLParser(fis);
160 List<Statement> st = parser.Statement();
161 //st.accept(new AQLPrintVisitor(), 0);
162 }
vinayakb38b7ca42012-03-05 05:44:15 +0000163}
164
165PARSER_END(AQLParser)
166
167
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000168List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000169{
vinayakb38b7ca42012-03-05 05:44:15 +0000170 scopeStack.push(RootScopeFactory.createRootScope(this));
171 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700172 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000173}
174{
Till Westmann31c21f92013-05-08 09:21:53 -0700175 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000176 {
Till Westmann31c21f92013-05-08 09:21:53 -0700177 decls.add(stmt);
178 }
179 )*
180 <EOF>
181 {
182 return decls;
183 }
184}
185
186Statement SingleStatement() throws ParseException:
187{
188 Statement stmt = null;
189}
190{
191 (
192 stmt = DataverseDeclaration()
193 | stmt = FunctionDeclaration()
194 | stmt = CreateStatement()
195 | stmt = LoadStatement()
196 | stmt = DropStatement()
197 | stmt = WriteStatement()
198 | stmt = SetStatement()
199 | stmt = InsertStatement()
200 | stmt = DeleteStatement()
201 | stmt = UpdateStatement()
202 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700203 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700204 | stmt = Query()
205 )
206 {
207 return stmt;
208 }
209}
210
211DataverseDecl DataverseDeclaration() throws ParseException:
212{
Till Westmann14a20a72013-05-09 00:06:24 -0700213 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700214}
215{
Till Westmanna4242bc2013-05-08 17:49:55 -0700216 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700217 {
Till Westmann14a20a72013-05-09 00:06:24 -0700218 defaultDataverse = dvName;
219 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700220 }
221}
222
223Statement CreateStatement() throws ParseException:
224{
225 String hint = null;
226 boolean dgen = false;
227 Statement stmt = null;
228}
229{
230 "create"
231 (
232 {
233 hint = getHint(token);
234 if (hint != null && hint.startsWith(DGEN_HINT)) {
235 dgen = true;
236 }
237 }
238 stmt = TypeSpecification(hint, dgen)
239 | stmt = NodegroupSpecification()
240 | stmt = DatasetSpecification()
241 | stmt = IndexSpecification()
242 | stmt = DataverseSpecification()
243 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700244 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700245 )
246 {
247 return stmt;
248 }
249}
250
251TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
252{
253 Pair<Identifier,Identifier> nameComponents = null;
254 boolean ifNotExists = false;
255 TypeExpression typeExpr = null;
256}
257{
ramangrover299f76a5e2013-06-18 10:25:17 -0700258 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700259 "as" typeExpr = TypeExpr()
260 {
261 long numValues = -1;
262 String filename = null;
263 if (dgen) {
264 String splits[] = hint.split(" +");
265 if (splits.length != 3) {
266 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
267 }
268 filename = splits[1];
269 numValues = Long.parseLong(splits[2]);
270 }
271 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
272 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
273 }
274}
275
276
277NodegroupDecl NodegroupSpecification() throws ParseException:
278{
Till Westmann14a20a72013-05-09 00:06:24 -0700279 String name = null;
280 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700281 boolean ifNotExists = false;
282 List<Identifier>ncNames = null;
283}
284{
Till Westmanna4242bc2013-05-08 17:49:55 -0700285 "nodegroup" name = Identifier()
286 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700287 {
288 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700289 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700290 }
Till Westmann96c1f172013-08-01 02:05:48 -0700291 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700292 {
Till Westmann14a20a72013-05-09 00:06:24 -0700293 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700294 }
295 )*
296 {
Till Westmann14a20a72013-05-09 00:06:24 -0700297 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700298 }
299}
300
301DatasetDecl DatasetSpecification() throws ParseException:
302{
303 Pair<Identifier,Identifier> nameComponents = null;
304 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700305 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700306 String adapterName = null;
307 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700308 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700309 FunctionSignature appliedFunction = null;
310 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700311 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700312 Map<String,String> hints = new HashMap<String,String>();
313 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700314 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700315 String compactionPolicy = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700316}
317{
318 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700319 "external" <DATASET> nameComponents = QualifiedName()
320 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
321 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700322 "using" adapterName = AdapterName() properties = Configuration()
323 ( "hints" hints = Properties() )?
324 {
325 ExternalDetailsDecl edd = new ExternalDetailsDecl();
326 edd.setAdapter(adapterName);
327 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700328 dsetDecl = new DatasetDecl(nameComponents.first,
329 nameComponents.second,
330 new Identifier(typeName),
331 hints,
332 DatasetType.EXTERNAL,
333 edd,
334 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700335 }
336
Till Westmannd7dcb122013-05-16 13:19:09 -0700337 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700338 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
339 ifNotExists = IfNotExists()
zheilbron2467f2e2013-08-23 19:07:31 -0700340 primaryKeyFields = PrimaryKey()
341 ("autogenerated" { autogenerated = true; } )?
342 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700343 ( "hints" hints = Properties() )?
salsubaiee801bffe2013-09-22 23:42:35 -0700344 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() compactionPolicyProperties = Configuration() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700345 {
Till Westmann14a20a72013-05-09 00:06:24 -0700346 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
347 ? new Identifier(nodeGroupName)
348 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700349 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700350 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700351 compactionPolicy,
352 compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700353 dsetDecl = new DatasetDecl(nameComponents.first,
354 nameComponents.second,
355 new Identifier(typeName),
356 hints,
357 DatasetType.INTERNAL,
358 idd,
359 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700360 }
361 )
362 {
363 return dsetDecl;
364 }
365}
366
367CreateIndexStatement IndexSpecification() throws ParseException:
368{
369 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700370 String indexName = null;
371 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700372 boolean ifNotExists = false;
373 Pair<Identifier,Identifier> nameComponents = null;
374 IndexParams indexType = null;
375}
376{
Till Westmanna4242bc2013-05-08 17:49:55 -0700377 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700378 ifNotExists = IfNotExists()
379 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700380 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700381 {
Till Westmann14a20a72013-05-09 00:06:24 -0700382 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700383 }
Till Westmann96c1f172013-08-01 02:05:48 -0700384 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700385 {
Till Westmann14a20a72013-05-09 00:06:24 -0700386 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700387 }
388 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
389 {
Till Westmann14a20a72013-05-09 00:06:24 -0700390 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700391 cis.setIfNotExists(ifNotExists);
392 cis.setDataverseName(nameComponents.first);
393 cis.setDatasetName(nameComponents.second);
394 if (indexType != null) {
395 cis.setIndexType(indexType.type);
396 cis.setGramLength(indexType.gramLength);
397 }
398 return cis;
399 }
400}
401
salsubaiee0b423fa2013-09-19 19:16:48 -0700402String CompactionPolicy() throws ParseException :
403{
404 String compactionPolicy = null;
405}
406{
407 compactionPolicy = Identifier()
408 {
409 return compactionPolicy;
410 }
411}
412
Till Westmann31c21f92013-05-08 09:21:53 -0700413IndexParams IndexType() throws ParseException:
414{
415 IndexType type = null;
416 int gramLength = 0;
417}
418{
419 ("btree"
420 {
421 type = IndexType.BTREE;
422 }
423 | "rtree"
424 {
425 type = IndexType.RTREE;
426 }
427 | "keyword"
428 {
JIMAHNb75446d2013-06-03 08:35:27 -0700429 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700430 }
431 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
432 {
JIMAHNb75446d2013-06-03 08:35:27 -0700433 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700434 gramLength = Integer.valueOf(token.image);
435 }
436 <RIGHTPAREN>)
437 {
438 return new IndexParams(type, gramLength);
439 }
440}
441
442CreateDataverseStatement DataverseSpecification() throws ParseException :
443{
Till Westmann14a20a72013-05-09 00:06:24 -0700444 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700445 boolean ifNotExists = false;
446 String format = null;
447}
448{
Till Westmanna4242bc2013-05-08 17:49:55 -0700449 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700450 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700451 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700452 {
Till Westmann14a20a72013-05-09 00:06:24 -0700453 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700454 }
455}
456
457CreateFunctionStatement FunctionSpecification() throws ParseException:
458{
459 FunctionSignature signature;
460 boolean ifNotExists = false;
461 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
462 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700463 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700464 Expression functionBodyExpr;
465 Token beginPos;
466 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700467 FunctionName fctName = null;
468
Till Westmann31c21f92013-05-08 09:21:53 -0700469 createNewScope();
470}
471{
ramangrover299f76a5e2013-06-18 10:25:17 -0700472 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700473 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700474 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700475 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530476 {
477 beginPos = token;
478 }
Till Westmann96c1f172013-08-01 02:05:48 -0700479 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700480 {
481 endPos = token;
482 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700483 // TODO use fctName.library
484 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700485 getCurrentScope().addFunctionDescriptor(signature, false);
486 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
487 }
488}
489
ramangrover29a774ef22013-07-17 09:29:18 -0700490CreateFeedStatement FeedSpecification() throws ParseException:
491{
492 Pair<Identifier,Identifier> nameComponents = null;
493 boolean ifNotExists = false;
494 String adaptorName = null;
495 Map<String,String> properties = null;
496 FunctionSignature appliedFunction = null;
497 CreateFeedStatement cfs = null;
498}
499{
500 (
501 "feed" nameComponents = QualifiedName()
502 ifNotExists = IfNotExists()
503 "using" adaptorName = AdapterName() properties = Configuration()
504 (appliedFunction = ApplyFunction())?
505 {
506 cfs = new CreateFeedStatement(nameComponents.first,
507 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
508 }
509
510 )
511 {
512 return cfs;
513 }
514}
515
516
517
Till Westmannd7dcb122013-05-16 13:19:09 -0700518List<VarIdentifier> ParameterList() throws ParseException:
519{
520 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
521 VarIdentifier var = null;
522}
523{
Till Westmann31c21f92013-05-08 09:21:53 -0700524 <LEFTPAREN> (<VARIABLE>
525 {
526 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700527 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700528 paramList.add(var);
529 getCurrentScope().addNewVarSymbolToScope(var);
530 }
Till Westmann96c1f172013-08-01 02:05:48 -0700531 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700532 {
533 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700534 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700535 paramList.add(var);
536 getCurrentScope().addNewVarSymbolToScope(var);
537 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700538 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700539 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700540 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700541 }
542}
543
544boolean IfNotExists() throws ParseException:
545{
546}
547{
548 ( "if not exists"
549 {
550 return true;
551 }
552 )?
553 {
554 return false;
555 }
556}
557
558FunctionSignature ApplyFunction() throws ParseException:
559{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530560 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700561 FunctionSignature funcSig = null;
562}
563{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530564 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700565 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530566 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
567 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700568 }
569}
570
ramangrover29566b3a92013-05-28 09:07:10 -0700571String GetPolicy() throws ParseException:
572{
573 String policy = null;
574}
575{
576 "using" "policy" policy = Identifier()
577 {
578 return policy;
579 }
580
581}
582
Till Westmann31c21f92013-05-08 09:21:53 -0700583FunctionSignature FunctionSignature() throws ParseException:
584{
ramangrover299f76a5e2013-06-18 10:25:17 -0700585 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700586 int arity = 0;
587}
588{
ramangrover299f76a5e2013-06-18 10:25:17 -0700589 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700590 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700591 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700592 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
593 throw new ParseException(" invalid arity:" + arity);
594 }
595
ramangrover299f76a5e2013-06-18 10:25:17 -0700596 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700597 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
598 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700599 }
600}
601
602List<String> PrimaryKey() throws ParseException:
603{
Till Westmann14a20a72013-05-09 00:06:24 -0700604 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700605 List<String> primaryKeyFields = new ArrayList<String>();
606}
607{
Till Westmann14a20a72013-05-09 00:06:24 -0700608 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700609 {
Till Westmann14a20a72013-05-09 00:06:24 -0700610 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700611 }
Till Westmann96c1f172013-08-01 02:05:48 -0700612 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700613 {
Till Westmann14a20a72013-05-09 00:06:24 -0700614 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700615 }
616 )*
617 {
618 return primaryKeyFields;
619 }
620}
621
622Statement DropStatement() throws ParseException:
623{
Till Westmann14a20a72013-05-09 00:06:24 -0700624 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700625 Pair<Identifier,Identifier> pairId = null;
626 Triple<Identifier,Identifier,Identifier> tripleId = null;
627 FunctionSignature funcSig = null;
628 boolean ifExists = false;
629 Statement stmt = null;
630}
631{
632 "drop"
633 (
634 <DATASET> pairId = QualifiedName() ifExists = IfExists()
635 {
636 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
637 }
638 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
639 {
640 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
641 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700642 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700643 {
Till Westmann14a20a72013-05-09 00:06:24 -0700644 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700645 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700646 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700647 {
648 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
649 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700650 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700651 {
Till Westmann14a20a72013-05-09 00:06:24 -0700652 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700653 }
654 | "function" funcSig = FunctionSignature() ifExists = IfExists()
655 {
656 stmt = new FunctionDropStatement(funcSig, ifExists);
657 }
ramangrover29a774ef22013-07-17 09:29:18 -0700658 | "feed" pairId = QualifiedName() ifExists = IfExists()
659 {
660 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
661 }
Till Westmann31c21f92013-05-08 09:21:53 -0700662 )
663 {
664 return stmt;
665 }
666}
667
668boolean IfExists() throws ParseException :
669{
670}
671{
Till Westmann96c1f172013-08-01 02:05:48 -0700672 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700673 {
674 return true;
675 }
676 )?
677 {
678 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000679 }
680}
681
682InsertStatement InsertStatement() throws ParseException:
683{
Till Westmann31c21f92013-05-08 09:21:53 -0700684 Pair<Identifier,Identifier> nameComponents = null;
685 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000686}
687{
Till Westmann31c21f92013-05-08 09:21:53 -0700688 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
689 {
690 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
691 }
vinayakb38b7ca42012-03-05 05:44:15 +0000692}
693
694DeleteStatement DeleteStatement() throws ParseException:
695{
Till Westmann31c21f92013-05-08 09:21:53 -0700696 VariableExpr var = null;
697 Expression condition = null;
698 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000699}
700{
Till Westmann31c21f92013-05-08 09:21:53 -0700701 "delete" var = Variable()
702 {
703 getCurrentScope().addNewVarSymbolToScope(var.getVar());
704 }
salsubaieedf89fbc2013-12-21 19:51:42 -0800705 "from" <DATASET> nameComponents = QualifiedName()
706 (<WHERE> condition = Expression())?
707 {
708 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700709 }
vinayakb38b7ca42012-03-05 05:44:15 +0000710}
711
712UpdateStatement UpdateStatement() throws ParseException:
713{
Till Westmann31c21f92013-05-08 09:21:53 -0700714 VariableExpr vars;
715 Expression target;
716 Expression condition;
717 UpdateClause uc;
718 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000719}
720{
Till Westmann96c1f172013-08-01 02:05:48 -0700721 "update" vars = Variable() <IN> target = Expression()
722 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700723 <LEFTPAREN> (uc = UpdateClause()
724 {
725 ucs.add(uc);
726 }
Till Westmann96c1f172013-08-01 02:05:48 -0700727 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700728 {
729 ucs.add(uc);
730 }
731 )*) <RIGHTPAREN>
732 {
733 return new UpdateStatement(vars, target, condition, ucs);
734 }
vinayakb38b7ca42012-03-05 05:44:15 +0000735}
736
vinayakb38b7ca42012-03-05 05:44:15 +0000737UpdateClause UpdateClause() throws ParseException:
738{
Till Westmann31c21f92013-05-08 09:21:53 -0700739 Expression target = null;
740 Expression value = null ;
741 InsertStatement is = null;
742 DeleteStatement ds = null;
743 UpdateStatement us = null;
744 Expression condition = null;
745 UpdateClause ifbranch = null;
746 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000747}
748{
Till Westmann96c1f172013-08-01 02:05:48 -0700749 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700750 | is = InsertStatement()
751 | ds = DeleteStatement()
752 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700753 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
754 <THEN> ifbranch = UpdateClause()
755 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700756 {
757 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
758 }
vinayakb38b7ca42012-03-05 05:44:15 +0000759}
760
vinayakb38b7ca42012-03-05 05:44:15 +0000761Statement SetStatement() throws ParseException:
762{
763 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700764 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000765}
766{
Till Westmann7d535322013-05-09 00:40:02 -0700767 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700768 {
Till Westmann31c21f92013-05-08 09:21:53 -0700769 return new SetStatement(pn, pv);
770 }
vinayakb38b7ca42012-03-05 05:44:15 +0000771}
772
773Statement WriteStatement() throws ParseException:
774{
Till Westmann14a20a72013-05-09 00:06:24 -0700775 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000776 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000777 Query query;
778 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000779 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000780}
781{
Till Westmann96c1f172013-08-01 02:05:48 -0700782 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700783 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700784 {
785 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000786 }
787}
788
zheilbron28e026f2013-11-20 10:15:15 -0800789LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000790{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000791 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000792 Identifier datasetName = null;
793 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000794 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000795 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000796 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000797}
798{
Till Westmann31c21f92013-05-08 09:21:53 -0700799 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000800 {
Till Westmann31c21f92013-05-08 09:21:53 -0700801 dataverseName = nameComponents.first;
802 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000803 }
Till Westmann31c21f92013-05-08 09:21:53 -0700804 "using" adapterName = AdapterName() properties = Configuration()
805 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000806 {
Till Westmann31c21f92013-05-08 09:21:53 -0700807 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000808 }
809 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700810 {
zheilbron28e026f2013-11-20 10:15:15 -0800811 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Till Westmann31c21f92013-05-08 09:21:53 -0700812 }
vinayakb38b7ca42012-03-05 05:44:15 +0000813}
814
vinayakb38b7ca42012-03-05 05:44:15 +0000815
Till Westmann31c21f92013-05-08 09:21:53 -0700816String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000817{
ramangrover29669d8f62013-02-11 06:03:32 +0000818 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000819}
820{
Till Westmann68d99652013-05-09 11:15:21 -0700821 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000822 {
Till Westmann7d535322013-05-09 00:40:02 -0700823 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000824 }
vinayakb38b7ca42012-03-05 05:44:15 +0000825}
826
salsubaiee0b423fa2013-09-19 19:16:48 -0700827Statement CompactStatement() throws ParseException:
828{
829 Pair<Identifier,Identifier> nameComponents = null;
830 Statement stmt = null;
831}
832{
833 "compact" <DATASET> nameComponents = QualifiedName()
834 {
835 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
836 }
837 {
838 return stmt;
839 }
840}
841
Till Westmann31c21f92013-05-08 09:21:53 -0700842Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000843{
ramangrover29a774ef22013-07-17 09:29:18 -0700844 Pair<Identifier,Identifier> feedNameComponents = null;
845 Pair<Identifier,Identifier> datasetNameComponents = null;
846
Till Westmann31c21f92013-05-08 09:21:53 -0700847 Map<String,String> configuration = null;
848 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700849 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000850}
851{
Till Westmann31c21f92013-05-08 09:21:53 -0700852 (
ramangrover29a774ef22013-07-17 09:29:18 -0700853 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700854 {
ramangrover29a774ef22013-07-17 09:29:18 -0700855 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700856 }
ramangrover29a774ef22013-07-17 09:29:18 -0700857 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700858 {
ramangrover29a774ef22013-07-17 09:29:18 -0700859 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700860 }
861 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000862 {
Till Westmann31c21f92013-05-08 09:21:53 -0700863 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000864 }
865}
866
Till Westmann31c21f92013-05-08 09:21:53 -0700867Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000868{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000869 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700870 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000871}
872{
Till Westmann31c21f92013-05-08 09:21:53 -0700873 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000874 {
Till Westmann31c21f92013-05-08 09:21:53 -0700875 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000876 }
Till Westmann96c1f172013-08-01 02:05:48 -0700877 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000878 {
Till Westmann31c21f92013-05-08 09:21:53 -0700879 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000880 }
Till Westmann31c21f92013-05-08 09:21:53 -0700881 )* )? <RIGHTPAREN>
882 {
883 return configuration;
884 }
885}
886
887Pair<String, String> KeyValuePair() throws ParseException:
888{
889 String key;
890 String value;
891}
892{
Till Westmann96c1f172013-08-01 02:05:48 -0700893 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700894 {
895 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000896 }
Till Westmann31c21f92013-05-08 09:21:53 -0700897}
898
899Map<String,String> Properties() throws ParseException:
900{
901 Map<String,String> properties = new HashMap<String,String>();
902 Pair<String, String> property;
903}
904{
905 ( <LEFTPAREN> property = Property()
906 {
907 properties.put(property.first, property.second);
908 }
Till Westmann96c1f172013-08-01 02:05:48 -0700909 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700910 {
911 properties.put(property.first, property.second);
912 }
913 )* <RIGHTPAREN> )?
914 {
915 return properties;
916 }
917}
918
919Pair<String, String> Property() throws ParseException:
920{
921 String key;
922 String value;
923}
924{
Till Westmann96c1f172013-08-01 02:05:48 -0700925 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700926 {
927 try {
928 value = "" + Long.valueOf(token.image);
929 } catch (NumberFormatException nfe) {
930 throw new ParseException("inapproriate value: " + token.image);
931 }
932 }
933 )
934 {
935 return new Pair<String, String>(key.toUpperCase(), value);
936 }
vinayakb38b7ca42012-03-05 05:44:15 +0000937}
938
939TypeExpression TypeExpr() throws ParseException:
940{
941 TypeExpression typeExpr = null;
942}
943{
944 (
945 typeExpr = RecordTypeDef()
946 | typeExpr = TypeReference()
947 | typeExpr = OrderedListTypeDef()
948 | typeExpr = UnorderedListTypeDef()
949 )
950 {
951 return typeExpr;
952 }
953}
954
955RecordTypeDefinition RecordTypeDef() throws ParseException:
956{
957 RecordTypeDefinition recType = new RecordTypeDefinition();
958 RecordTypeDefinition.RecordKind recordKind = null;
959}
960{
961 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
962 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700963 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000964 {
965 String hint = getHint(token);
966 if (hint != null) {
967 String splits[] = hint.split(" +");
968 if (splits[0].equals(GEN_FIELDS_HINT)) {
969 if (splits.length != 5) {
970 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
971 }
972 if (!splits[1].equals("int")) {
973 throw new ParseException("The only supported type for gen-fields is int.");
974 }
975 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
976 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
977 recType.setUndeclaredFieldsDataGen(ufdg);
978 }
979 }
980
981 }
982 (
983 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700984 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000985 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700986 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000987 {
988 if (recordKind == null) {
989 recordKind = RecordTypeDefinition.RecordKind.OPEN;
990 }
991 recType.setRecordKind(recordKind);
992 return recType;
993 }
994}
995
996void RecordField(RecordTypeDefinition recType) throws ParseException:
997{
Till Westmann77cb2f42013-07-15 16:44:19 -0700998 String fieldName;
999 TypeExpression type = null;
1000 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001001}
1002{
Till Westmann77cb2f42013-07-15 16:44:19 -07001003 fieldName = Identifier()
1004 {
1005 String hint = getHint(token);
1006 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1007 }
Till Westmann96c1f172013-08-01 02:05:48 -07001008 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001009 {
1010 recType.addField(fieldName, type, nullable, rfdg);
1011 }
vinayakb38b7ca42012-03-05 05:44:15 +00001012}
1013
1014TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001015{
Till Westmann14a20a72013-05-09 00:06:24 -07001016 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001017}
1018{
1019 id = Identifier()
1020 {
Till Westmann14a20a72013-05-09 00:06:24 -07001021 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001022 }
vinayakb38b7ca42012-03-05 05:44:15 +00001023}
1024
1025OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1026{
1027 TypeExpression type = null;
1028}
1029{
Till Westmann96c1f172013-08-01 02:05:48 -07001030 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001031 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001032 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001033 {
1034 return new OrderedListTypeDefinition(type);
1035 }
1036}
1037
1038
1039UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1040{
1041 TypeExpression type = null;
1042}
1043{
Till Westmann96c1f172013-08-01 02:05:48 -07001044 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001045 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001046 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001047 {
1048 return new UnorderedListTypeDefinition(type);
1049 }
1050}
1051
ramangrover299f76a5e2013-06-18 10:25:17 -07001052FunctionName FunctionName() throws ParseException:
1053{
1054 String first = null;
1055 String second = null;
1056 String third = null;
1057 boolean secondAfterDot = false;
1058}
1059{
zheilbron555dc9d2013-08-14 19:58:00 -07001060 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001061 {
1062 secondAfterDot = true;
1063 }
1064 ("#" third = Identifier())? | "#" second = Identifier() )?
1065 {
1066 FunctionName result = new FunctionName();
1067 if (second == null) {
1068 result.dataverse = defaultDataverse;
1069 result.library = null;
1070 result.function = first;
1071 } else if (third == null) {
1072 if (secondAfterDot) {
1073 result.dataverse = first;
1074 result.library = null;
1075 result.function = second;
1076 } else {
1077 result.dataverse = defaultDataverse;
1078 result.library = first;
1079 result.function = second;
1080 }
1081 } else {
1082 result.dataverse = first;
1083 result.library = second;
1084 result.function = third;
1085 }
1086 return result;
1087 }
1088}
Till Westmann31c21f92013-05-08 09:21:53 -07001089
ramangrover299f76a5e2013-06-18 10:25:17 -07001090
1091Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001092{
Till Westmann31c21f92013-05-08 09:21:53 -07001093 Pair<Identifier,Identifier> name = null;
1094}
1095{
1096 name = QualifiedName()
1097 {
1098 if (name.first == null) {
1099 name.first = new Identifier(defaultDataverse);
1100 }
1101 return name;
1102 }
1103}
1104
Till Westmann14a20a72013-05-09 00:06:24 -07001105String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001106{
Till Westmann68d99652013-05-09 11:15:21 -07001107 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001108}
1109{
1110 <IDENTIFIER>
1111 {
Till Westmann14a20a72013-05-09 00:06:24 -07001112 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001113 }
Till Westmann68d99652013-05-09 11:15:21 -07001114 | lit = StringLiteral()
1115 {
1116 return lit;
1117 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001118}
1119
Till Westmann7d535322013-05-09 00:40:02 -07001120String StringLiteral() throws ParseException:
1121{
1122}
1123{
1124 <STRING_LITERAL>
1125 {
1126 return removeQuotesAndEscapes(token.image);
1127 }
1128}
1129
Till Westmann31c21f92013-05-08 09:21:53 -07001130Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1131{
Till Westmann14a20a72013-05-09 00:06:24 -07001132 String first = null;
1133 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001134}
1135{
Till Westmann96c1f172013-08-01 02:05:48 -07001136 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001137 {
Till Westmann14a20a72013-05-09 00:06:24 -07001138 Identifier id1 = null;
1139 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001140 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001141 id2 = new Identifier(first);
1142 } else
1143 {
1144 id1 = new Identifier(first);
1145 id2 = new Identifier(second);
1146 }
1147 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001148 }
1149}
1150
Till Westmann31c21f92013-05-08 09:21:53 -07001151Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001152{
Till Westmann14a20a72013-05-09 00:06:24 -07001153 String first = null;
1154 String second = null;
1155 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001156}
1157{
Till Westmann96c1f172013-08-01 02:05:48 -07001158 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001159 {
Till Westmann14a20a72013-05-09 00:06:24 -07001160 Identifier id1 = null;
1161 Identifier id2 = null;
1162 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001163 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001164 id2 = new Identifier(first);
1165 id3 = new Identifier(second);
1166 } else {
1167 id1 = new Identifier(first);
1168 id2 = new Identifier(second);
1169 id3 = new Identifier(third);
1170 }
1171 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001172 }
1173}
1174
vinayakb38b7ca42012-03-05 05:44:15 +00001175FunctionDecl FunctionDeclaration() throws ParseException:
1176{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001177 FunctionDecl funcDecl;
1178 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001179 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001180 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1181 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001182 createNewScope();
1183}
1184{
Till Westmannd7dcb122013-05-16 13:19:09 -07001185 "declare" "function" functionName = Identifier()
1186 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001187 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001188 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001189 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001190 getCurrentScope().addFunctionDescriptor(signature, false);
1191 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001192 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001193 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001194 }
1195}
1196
vinayakb38b7ca42012-03-05 05:44:15 +00001197
Till Westmann31c21f92013-05-08 09:21:53 -07001198Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001199{
1200 Query query = new Query();
1201 Expression expr;
1202}
1203{
Till Westmann31c21f92013-05-08 09:21:53 -07001204 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001205 {
1206 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001207 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001208 return query;
1209 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001210
vinayakb38b7ca42012-03-05 05:44:15 +00001211}
1212
1213
1214
1215Expression Expression():
1216{
1217 Expression expr = null;
1218 Expression exprP = null;
1219}
1220{
1221(
1222
1223//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1224 expr = OperatorExpr()
1225 | expr = IfThenElse()
1226 | expr = FLWOGR()
1227 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001228
vinayakb38b7ca42012-03-05 05:44:15 +00001229
1230)
1231 {
1232 return (exprP==null) ? expr : exprP;
1233 }
1234}
1235
1236
1237
1238Expression OperatorExpr()throws ParseException:
1239{
1240 OperatorExpr op = null;
1241 Expression operand = null;
1242}
1243{
1244 operand = AndExpr()
1245 (
1246
Till Westmann96c1f172013-08-01 02:05:48 -07001247 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001248 {
1249 if (op == null) {
1250 op = new OperatorExpr();
1251 op.addOperand(operand);
1252 op.setCurrentop(true);
1253 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001254 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001255 }
1256
1257 operand = AndExpr()
1258 {
1259 op.addOperand(operand);
1260 }
1261
1262 )*
1263
1264 {
1265 return op==null? operand: op;
1266 }
1267}
1268
1269Expression AndExpr()throws ParseException:
1270{
1271 OperatorExpr op = null;
1272 Expression operand = null;
1273}
1274{
1275 operand = RelExpr()
1276 (
1277
Till Westmann96c1f172013-08-01 02:05:48 -07001278 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001279 {
1280 if (op == null) {
1281 op = new OperatorExpr();
1282 op.addOperand(operand);
1283 op.setCurrentop(true);
1284 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001285 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001286 }
1287
1288 operand = RelExpr()
1289 {
1290 op.addOperand(operand);
1291 }
1292
1293 )*
1294
1295 {
1296 return op==null? operand: op;
1297 }
1298}
1299
1300
1301
1302Expression RelExpr()throws ParseException:
1303{
1304 OperatorExpr op = null;
1305 Expression operand = null;
1306 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001307 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001308}
1309{
1310 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001311 {
1312 if (operand instanceof VariableExpr) {
1313 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001314 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001315 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001316 }
1317 }
1318 }
1319
1320 (
Till Westmann96c1f172013-08-01 02:05:48 -07001321 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001322 {
alexander.behm07617fd2012-07-25 10:13:50 +00001323 String mhint = getHint(token);
salsubaieedf89fbc2013-12-21 19:51:42 -08001324 if (mhint != null) {
1325 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1326 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1327 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1328 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1329 }
alexander.behm07617fd2012-07-25 10:13:50 +00001330 }
vinayakb38b7ca42012-03-05 05:44:15 +00001331 if (op == null) {
1332 op = new OperatorExpr();
1333 op.addOperand(operand, broadcast);
1334 op.setCurrentop(true);
1335 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001336 }
1337 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001338 }
1339
1340 operand = AddExpr()
1341 {
alexander.behm07617fd2012-07-25 10:13:50 +00001342 broadcast = false;
1343 if (operand instanceof VariableExpr) {
1344 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001345 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1346 broadcast = true;
1347 }
alexander.behm07617fd2012-07-25 10:13:50 +00001348 }
vinayakb38b7ca42012-03-05 05:44:15 +00001349 op.addOperand(operand, broadcast);
1350 }
1351 )?
1352
1353 {
alexander.behm07617fd2012-07-25 10:13:50 +00001354 if (annotation != null) {
1355 op.addHint(annotation);
1356 }
vinayakb38b7ca42012-03-05 05:44:15 +00001357 return op==null? operand: op;
1358 }
1359}
1360
1361Expression AddExpr()throws ParseException:
1362{
1363 OperatorExpr op = null;
1364 Expression operand = null;
1365}
1366{
1367 operand = MultExpr()
1368
Till Westmann96c1f172013-08-01 02:05:48 -07001369 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001370 {
1371 if (op == null) {
1372 op = new OperatorExpr();
1373 op.addOperand(operand);
1374 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001375 }
1376 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001377 }
1378
1379 operand = MultExpr()
1380 {
1381 op.addOperand(operand);
1382 }
1383 )*
1384
1385 {
1386 return op==null? operand: op;
1387 }
1388}
1389
1390Expression MultExpr()throws ParseException:
1391{
1392 OperatorExpr op = null;
1393 Expression operand = null;
1394}
1395{
1396 operand = UnionExpr()
1397
Till Westmann96c1f172013-08-01 02:05:48 -07001398 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001399 {
1400 if (op == null) {
1401 op = new OperatorExpr();
1402 op.addOperand(operand);
1403 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001404 }
1405 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001406 }
1407 operand = UnionExpr()
1408 {
1409 op.addOperand(operand);
1410 }
1411 )*
1412
1413 {
1414 return op==null?operand:op;
1415 }
1416}
1417
1418Expression UnionExpr() throws ParseException:
1419{
1420 UnionExpr union = null;
1421 Expression operand1 = null;
1422 Expression operand2 = null;
1423}
1424{
1425 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001426 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001427 (operand2 = UnaryExpr()) {
1428 if (union == null) {
1429 union = new UnionExpr();
1430 union.addExpr(operand1);
1431 }
1432 union.addExpr(operand2);
1433 } )*
1434 {
1435 return (union == null)? operand1: union;
1436 }
1437}
1438
1439Expression UnaryExpr() throws ParseException:
1440{
1441 Expression uexpr = null;
1442 Expression expr = null;
1443}
1444{
Till Westmann96c1f172013-08-01 02:05:48 -07001445 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001446 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001447 uexpr = new UnaryExpr();
1448 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001449 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001450 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001451 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1452 else
1453 throw new ParseException();
1454 }
1455 )?
1456
1457 expr = ValueExpr()
1458 {
1459 if(uexpr!=null){
1460 ((UnaryExpr)uexpr).setExpr(expr);
1461 return uexpr;
1462 }
1463 else{
1464 return expr;
1465 }
1466 }
1467}
1468
Till Westmann04478e72013-05-13 23:01:34 -07001469Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001470{
1471 Expression expr = null;
1472 Identifier ident = null;
1473 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001474 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001475}
1476{
Till Westmann04478e72013-05-13 23:01:34 -07001477 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001478 {
Till Westmann04478e72013-05-13 23:01:34 -07001479 fa = (fa == null ? new FieldAccessor(expr, ident)
1480 : new FieldAccessor(fa, ident));
1481 }
icetindila611ac72014-05-16 10:10:11 -07001482 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001483 {
icetindila611ac72014-05-16 10:10:11 -07001484 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1485 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001486 }
1487 )*
1488 {
1489 return fa == null ? expr : fa;
1490 }
vinayakb38b7ca42012-03-05 05:44:15 +00001491}
1492
1493Identifier Field() throws ParseException:
1494{
Till Westmann14a20a72013-05-09 00:06:24 -07001495 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001496}
1497{
Till Westmann96c1f172013-08-01 02:05:48 -07001498 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001499 {
Till Westmann14a20a72013-05-09 00:06:24 -07001500 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001501 }
vinayakb38b7ca42012-03-05 05:44:15 +00001502}
1503
icetindila611ac72014-05-16 10:10:11 -07001504Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001505{
1506 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001507}
1508{
Till Westmann96c1f172013-08-01 02:05:48 -07001509 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001510 {
1511 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1512 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001513 Literal lit = ((LiteralExpr)expr).getValue();
icetindila611ac72014-05-16 10:10:11 -07001514 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1515 lit.getLiteralType() != Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001516 throw new ParseException("Index should be an INTEGER");
1517 }
1518 }
vinayakb38b7ca42012-03-05 05:44:15 +00001519 }
1520
icetindil5860fb92014-05-16 11:22:15 -07001521 | <QUES> // ANY
vinayakb38b7ca42012-03-05 05:44:15 +00001522
1523 )
1524
Till Westmann96c1f172013-08-01 02:05:48 -07001525 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001526 {
icetindila611ac72014-05-16 10:10:11 -07001527 return expr;
vinayakb38b7ca42012-03-05 05:44:15 +00001528 }
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);
salsubaieedf89fbc2013-12-21 19:51:42 -08001771 if (hint != null) {
1772 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1773 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1774 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1775 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1776 }
Till Westmann31c21f92013-05-08 09:21:53 -07001777 }
1778 return callExpr;
1779 }
vinayakb38b7ca42012-03-05 05:44:15 +00001780}
1781
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001782
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001783Expression DatasetAccessExpression() throws ParseException:
1784{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001785 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001786 String arg1 = null;
1787 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001788 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001789}
1790{
Till Westmann14a20a72013-05-09 00:06:24 -07001791 <DATASET>
1792 {
Till Westmann14a20a72013-05-09 00:06:24 -07001793 funcName = token.image;
1794 }
Till Westmann96c1f172013-08-01 02:05:48 -07001795 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001796 {
1797 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001798 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001799 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001800 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001801 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001802 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001803 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001804 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1805 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1806 if (signature == null) {
1807 signature = new FunctionSignature(dataverse, funcName, 1);
1808 }
1809 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001810 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001811 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001812 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001813}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001814
vinayakb38b7ca42012-03-05 05:44:15 +00001815Expression ParenthesizedExpression() throws ParseException:
1816{
1817 Expression expr;
1818}
1819{
1820 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1821 {
1822 return expr;
1823 }
1824}
1825
1826Expression IfThenElse() throws ParseException:
1827{
1828 Expression condExpr;
1829 Expression thenExpr;
1830 Expression elseExpr;
1831 IfExpr ifExpr = new IfExpr();
1832}
1833{
Till Westmann96c1f172013-08-01 02:05:48 -07001834 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001835
1836 {
1837 ifExpr.setCondExpr(condExpr);
1838 ifExpr.setThenExpr(thenExpr);
1839 ifExpr.setElseExpr(elseExpr);
1840 return ifExpr;
1841 }
1842}
1843
1844Expression FLWOGR() throws ParseException:
1845{
1846 FLWOGRExpression flworg = new FLWOGRExpression();
1847 List<Clause> clauseList = new ArrayList<Clause>();
1848 Expression returnExpr;
1849 Clause tmp;
1850 createNewScope();
1851}
1852{
1853 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001854 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001855
1856 {
1857 flworg.setClauseList(clauseList);
1858 flworg.setReturnExpr(returnExpr);
1859 removeCurrentScope();
1860 return flworg;
1861 }
1862}
1863
1864Clause Clause()throws ParseException :
1865{
1866 Clause clause;
1867}
1868{
1869 (
1870 clause = ForClause()
1871 | clause = LetClause()
1872 | clause = WhereClause()
1873 | clause = OrderbyClause()
1874 | clause = GroupClause()
1875 | clause = LimitClause()
1876 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001877 )
1878 {
1879 return clause;
1880 }
1881}
1882
1883Clause ForClause()throws ParseException :
1884{
1885 ForClause fc = new ForClause();
1886 VariableExpr varExp;
1887 VariableExpr varPos = null;
1888 Expression inExp;
1889 extendCurrentScope();
1890}
1891{
Till Westmann96c1f172013-08-01 02:05:48 -07001892 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001893 {
1894 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001895 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001896 fc.setInExpr(inExp);
1897 if (varPos != null) {
1898 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001899 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001900 }
1901 return fc;
1902 }
1903}
1904
1905Clause LetClause() throws ParseException:
1906{
1907 LetClause lc = new LetClause();
1908 VariableExpr varExp;
1909 Expression beExp;
1910 extendCurrentScope();
1911}
1912{
Till Westmann96c1f172013-08-01 02:05:48 -07001913 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001914 {
1915 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001916 lc.setVarExpr(varExp);
1917 lc.setBeExpr(beExp);
1918 return lc;
1919 }
1920}
1921
1922Clause WhereClause()throws ParseException :
1923{
1924 WhereClause wc = new WhereClause();
1925 Expression whereExpr;
1926}
1927{
salsubaieedf89fbc2013-12-21 19:51:42 -08001928 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001929 {
1930 wc.setWhereExpr(whereExpr);
1931 return wc;
1932 }
1933}
1934
1935Clause OrderbyClause()throws ParseException :
1936{
1937 OrderbyClause oc = new OrderbyClause();
1938 Expression orderbyExpr;
1939 List<Expression> orderbyList = new ArrayList<Expression>();
1940 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1941 int numOfOrderby = 0;
1942}
1943{
1944 (
Till Westmann96c1f172013-08-01 02:05:48 -07001945 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001946 {
1947 String hint = getHint(token);
1948 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1949 String splits[] = hint.split(" +");
1950 int numFrames = Integer.parseInt(splits[1]);
1951 int numTuples = Integer.parseInt(splits[2]);
1952 oc.setNumFrames(numFrames);
1953 oc.setNumTuples(numTuples);
1954 }
1955 }
Till Westmann96c1f172013-08-01 02:05:48 -07001956 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001957 {
1958 orderbyList.add(orderbyExpr);
1959 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1960 }
Till Westmann96c1f172013-08-01 02:05:48 -07001961 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1962 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001963 {
1964 modifierList.add(modif);
1965 }
1966
Till Westmann96c1f172013-08-01 02:05:48 -07001967 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001968 {
1969 orderbyList.add(orderbyExpr);
1970 modif = OrderbyClause.OrderModifier.ASC;
1971 }
Till Westmann96c1f172013-08-01 02:05:48 -07001972 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1973 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001974 {
1975 modifierList.add(modif);
1976 }
1977 )*
1978)
1979 {
1980 oc.setModifierList(modifierList);
1981 oc.setOrderbyList(orderbyList);
1982 return oc;
1983 }
1984}
1985Clause GroupClause()throws ParseException :
1986{
1987 GroupbyClause gbc = new GroupbyClause();
1988 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1989 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1990 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1991 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1992 VariableExpr var = null;
1993 VariableExpr withVar = null;
1994 Expression expr = null;
1995 VariableExpr decorVar = null;
1996 Expression decorExpr = null;
1997}
1998{
1999 {
2000 Scope newScope = extendCurrentScopeNoPush(true);
2001 // extendCurrentScope(true);
2002 }
Till Westmann96c1f172013-08-01 02:05:48 -07002003 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002004 {
2005 String hint = getHint(token);
2006 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2007 gbc.setHashGroupByHint(true);
2008 }
2009 }
Till Westmann96c1f172013-08-01 02:05:48 -07002010 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002011 {
2012 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002013 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002014 expr = Expression()
2015 {
2016 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2017 vePairList.add(pair1);
2018 }
Till Westmann96c1f172013-08-01 02:05:48 -07002019 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002020 {
2021 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002022 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002023 expr = Expression()
2024 {
2025 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2026 vePairList.add(pair2);
2027 }
2028 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002029 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002030 {
2031 newScope.addNewVarSymbolToScope(decorVar.getVar());
2032 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2033 decorPairList.add(pair3);
2034 }
Till Westmann96c1f172013-08-01 02:05:48 -07002035 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002036 {
2037 newScope.addNewVarSymbolToScope(decorVar.getVar());
2038 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2039 decorPairList.add(pair4);
2040 }
2041 )*
2042 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002043 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002044 {
2045 if(withVar.getIsNewVar()==true)
2046 throw new ParseException("can't find variable " + withVar.getVar());
2047 withVarList.add(withVar);
2048 newScope.addNewVarSymbolToScope(withVar.getVar());
2049 }
Till Westmann96c1f172013-08-01 02:05:48 -07002050 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002051 {
2052 if(withVar.getIsNewVar()==true)
2053 throw new ParseException("can't find variable " + withVar.getVar());
2054 withVarList.add(withVar);
2055 newScope.addNewVarSymbolToScope(withVar.getVar());
2056 })*
2057 {
2058 gbc.setGbyPairList(vePairList);
2059 gbc.setDecorPairList(decorPairList);
2060 gbc.setWithVarList(withVarList);
2061 replaceCurrentScope(newScope);
2062 return gbc;
2063 }
2064}
2065
2066
2067LimitClause LimitClause() throws ParseException:
2068{
2069 LimitClause lc = new LimitClause();
2070 Expression expr;
2071 pushForbiddenScope(getCurrentScope());
2072}
2073{
Till Westmann96c1f172013-08-01 02:05:48 -07002074 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2075 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002076
2077 {
2078 popForbiddenScope();
2079 return lc;
2080 }
2081}
2082
2083DistinctClause DistinctClause() throws ParseException:
2084{
2085 List<Expression> exprs = new ArrayList<Expression>();
2086 Expression expr;
2087}
2088{
Till Westmann96c1f172013-08-01 02:05:48 -07002089 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002090 {
2091 exprs.add(expr);
2092 }
Till Westmann96c1f172013-08-01 02:05:48 -07002093 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002094 {
2095 exprs.add(expr);
2096 }
2097 )*
2098 {
2099 return new DistinctClause(exprs);
2100 }
2101}
2102
vinayakb38b7ca42012-03-05 05:44:15 +00002103QuantifiedExpression QuantifiedExpression()throws ParseException:
2104{
2105 QuantifiedExpression qc = new QuantifiedExpression();
2106 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2107 Expression satisfiesExpr;
2108 VariableExpr var;
2109 Expression inExpr;
2110 QuantifiedPair pair;
2111}
2112{
2113 {
2114 createNewScope();
2115 }
2116
Till Westmann96c1f172013-08-01 02:05:48 -07002117 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2118 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2119 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002120 {
2121 pair = new QuantifiedPair(var, inExpr);
2122 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2123 quantifiedList.add(pair);
2124 }
2125 (
Till Westmann96c1f172013-08-01 02:05:48 -07002126 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002127 {
2128 pair = new QuantifiedPair(var, inExpr);
2129 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2130 quantifiedList.add(pair);
2131 }
2132 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002133 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002134 {
2135 qc.setSatisfiesExpr(satisfiesExpr);
2136 qc.setQuantifiedList(quantifiedList);
2137 removeCurrentScope();
2138 return qc;
2139 }
2140}
2141
2142TOKEN_MGR_DECLS:
2143{
Till Westmann96c1f172013-08-01 02:05:48 -07002144 public int commentDepth = 0;
2145 public IntStack lexerStateStack = new IntStack();
2146
2147 public void pushState() {
2148 lexerStateStack.push( curLexState );
2149 }
2150
2151 public void popState() {
2152 if (lexerStateStack.size() > 0) {
2153 SwitchTo( lexerStateStack.pop() );
2154 } else {
2155 throw new RuntimeException();
2156 }
2157 }
vinayakb38b7ca42012-03-05 05:44:15 +00002158}
2159
Till Westmann96c1f172013-08-01 02:05:48 -07002160<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002161TOKEN :
2162{
Till Westmann5df7b452013-08-02 13:07:16 -07002163 <ASC : "asc">
2164 | <AT : "at">
2165 | <BY : "by">
2166 | <DATASET : "dataset">
2167 | <DECOR : "decor">
2168 | <DESC : "desc">
2169 | <DISTINCT : "distinct">
2170 | <ELSE : "else">
2171 | <EVERY : "every">
2172 | <FOR : "for">
2173 | <GROUP : "group">
2174 | <IF : "if">
2175 | <IN : "in">
2176 | <LET : "let">
2177 | <LIMIT : "limit">
2178 | <OFFSET : "offset">
2179 | <ORDER : "order">
2180 | <RETURN : "return">
2181 | <SATISFIES : "satisfies">
2182 | <SOME : "some">
2183 | <THEN : "then">
2184 | <UNION : "union">
2185 | <WHERE : "where">
2186 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002187}
2188
Till Westmann96c1f172013-08-01 02:05:48 -07002189<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002190TOKEN :
2191{
Till Westmann5df7b452013-08-02 13:07:16 -07002192 <CARET : "^">
2193 | <DIV : "/">
2194 | <IDIV : "idiv">
2195 | <MINUS : "-">
2196 | <MOD : "%">
2197 | <MUL : "*">
2198 | <PLUS : "+">
2199
2200 | <LEFTPAREN : "(">
2201 | <RIGHTPAREN : ")">
2202 | <LEFTBRACKET : "[">
2203 | <RIGHTBRACKET : "]">
2204
2205 | <COLON : ":">
2206 | <COMMA : ",">
2207 | <DOT : ".">
2208 | <QUES : "?">
2209
2210 | <LT : "<">
2211 | <GT : ">">
2212 | <LE : "<=">
2213 | <GE : ">=">
2214 | <EQ : "=">
2215 | <NE : "!=">
2216 | <SIMILAR : "~=">
2217 | <ASSIGN : ":=">
2218
2219 | <AND : "and">
2220 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222
Till Westmann96c1f172013-08-01 02:05:48 -07002223<DEFAULT,IN_DBL_BRACE>
2224TOKEN :
2225{
Till Westmann5df7b452013-08-02 13:07:16 -07002226 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002227}
2228
2229<DEFAULT>
2230TOKEN :
2231{
Till Westmann5df7b452013-08-02 13:07:16 -07002232 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002233}
2234
Till Westmann96c1f172013-08-01 02:05:48 -07002235<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002236TOKEN :
2237{
Till Westmann5df7b452013-08-02 13:07:16 -07002238 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002239}
2240
Till Westmann96c1f172013-08-01 02:05:48 -07002241<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002242TOKEN :
2243{
Till Westmann5df7b452013-08-02 13:07:16 -07002244 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002245}
2246
Till Westmann96c1f172013-08-01 02:05:48 -07002247<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002248TOKEN :
2249{
Till Westmann5df7b452013-08-02 13:07:16 -07002250 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002251}
2252
Till Westmann96c1f172013-08-01 02:05:48 -07002253<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002254TOKEN :
2255{
Till Westmann5df7b452013-08-02 13:07:16 -07002256 <NULL : "null">
2257 | <TRUE : "true">
2258 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002259}
2260
Till Westmann96c1f172013-08-01 02:05:48 -07002261<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002262TOKEN :
2263{
Till Westmann5df7b452013-08-02 13:07:16 -07002264 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002265}
2266
Till Westmann96c1f172013-08-01 02:05:48 -07002267<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002268TOKEN:
2269{
Till Westmann5df7b452013-08-02 13:07:16 -07002270 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002271 | <DIGITS> ( "." <DIGITS> )?
2272 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002273 >
2274 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002275 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2276 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002277 >
2278 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002279}
2280
Till Westmann96c1f172013-08-01 02:05:48 -07002281<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002282TOKEN :
2283{
Till Westmann5df7b452013-08-02 13:07:16 -07002284 <#LETTER : ["A" - "Z", "a" - "z"]>
2285 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002286}
2287
Till Westmann96c1f172013-08-01 02:05:48 -07002288<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002289TOKEN :
2290{
Till Westmanne0cc01c2014-03-31 10:26:10 -07002291 <STRING_LITERAL : ("\"" (<EscapeQuot> | <EscapeBslash> | ~["\"","\\"])* "\"")
2292 | ("\'"(<EscapeApos> | <EscapeBslash> | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002293 | < #EscapeQuot: "\\\"" >
2294 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002295 | < #EscapeBslash: "\\\\" >
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 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
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 +00002305TOKEN :
2306{
Till Westmann5df7b452013-08-02 13:07:16 -07002307 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002308}
2309
Till Westmann96c1f172013-08-01 02:05:48 -07002310<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002311SKIP:
2312{
2313 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002314 | "\t"
2315 | "\r"
2316 | "\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"])* "\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 Westmann5df7b452013-08-02 13:07:16 -07002328 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002329}
2330
Till Westmann96c1f172013-08-01 02:05:48 -07002331<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002332SKIP:
2333{
Till Westmann96c1f172013-08-01 02:05:48 -07002334 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002335}
2336
2337<INSIDE_COMMENT>
2338SPECIAL_TOKEN:
2339{
Till Westmann5df7b452013-08-02 13:07:16 -07002340 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002341}
2342
2343<INSIDE_COMMENT>
2344SKIP:
2345{
Till Westmann96c1f172013-08-01 02:05:48 -07002346 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002347}
2348
2349<INSIDE_COMMENT>
2350SKIP:
2351{
Till Westmann96c1f172013-08-01 02:05:48 -07002352 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002353 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002354}