blob: 1044d2e6f1d960609af0ce5ec0954daf2dda592c [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;
1474 int index;
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 }
1482 | index = Index()
1483 {
1484 fa = (fa == null ? new IndexAccessor(expr, index)
1485 : new IndexAccessor(fa, index));
1486 }
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
1504int Index() throws ParseException:
1505{
1506 Expression expr = null;
1507 int idx = -2;
1508}
1509{
Till Westmann96c1f172013-08-01 02:05:48 -07001510 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001511 {
1512 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1513 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001514 Literal lit = ((LiteralExpr)expr).getValue();
1515 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1516 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001517 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001518 }
vinayakb38b7ca42012-03-05 05:44:15 +00001519 else {
1520 throw new ParseException("Index should be an INTEGER");
1521 }
1522 }
1523
1524 }
1525
Till Westmann96c1f172013-08-01 02:05:48 -07001526 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001527 {
1528 idx = IndexAccessor.ANY;
1529 // ANY
1530 }
1531
1532 )
1533
Till Westmann96c1f172013-08-01 02:05:48 -07001534 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001535 {
1536 return idx;
1537 }
1538}
1539
1540
1541Expression PrimaryExpr()throws ParseException:
1542{
1543 Expression expr = null;
1544}
1545{
Till Westmann68d99652013-05-09 11:15:21 -07001546 ( LOOKAHEAD(2)
1547 expr = FunctionCallExpr()
1548 | expr = Literal()
1549 | expr = DatasetAccessExpression()
1550 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001551 {
1552 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001553 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001554 }
Till Westmann68d99652013-05-09 11:15:21 -07001555 | expr = ListConstructor()
1556 | expr = RecordConstructor()
1557 | expr = ParenthesizedExpression()
1558 )
1559 {
1560 return expr;
1561 }
vinayakb38b7ca42012-03-05 05:44:15 +00001562}
1563
1564Expression Literal() throws ParseException:
1565{
vinayakb38b7ca42012-03-05 05:44:15 +00001566 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001567 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001568}
1569{
Till Westmann7d535322013-05-09 00:40:02 -07001570 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001571 {
Till Westmann7d535322013-05-09 00:40:02 -07001572 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001573 }
1574 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001575 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001576 try {
1577 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1578 } catch(NumberFormatException ex) {
1579 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1580 }
1581 }
1582 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001583 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001584 lit.setValue(new FloatLiteral(new Float(token.image)));
1585 }
1586 | <DOUBLE_LITERAL>
1587 {
1588 lit.setValue(new DoubleLiteral(new Double(token.image)));
1589 }
1590 | <NULL>
1591 {
1592 lit.setValue(NullLiteral.INSTANCE);
1593 }
1594 | <TRUE>
1595 {
1596 lit.setValue(TrueLiteral.INSTANCE);
1597 }
1598 | <FALSE>
1599 {
1600 lit.setValue(FalseLiteral.INSTANCE);
1601 }
1602 )
vinayakb38b7ca42012-03-05 05:44:15 +00001603 {
1604 return lit;
1605 }
1606}
1607
1608
1609VariableExpr VariableRef() throws ParseException:
1610{
1611 VariableExpr varExp = new VariableExpr();
1612 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001613}
1614{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001615 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001616 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001617 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001618 Identifier ident = lookupSymbol(varName);
1619 if (isInForbiddenScopes(varName)) {
1620 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.");
1621 }
1622 if(ident != null) { // exist such ident
1623 varExp.setIsNewVar(false);
1624 varExp.setVar((VarIdentifier)ident);
1625 } else {
1626 varExp.setVar(var);
1627 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001628 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001629 return varExp;
1630 }
1631}
1632
1633
1634VariableExpr Variable() throws ParseException:
1635{
1636 VariableExpr varExp = new VariableExpr();
1637 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001638}
1639{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001640 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001641 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001642 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001643 if(ident != null) { // exist such ident
1644 varExp.setIsNewVar(false);
1645 }
1646 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001647 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001648 return varExp;
1649 }
1650}
1651
1652Expression ListConstructor() throws ParseException:
1653{
1654 Expression expr = null;
1655}
1656{
1657 (
1658 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1659 )
1660
1661 {
1662 return expr;
1663 }
1664}
1665
1666
1667ListConstructor OrderedListConstructor() throws ParseException:
1668{
1669 ListConstructor expr = new ListConstructor();
1670 Expression tmp = null;
1671 List<Expression> exprList = new ArrayList<Expression>();
1672 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1673}
1674{
1675
Till Westmann96c1f172013-08-01 02:05:48 -07001676 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001677 ( tmp = Expression()
1678 {
1679 exprList.add(tmp);
1680 }
1681
Till Westmann96c1f172013-08-01 02:05:48 -07001682 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001683 )?
1684
Till Westmann96c1f172013-08-01 02:05:48 -07001685 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001686
1687 {
1688 expr.setExprList(exprList);
1689 return expr;
1690 }
1691}
1692
1693ListConstructor UnorderedListConstructor() throws ParseException:
1694{
1695 ListConstructor expr = new ListConstructor();
1696 Expression tmp = null;
1697 List<Expression> exprList = new ArrayList<Expression>();
1698 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1699}
1700{
1701
Till Westmann96c1f172013-08-01 02:05:48 -07001702 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001703 {
1704 exprList.add(tmp);
1705 }
Till Westmann96c1f172013-08-01 02:05:48 -07001706 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001707 {
1708 expr.setExprList(exprList);
1709 return expr;
1710 }
1711}
1712
1713RecordConstructor RecordConstructor() throws ParseException:
1714{
1715 RecordConstructor expr = new RecordConstructor();
1716 FieldBinding tmp = null;
1717 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1718}
1719{
Till Westmann96c1f172013-08-01 02:05:48 -07001720 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001721 {
1722 fbList.add(tmp);
1723 }
Till Westmann96c1f172013-08-01 02:05:48 -07001724 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001725 {
1726 expr.setFbList(fbList);
1727 return expr;
1728 }
1729}
1730
1731FieldBinding FieldBinding() throws ParseException:
1732{
1733 FieldBinding fb = new FieldBinding();
1734 Expression left, right;
1735}
1736{
Till Westmann96c1f172013-08-01 02:05:48 -07001737 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001738 {
1739 fb.setLeftExpr(left);
1740 fb.setRightExpr(right);
1741 return fb;
1742 }
1743}
1744
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001745
vinayakb38b7ca42012-03-05 05:44:15 +00001746Expression FunctionCallExpr() throws ParseException:
1747{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001748 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001749 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001750 Expression tmp;
1751 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001752 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001753 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001754}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001755{
ramangrover299f76a5e2013-06-18 10:25:17 -07001756 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001757 {
Till Westmann31c21f92013-05-08 09:21:53 -07001758 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001759 }
Till Westmann31c21f92013-05-08 09:21:53 -07001760 <LEFTPAREN> (tmp = Expression()
1761 {
1762 argList.add(tmp);
1763 arity ++;
1764 }
Till Westmann96c1f172013-08-01 02:05:48 -07001765 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001766 {
1767 argList.add(tmp);
1768 arity++;
1769 }
1770 )*)? <RIGHTPAREN>
1771 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001772 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001773 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001774 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001775 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001776 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001777 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001778 }
1779 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08001780 if (hint != null) {
1781 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1782 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1783 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1784 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
1785 }
Till Westmann31c21f92013-05-08 09:21:53 -07001786 }
1787 return callExpr;
1788 }
vinayakb38b7ca42012-03-05 05:44:15 +00001789}
1790
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001791
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001792Expression DatasetAccessExpression() throws ParseException:
1793{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001794 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001795 String arg1 = null;
1796 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001797 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001798}
1799{
Till Westmann14a20a72013-05-09 00:06:24 -07001800 <DATASET>
1801 {
Till Westmann14a20a72013-05-09 00:06:24 -07001802 funcName = token.image;
1803 }
Till Westmann96c1f172013-08-01 02:05:48 -07001804 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001805 {
1806 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001807 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001808 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001809 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001810 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001811 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001812 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001813 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1814 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1815 if (signature == null) {
1816 signature = new FunctionSignature(dataverse, funcName, 1);
1817 }
1818 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001819 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001820 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001821 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001822}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001823
vinayakb38b7ca42012-03-05 05:44:15 +00001824Expression ParenthesizedExpression() throws ParseException:
1825{
1826 Expression expr;
1827}
1828{
1829 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1830 {
1831 return expr;
1832 }
1833}
1834
1835Expression IfThenElse() throws ParseException:
1836{
1837 Expression condExpr;
1838 Expression thenExpr;
1839 Expression elseExpr;
1840 IfExpr ifExpr = new IfExpr();
1841}
1842{
Till Westmann96c1f172013-08-01 02:05:48 -07001843 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001844
1845 {
1846 ifExpr.setCondExpr(condExpr);
1847 ifExpr.setThenExpr(thenExpr);
1848 ifExpr.setElseExpr(elseExpr);
1849 return ifExpr;
1850 }
1851}
1852
1853Expression FLWOGR() throws ParseException:
1854{
1855 FLWOGRExpression flworg = new FLWOGRExpression();
1856 List<Clause> clauseList = new ArrayList<Clause>();
1857 Expression returnExpr;
1858 Clause tmp;
1859 createNewScope();
1860}
1861{
1862 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001863 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001864
1865 {
1866 flworg.setClauseList(clauseList);
1867 flworg.setReturnExpr(returnExpr);
1868 removeCurrentScope();
1869 return flworg;
1870 }
1871}
1872
1873Clause Clause()throws ParseException :
1874{
1875 Clause clause;
1876}
1877{
1878 (
1879 clause = ForClause()
1880 | clause = LetClause()
1881 | clause = WhereClause()
1882 | clause = OrderbyClause()
1883 | clause = GroupClause()
1884 | clause = LimitClause()
1885 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001886 )
1887 {
1888 return clause;
1889 }
1890}
1891
1892Clause ForClause()throws ParseException :
1893{
1894 ForClause fc = new ForClause();
1895 VariableExpr varExp;
1896 VariableExpr varPos = null;
1897 Expression inExp;
1898 extendCurrentScope();
1899}
1900{
Till Westmann96c1f172013-08-01 02:05:48 -07001901 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001902 {
1903 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001904 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001905 fc.setInExpr(inExp);
1906 if (varPos != null) {
1907 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001908 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001909 }
1910 return fc;
1911 }
1912}
1913
1914Clause LetClause() throws ParseException:
1915{
1916 LetClause lc = new LetClause();
1917 VariableExpr varExp;
1918 Expression beExp;
1919 extendCurrentScope();
1920}
1921{
Till Westmann96c1f172013-08-01 02:05:48 -07001922 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001923 {
1924 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001925 lc.setVarExpr(varExp);
1926 lc.setBeExpr(beExp);
1927 return lc;
1928 }
1929}
1930
1931Clause WhereClause()throws ParseException :
1932{
1933 WhereClause wc = new WhereClause();
1934 Expression whereExpr;
1935}
1936{
salsubaieedf89fbc2013-12-21 19:51:42 -08001937 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001938 {
1939 wc.setWhereExpr(whereExpr);
1940 return wc;
1941 }
1942}
1943
1944Clause OrderbyClause()throws ParseException :
1945{
1946 OrderbyClause oc = new OrderbyClause();
1947 Expression orderbyExpr;
1948 List<Expression> orderbyList = new ArrayList<Expression>();
1949 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1950 int numOfOrderby = 0;
1951}
1952{
1953 (
Till Westmann96c1f172013-08-01 02:05:48 -07001954 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001955 {
1956 String hint = getHint(token);
1957 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1958 String splits[] = hint.split(" +");
1959 int numFrames = Integer.parseInt(splits[1]);
1960 int numTuples = Integer.parseInt(splits[2]);
1961 oc.setNumFrames(numFrames);
1962 oc.setNumTuples(numTuples);
1963 }
1964 }
Till Westmann96c1f172013-08-01 02:05:48 -07001965 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001966 {
1967 orderbyList.add(orderbyExpr);
1968 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1969 }
Till Westmann96c1f172013-08-01 02:05:48 -07001970 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1971 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001972 {
1973 modifierList.add(modif);
1974 }
1975
Till Westmann96c1f172013-08-01 02:05:48 -07001976 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001977 {
1978 orderbyList.add(orderbyExpr);
1979 modif = OrderbyClause.OrderModifier.ASC;
1980 }
Till Westmann96c1f172013-08-01 02:05:48 -07001981 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1982 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001983 {
1984 modifierList.add(modif);
1985 }
1986 )*
1987)
1988 {
1989 oc.setModifierList(modifierList);
1990 oc.setOrderbyList(orderbyList);
1991 return oc;
1992 }
1993}
1994Clause GroupClause()throws ParseException :
1995{
1996 GroupbyClause gbc = new GroupbyClause();
1997 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1998 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1999 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
2000 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2001 VariableExpr var = null;
2002 VariableExpr withVar = null;
2003 Expression expr = null;
2004 VariableExpr decorVar = null;
2005 Expression decorExpr = null;
2006}
2007{
2008 {
2009 Scope newScope = extendCurrentScopeNoPush(true);
2010 // extendCurrentScope(true);
2011 }
Till Westmann96c1f172013-08-01 02:05:48 -07002012 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002013 {
2014 String hint = getHint(token);
2015 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2016 gbc.setHashGroupByHint(true);
2017 }
2018 }
Till Westmann96c1f172013-08-01 02:05:48 -07002019 <BY> (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 pair1 = new GbyVariableExpressionPair(var, expr);
2026 vePairList.add(pair1);
2027 }
Till Westmann96c1f172013-08-01 02:05:48 -07002028 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002029 {
2030 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002031 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00002032 expr = Expression()
2033 {
2034 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2035 vePairList.add(pair2);
2036 }
2037 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002038 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002039 {
2040 newScope.addNewVarSymbolToScope(decorVar.getVar());
2041 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2042 decorPairList.add(pair3);
2043 }
Till Westmann96c1f172013-08-01 02:05:48 -07002044 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002045 {
2046 newScope.addNewVarSymbolToScope(decorVar.getVar());
2047 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2048 decorPairList.add(pair4);
2049 }
2050 )*
2051 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002052 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002053 {
2054 if(withVar.getIsNewVar()==true)
2055 throw new ParseException("can't find variable " + withVar.getVar());
2056 withVarList.add(withVar);
2057 newScope.addNewVarSymbolToScope(withVar.getVar());
2058 }
Till Westmann96c1f172013-08-01 02:05:48 -07002059 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002060 {
2061 if(withVar.getIsNewVar()==true)
2062 throw new ParseException("can't find variable " + withVar.getVar());
2063 withVarList.add(withVar);
2064 newScope.addNewVarSymbolToScope(withVar.getVar());
2065 })*
2066 {
2067 gbc.setGbyPairList(vePairList);
2068 gbc.setDecorPairList(decorPairList);
2069 gbc.setWithVarList(withVarList);
2070 replaceCurrentScope(newScope);
2071 return gbc;
2072 }
2073}
2074
2075
2076LimitClause LimitClause() throws ParseException:
2077{
2078 LimitClause lc = new LimitClause();
2079 Expression expr;
2080 pushForbiddenScope(getCurrentScope());
2081}
2082{
Till Westmann96c1f172013-08-01 02:05:48 -07002083 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2084 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002085
2086 {
2087 popForbiddenScope();
2088 return lc;
2089 }
2090}
2091
2092DistinctClause DistinctClause() throws ParseException:
2093{
2094 List<Expression> exprs = new ArrayList<Expression>();
2095 Expression expr;
2096}
2097{
Till Westmann96c1f172013-08-01 02:05:48 -07002098 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002099 {
2100 exprs.add(expr);
2101 }
Till Westmann96c1f172013-08-01 02:05:48 -07002102 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002103 {
2104 exprs.add(expr);
2105 }
2106 )*
2107 {
2108 return new DistinctClause(exprs);
2109 }
2110}
2111
vinayakb38b7ca42012-03-05 05:44:15 +00002112QuantifiedExpression QuantifiedExpression()throws ParseException:
2113{
2114 QuantifiedExpression qc = new QuantifiedExpression();
2115 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2116 Expression satisfiesExpr;
2117 VariableExpr var;
2118 Expression inExpr;
2119 QuantifiedPair pair;
2120}
2121{
2122 {
2123 createNewScope();
2124 }
2125
Till Westmann96c1f172013-08-01 02:05:48 -07002126 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2127 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2128 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002129 {
2130 pair = new QuantifiedPair(var, inExpr);
2131 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2132 quantifiedList.add(pair);
2133 }
2134 (
Till Westmann96c1f172013-08-01 02:05:48 -07002135 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002136 {
2137 pair = new QuantifiedPair(var, inExpr);
2138 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2139 quantifiedList.add(pair);
2140 }
2141 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002142 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002143 {
2144 qc.setSatisfiesExpr(satisfiesExpr);
2145 qc.setQuantifiedList(quantifiedList);
2146 removeCurrentScope();
2147 return qc;
2148 }
2149}
2150
2151TOKEN_MGR_DECLS:
2152{
Till Westmann96c1f172013-08-01 02:05:48 -07002153 public int commentDepth = 0;
2154 public IntStack lexerStateStack = new IntStack();
2155
2156 public void pushState() {
2157 lexerStateStack.push( curLexState );
2158 }
2159
2160 public void popState() {
2161 if (lexerStateStack.size() > 0) {
2162 SwitchTo( lexerStateStack.pop() );
2163 } else {
2164 throw new RuntimeException();
2165 }
2166 }
vinayakb38b7ca42012-03-05 05:44:15 +00002167}
2168
Till Westmann96c1f172013-08-01 02:05:48 -07002169<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002170TOKEN :
2171{
Till Westmann5df7b452013-08-02 13:07:16 -07002172 <ASC : "asc">
2173 | <AT : "at">
2174 | <BY : "by">
2175 | <DATASET : "dataset">
2176 | <DECOR : "decor">
2177 | <DESC : "desc">
2178 | <DISTINCT : "distinct">
2179 | <ELSE : "else">
2180 | <EVERY : "every">
2181 | <FOR : "for">
2182 | <GROUP : "group">
2183 | <IF : "if">
2184 | <IN : "in">
2185 | <LET : "let">
2186 | <LIMIT : "limit">
2187 | <OFFSET : "offset">
2188 | <ORDER : "order">
2189 | <RETURN : "return">
2190 | <SATISFIES : "satisfies">
2191 | <SOME : "some">
2192 | <THEN : "then">
2193 | <UNION : "union">
2194 | <WHERE : "where">
2195 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002196}
2197
Till Westmann96c1f172013-08-01 02:05:48 -07002198<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002199TOKEN :
2200{
Till Westmann5df7b452013-08-02 13:07:16 -07002201 <CARET : "^">
2202 | <DIV : "/">
2203 | <IDIV : "idiv">
2204 | <MINUS : "-">
2205 | <MOD : "%">
2206 | <MUL : "*">
2207 | <PLUS : "+">
2208
2209 | <LEFTPAREN : "(">
2210 | <RIGHTPAREN : ")">
2211 | <LEFTBRACKET : "[">
2212 | <RIGHTBRACKET : "]">
2213
2214 | <COLON : ":">
2215 | <COMMA : ",">
2216 | <DOT : ".">
2217 | <QUES : "?">
2218
2219 | <LT : "<">
2220 | <GT : ">">
2221 | <LE : "<=">
2222 | <GE : ">=">
2223 | <EQ : "=">
2224 | <NE : "!=">
2225 | <SIMILAR : "~=">
2226 | <ASSIGN : ":=">
2227
2228 | <AND : "and">
2229 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002230}
2231
Till Westmann96c1f172013-08-01 02:05:48 -07002232<DEFAULT,IN_DBL_BRACE>
2233TOKEN :
2234{
Till Westmann5df7b452013-08-02 13:07:16 -07002235 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002236}
2237
2238<DEFAULT>
2239TOKEN :
2240{
Till Westmann5df7b452013-08-02 13:07:16 -07002241 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002242}
2243
Till Westmann96c1f172013-08-01 02:05:48 -07002244<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002245TOKEN :
2246{
Till Westmann5df7b452013-08-02 13:07:16 -07002247 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002248}
2249
Till Westmann96c1f172013-08-01 02:05:48 -07002250<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002251TOKEN :
2252{
Till Westmann5df7b452013-08-02 13:07:16 -07002253 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002254}
2255
Till Westmann96c1f172013-08-01 02:05:48 -07002256<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002257TOKEN :
2258{
Till Westmann5df7b452013-08-02 13:07:16 -07002259 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002260}
2261
Till Westmann96c1f172013-08-01 02:05:48 -07002262<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002263TOKEN :
2264{
Till Westmann5df7b452013-08-02 13:07:16 -07002265 <NULL : "null">
2266 | <TRUE : "true">
2267 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002268}
2269
Till Westmann96c1f172013-08-01 02:05:48 -07002270<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002271TOKEN :
2272{
Till Westmann5df7b452013-08-02 13:07:16 -07002273 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002274}
2275
Till Westmann96c1f172013-08-01 02:05:48 -07002276<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002277TOKEN:
2278{
Till Westmann5df7b452013-08-02 13:07:16 -07002279 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002280 | <DIGITS> ( "." <DIGITS> )?
2281 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002282 >
2283 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002284 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2285 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002286 >
2287 | <DIGITS : (<DIGIT>)+ >
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 <#LETTER : ["A" - "Z", "a" - "z"]>
2294 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002295}
2296
Till Westmann96c1f172013-08-01 02:05:48 -07002297<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002298TOKEN :
2299{
Till Westmann5df7b452013-08-02 13:07:16 -07002300 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2301 | < #EscapeQuot: "\\\"" >
2302 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002303}
2304
Till Westmann96c1f172013-08-01 02:05:48 -07002305<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002306TOKEN :
2307{
Till Westmann5df7b452013-08-02 13:07:16 -07002308 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
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 +00002312TOKEN :
2313{
Till Westmann5df7b452013-08-02 13:07:16 -07002314 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
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{
2320 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002321 | "\t"
2322 | "\r"
2323 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002324}
2325
Till Westmann96c1f172013-08-01 02:05:48 -07002326<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002327SKIP:
2328{
Till Westmann5df7b452013-08-02 13:07:16 -07002329 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002330}
2331
Till Westmann96c1f172013-08-01 02:05:48 -07002332<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002333SKIP:
2334{
Till Westmann5df7b452013-08-02 13:07:16 -07002335 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002336}
2337
Till Westmann96c1f172013-08-01 02:05:48 -07002338<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002339SKIP:
2340{
Till Westmann96c1f172013-08-01 02:05:48 -07002341 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002342}
2343
2344<INSIDE_COMMENT>
2345SPECIAL_TOKEN:
2346{
Till Westmann5df7b452013-08-02 13:07:16 -07002347 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002348}
2349
2350<INSIDE_COMMENT>
2351SKIP:
2352{
Till Westmann96c1f172013-08-01 02:05:48 -07002353 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002354}
2355
2356<INSIDE_COMMENT>
2357SKIP:
2358{
Till Westmann96c1f172013-08-01 02:05:48 -07002359 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002360 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002361}