blob: ef69a5f2f0b9e4c48e4ead95dc31a6117ebf9f3c [file] [log] [blame]
Till Westmann5b431ca2015-10-01 19:16:11 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
vinayakb38b7ca42012-03-05 05:44:15 +000020options {
21
Taewoo Kima12d8cd2015-03-04 13:47:08 -080022
vinayakb38b7ca42012-03-05 05:44:15 +000023 STATIC = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -080024
vinayakb38b7ca42012-03-05 05:44:15 +000025}
26
27
28PARSER_BEGIN(AQLParser)
29
Ian Maxonf18bba22015-08-21 12:35:14 -070030package org.apache.asterix.aql.parser;
vinayakb38b7ca42012-03-05 05:44:15 +000031
Eldon Carmand2d78ad2015-05-07 16:23:41 -070032// For AQLParserTokenManager
Till Westmann96c1f172013-08-01 02:05:48 -070033import org.apache.xerces.util.IntStack;
34
Eldon Carmand2d78ad2015-05-07 16:23:41 -070035import java.io.BufferedReader;
36import java.io.File;
37import java.io.FileInputStream;
38import java.io.FileNotFoundException;
39import java.io.IOException;
40import java.io.InputStreamReader;
41import java.io.Reader;
42import java.io.StringReader;
43import java.util.ArrayList;
44import java.util.HashMap;
45import java.util.LinkedHashMap;
46import java.util.List;
47import java.util.Map;
48
Ian Maxonf18bba22015-08-21 12:35:14 -070049import org.apache.asterix.aql.base.Clause;
50import org.apache.asterix.aql.base.Expression;
51import org.apache.asterix.aql.base.Literal;
52import org.apache.asterix.aql.base.Statement;
53import org.apache.asterix.aql.context.RootScopeFactory;
54import org.apache.asterix.aql.context.Scope;
55import org.apache.asterix.aql.expression.AbstractAccessor;
56import org.apache.asterix.aql.expression.CallExpr;
57import org.apache.asterix.aql.expression.CompactStatement;
58import org.apache.asterix.aql.expression.ConnectFeedStatement;
59import org.apache.asterix.aql.expression.CreateFeedPolicyStatement;
60import org.apache.asterix.aql.expression.CreatePrimaryFeedStatement;
61import org.apache.asterix.aql.expression.CreateSecondaryFeedStatement;
62import org.apache.asterix.aql.expression.CreateDataverseStatement;
63import org.apache.asterix.aql.expression.CreateFeedStatement;
64import org.apache.asterix.aql.expression.CreateFunctionStatement;
65import org.apache.asterix.aql.expression.CreateIndexStatement;
66import org.apache.asterix.aql.expression.DatasetDecl;
67import org.apache.asterix.aql.expression.DataverseDecl;
68import org.apache.asterix.aql.expression.DataverseDropStatement;
69import org.apache.asterix.aql.expression.DeleteStatement;
70import org.apache.asterix.aql.expression.DisconnectFeedStatement;
71import org.apache.asterix.aql.expression.DistinctClause;
72import org.apache.asterix.aql.expression.DropStatement;
73import org.apache.asterix.aql.expression.ExternalDetailsDecl;
74import org.apache.asterix.aql.expression.FLWOGRExpression;
75import org.apache.asterix.aql.expression.FeedDropStatement;
76import org.apache.asterix.aql.expression.FieldAccessor;
77import org.apache.asterix.aql.expression.FieldBinding;
78import org.apache.asterix.aql.expression.ForClause;
79import org.apache.asterix.aql.expression.FunctionDecl;
80import org.apache.asterix.aql.expression.FunctionDropStatement;
81import org.apache.asterix.aql.expression.GbyVariableExpressionPair;
82import org.apache.asterix.aql.expression.GroupbyClause;
83import org.apache.asterix.aql.expression.Identifier;
84import org.apache.asterix.aql.expression.IfExpr;
85import org.apache.asterix.aql.expression.IndexAccessor;
86import org.apache.asterix.aql.expression.IndexDropStatement;
87import org.apache.asterix.aql.expression.InsertStatement;
88import org.apache.asterix.aql.expression.InternalDetailsDecl;
89import org.apache.asterix.aql.expression.LetClause;
90import org.apache.asterix.aql.expression.LimitClause;
91import org.apache.asterix.aql.expression.ListConstructor;
92import org.apache.asterix.aql.expression.LiteralExpr;
93import org.apache.asterix.aql.expression.LoadStatement;
94import org.apache.asterix.aql.expression.NodeGroupDropStatement;
95import org.apache.asterix.aql.expression.NodegroupDecl;
96import org.apache.asterix.aql.expression.OperatorExpr;
97import org.apache.asterix.aql.expression.OrderbyClause;
98import org.apache.asterix.aql.expression.OrderedListTypeDefinition;
99import org.apache.asterix.aql.expression.QuantifiedExpression;
100import org.apache.asterix.aql.expression.QuantifiedPair;
101import org.apache.asterix.aql.expression.Query;
102import org.apache.asterix.aql.expression.RecordConstructor;
103import org.apache.asterix.aql.expression.RecordTypeDefinition;
104import org.apache.asterix.aql.expression.RefreshExternalDatasetStatement;
105import org.apache.asterix.aql.expression.RunStatement;
106import org.apache.asterix.aql.expression.SetStatement;
107import org.apache.asterix.aql.expression.TypeDecl;
108import org.apache.asterix.aql.expression.TypeDropStatement;
109import org.apache.asterix.aql.expression.TypeExpression;
110import org.apache.asterix.aql.expression.TypeReferenceExpression;
111import org.apache.asterix.aql.expression.UnaryExpr;
112import org.apache.asterix.aql.expression.UnaryExpr.Sign;
113import org.apache.asterix.aql.expression.UnionExpr;
114import org.apache.asterix.aql.expression.UnorderedListTypeDefinition;
115import org.apache.asterix.aql.expression.UpdateClause;
116import org.apache.asterix.aql.expression.UpdateStatement;
117import org.apache.asterix.aql.expression.VarIdentifier;
118import org.apache.asterix.aql.expression.VariableExpr;
119import org.apache.asterix.aql.expression.WhereClause;
120import org.apache.asterix.aql.expression.WriteStatement;
121import org.apache.asterix.aql.literal.DoubleLiteral;
122import org.apache.asterix.aql.literal.FalseLiteral;
123import org.apache.asterix.aql.literal.FloatLiteral;
124import org.apache.asterix.aql.literal.LongIntegerLiteral;
125import org.apache.asterix.aql.literal.NullLiteral;
126import org.apache.asterix.aql.literal.StringLiteral;
127import org.apache.asterix.aql.literal.TrueLiteral;
128import org.apache.asterix.aql.util.RangeMapBuilder;
129import org.apache.asterix.common.annotations.AutoDataGen;
130import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
131import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
132import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
133import org.apache.asterix.common.annotations.FieldIntervalDataGen;
134import org.apache.asterix.common.annotations.FieldValFileDataGen;
135import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
136import org.apache.asterix.common.annotations.IRecordFieldDataGen;
137import org.apache.asterix.common.annotations.InsertRandIntDataGen;
138import org.apache.asterix.common.annotations.ListDataGen;
139import org.apache.asterix.common.annotations.ListValFileDataGen;
140import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
141import org.apache.asterix.common.annotations.TypeDataGen;
142import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
143import org.apache.asterix.common.config.DatasetConfig.DatasetType;
144import org.apache.asterix.common.config.DatasetConfig.IndexType;
145import org.apache.asterix.common.exceptions.AsterixException;
146import org.apache.asterix.common.functions.FunctionSignature;
147import org.apache.asterix.metadata.bootstrap.MetadataConstants;
148import org.apache.hyracks.algebricks.common.utils.Pair;
149import org.apache.hyracks.algebricks.common.utils.Triple;
150import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
151import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
152import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
153import org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000154
155
vinayakb38b7ca42012-03-05 05:44:15 +0000156
157
158public class AQLParser extends ScopeChecker {
159
vinayakb38b7ca42012-03-05 05:44:15 +0000160 // optimizer hints
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700161 private static final String AUTO_HINT = "auto";
vinayakb38b7ca42012-03-05 05:44:15 +0000162 private static final String BROADCAST_JOIN_HINT = "bcast";
vinayakb38b7ca42012-03-05 05:44:15 +0000163 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
vinayakb38b7ca42012-03-05 05:44:15 +0000164 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
165 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700166 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
167 private static final String HASH_GROUP_BY_HINT = "hash";
168 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
169 private static final String INMEMORY_HINT = "inmem";
170 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
171 private static final String INTERVAL_HINT = "interval";
172 private static final String LIST_HINT = "list";
173 private static final String LIST_VAL_FILE_HINT = "list-val-file";
174 private static final String RANGE_HINT = "range";
175 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
176 private static final String VAL_FILE_HINT = "val-files";
177 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800178
179 private static final String GEN_FIELDS_HINT = "gen-fields";
180
vinayakb38b7ca42012-03-05 05:44:15 +0000181 // data generator hints
182 private static final String DGEN_HINT = "dgen";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800183
Till Westmann31c21f92013-05-08 09:21:53 -0700184 private static class IndexParams {
185 public IndexType type;
186 public int gramLength;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800187
Till Westmann31c21f92013-05-08 09:21:53 -0700188 public IndexParams(IndexType type, int gramLength) {
189 this.type = type;
190 this.gramLength = gramLength;
191 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800192 };
193
ramangrover299f76a5e2013-06-18 10:25:17 -0700194 private static class FunctionName {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800195 public String dataverse = null;
196 public String library = null;
197 public String function = null;
198 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700199
vinayakb38b7ca42012-03-05 05:44:15 +0000200 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -0700201 if (t.specialToken == null) {
202 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800203 }
Till Westmann31c21f92013-05-08 09:21:53 -0700204 String s = t.specialToken.image;
205 int n = s.length();
206 if (n < 2) {
207 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800208 }
Till Westmann31c21f92013-05-08 09:21:53 -0700209 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000210 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800211
Till Westmann77cb2f42013-07-15 16:44:19 -0700212 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
213 IRecordFieldDataGen rfdg = null;
214 String splits[] = hint.split(" +");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800215 if (splits[0].equals(VAL_FILE_HINT)) {
Till Westmann77cb2f42013-07-15 16:44:19 -0700216 File[] valFiles = new File[splits.length - 1];
217 for (int k=1; k<splits.length; k++) {
218 valFiles[k-1] = new File(splits[k]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800219 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700220 rfdg = new FieldValFileDataGen(valFiles);
221 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
222 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
223 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
224 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
225 } else if (splits[0].equals(LIST_HINT)) {
226 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
227 } else if (splits[0].equals(INTERVAL_HINT)) {
228 FieldIntervalDataGen.ValueType vt;
229 if (splits[1].equals("int")) {
230 vt = FieldIntervalDataGen.ValueType.INT;
231 } else if (splits[1].equals("long")) {
232 vt = FieldIntervalDataGen.ValueType.LONG;
233 } else if (splits[1].equals("float")) {
234 vt = FieldIntervalDataGen.ValueType.FLOAT;
235 } else if (splits[1].equals("double")) {
236 vt = FieldIntervalDataGen.ValueType.DOUBLE;
237 } else {
238 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
239 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800240 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
Till Westmann77cb2f42013-07-15 16:44:19 -0700241 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
242 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
243 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
244 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
245 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
246 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
247 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
248 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
249 } else if (splits[0].equals(AUTO_HINT)) {
250 rfdg = new AutoDataGen(splits[1]);
251 }
252 return rfdg;
253 }
vinayakb38b7ca42012-03-05 05:44:15 +0000254
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000255 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700256 this(new StringReader(s));
257 super.setInput(s);
258 }
vinayakb38b7ca42012-03-05 05:44:15 +0000259
Till Westmann31c21f92013-05-08 09:21:53 -0700260 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
261 File file = new File(args[0]);
262 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
263 AQLParser parser = new AQLParser(fis);
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700264 List<Statement> st = parser.parse();
Till Westmann31c21f92013-05-08 09:21:53 -0700265 //st.accept(new AQLPrintVisitor(), 0);
266 }
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700267
268 public List<Statement> parse() throws ParseException {
269 try {
270 return Statement();
271 } catch (Error e) {
272 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
273 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
274 throw new ParseException(e.getMessage());
275 }
276 }
vinayakb38b7ca42012-03-05 05:44:15 +0000277}
278
279PARSER_END(AQLParser)
280
281
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000282List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000283{
vinayakb38b7ca42012-03-05 05:44:15 +0000284 scopeStack.push(RootScopeFactory.createRootScope(this));
285 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700286 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000287}
288{
Till Westmann31c21f92013-05-08 09:21:53 -0700289 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000290 {
Till Westmann31c21f92013-05-08 09:21:53 -0700291 decls.add(stmt);
292 }
293 )*
294 <EOF>
295 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800296 return decls;
Till Westmann31c21f92013-05-08 09:21:53 -0700297 }
298}
299
300Statement SingleStatement() throws ParseException:
301{
302 Statement stmt = null;
303}
304{
305 (
306 stmt = DataverseDeclaration()
307 | stmt = FunctionDeclaration()
308 | stmt = CreateStatement()
309 | stmt = LoadStatement()
310 | stmt = DropStatement()
311 | stmt = WriteStatement()
312 | stmt = SetStatement()
313 | stmt = InsertStatement()
314 | stmt = DeleteStatement()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800315 | stmt = UpdateStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700316 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700317 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700318 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700319 | stmt = RefreshExternalDatasetStatement()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800320 | stmt = RunStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700321 )
322 {
323 return stmt;
324 }
325}
326
327DataverseDecl DataverseDeclaration() throws ParseException:
328{
Till Westmann14a20a72013-05-09 00:06:24 -0700329 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700330}
331{
Till Westmanna4242bc2013-05-08 17:49:55 -0700332 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700333 {
Till Westmann14a20a72013-05-09 00:06:24 -0700334 defaultDataverse = dvName;
335 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700336 }
337}
338
339Statement CreateStatement() throws ParseException:
340{
341 String hint = null;
342 boolean dgen = false;
343 Statement stmt = null;
344}
345{
346 "create"
347 (
348 {
349 hint = getHint(token);
350 if (hint != null && hint.startsWith(DGEN_HINT)) {
351 dgen = true;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800352 }
Till Westmann31c21f92013-05-08 09:21:53 -0700353 }
354 stmt = TypeSpecification(hint, dgen)
355 | stmt = NodegroupSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800356 | stmt = DatasetSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700357 | stmt = IndexSpecification()
358 | stmt = DataverseSpecification()
359 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700360 | stmt = FeedSpecification()
ramangrover29ae85a1d2015-06-26 17:26:05 -0700361 | stmt = FeedPolicySpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800362 )
Till Westmann31c21f92013-05-08 09:21:53 -0700363 {
364 return stmt;
365 }
366}
367
368TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
369{
370 Pair<Identifier,Identifier> nameComponents = null;
371 boolean ifNotExists = false;
372 TypeExpression typeExpr = null;
373}
374{
ramangrover299f76a5e2013-06-18 10:25:17 -0700375 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700376 "as" typeExpr = TypeExpr()
377 {
378 long numValues = -1;
379 String filename = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800380 if (dgen) {
Till Westmann31c21f92013-05-08 09:21:53 -0700381 String splits[] = hint.split(" +");
382 if (splits.length != 3) {
383 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800384 }
Till Westmann31c21f92013-05-08 09:21:53 -0700385 filename = splits[1];
386 numValues = Long.parseLong(splits[2]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800387 }
Till Westmann31c21f92013-05-08 09:21:53 -0700388 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
389 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
390 }
391}
392
393
394NodegroupDecl NodegroupSpecification() throws ParseException:
395{
Till Westmann14a20a72013-05-09 00:06:24 -0700396 String name = null;
397 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700398 boolean ifNotExists = false;
399 List<Identifier>ncNames = null;
400}
401{
Till Westmanna4242bc2013-05-08 17:49:55 -0700402 "nodegroup" name = Identifier()
403 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700404 {
405 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700406 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700407 }
Till Westmann96c1f172013-08-01 02:05:48 -0700408 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700409 {
Till Westmann14a20a72013-05-09 00:06:24 -0700410 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700411 }
412 )*
413 {
Till Westmann14a20a72013-05-09 00:06:24 -0700414 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700415 }
416}
417
418DatasetDecl DatasetSpecification() throws ParseException:
419{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800420 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700421 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700422 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700423 String adapterName = null;
424 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700425 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700426 FunctionSignature appliedFunction = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700427 List<List<String>> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700428 String nodeGroupName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800429 Map<String,String> hints = new HashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700430 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700431 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700432 String compactionPolicy = null;
buyingyiccd67fe2015-05-19 11:53:39 -0700433 boolean temp = false;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700434 List<String> filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700435}
436{
437 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700438 "external" <DATASET> nameComponents = QualifiedName()
439 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
440 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700441 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700442 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700443 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700444 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700445 {
446 ExternalDetailsDecl edd = new ExternalDetailsDecl();
447 edd.setAdapter(adapterName);
448 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700449 dsetDecl = new DatasetDecl(nameComponents.first,
450 nameComponents.second,
451 new Identifier(typeName),
Ildar Absalyamova5895302015-08-17 23:15:41 -0700452 nodeGroupName != null? new Identifier(nodeGroupName): null,
453 compactionPolicy,
454 compactionPolicyProperties,
Till Westmann14a20a72013-05-09 00:06:24 -0700455 hints,
456 DatasetType.EXTERNAL,
457 edd,
458 ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800459 }
Till Westmann31c21f92013-05-08 09:21:53 -0700460
buyingyiccd67fe2015-05-19 11:53:39 -0700461 | ("internal" | "temporary" {
462 temp = token.image.toLowerCase().equals("temporary");
463 }
464 )?
465 <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700466 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
467 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800468 primaryKeyFields = PrimaryKey()
469 ("autogenerated" { autogenerated = true; } )?
zheilbron2467f2e2013-08-23 19:07:31 -0700470 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700471 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700472 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700473 ( "with filter on" filterField = NestedField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700474 {
Ildar Absalyamova5895302015-08-17 23:15:41 -0700475 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700476 autogenerated,
buyingyiccd67fe2015-05-19 11:53:39 -0700477 filterField,
478 temp);
Till Westmann14a20a72013-05-09 00:06:24 -0700479 dsetDecl = new DatasetDecl(nameComponents.first,
480 nameComponents.second,
481 new Identifier(typeName),
Ildar Absalyamova5895302015-08-17 23:15:41 -0700482 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
483 compactionPolicy,
484 compactionPolicyProperties,
Till Westmann14a20a72013-05-09 00:06:24 -0700485 hints,
486 DatasetType.INTERNAL,
487 idd,
488 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700489 }
490 )
491 {
492 return dsetDecl;
493 }
494}
495
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700496RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
497{
498 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
499 Pair<Identifier,Identifier> nameComponents = null;
500 String datasetName = null;
501}
502{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800503 "refresh external" <DATASET> nameComponents = QualifiedName()
504 {
505 redss.setDataverseName(nameComponents.first);
506 redss.setDatasetName(nameComponents.second);
507 return redss;
508 }
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700509}
510
Markus Holzemer52c568e2014-12-18 10:51:49 -0800511RunStatement RunStatement() throws ParseException:
512{
513 String system = null;
514 String tmp;
515 ArrayList<String> parameters = new ArrayList<String>();
516 Pair<Identifier,Identifier> nameComponentsFrom = null;
517 Pair<Identifier,Identifier> nameComponentsTo = null;
518}
519{
520 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
521 {
522 parameters.add(tmp);
523 }
524 )*<RIGHTPAREN>
525 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800526 "to" <DATASET> nameComponentsTo = QualifiedName()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800527 {
528 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
529 }
530}
531
Till Westmann31c21f92013-05-08 09:21:53 -0700532CreateIndexStatement IndexSpecification() throws ParseException:
533{
534 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700535 String indexName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700536 boolean ifNotExists = false;
537 Pair<Identifier,Identifier> nameComponents = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700538 Pair<List<String>, TypeExpression> fieldPair = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700539 IndexParams indexType = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700540 boolean enforced = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700541}
542{
Till Westmanna4242bc2013-05-08 17:49:55 -0700543 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700544 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800545 "on" nameComponents = QualifiedName()
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700546 <LEFTPAREN> ( fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700547 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700548 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700549 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700550 ) (<COMMA> fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700551 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700552 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700553 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700554 )* <RIGHTPAREN> ( "type" indexType = IndexType() )? ( "enforced" { enforced = true; } )?
Till Westmann31c21f92013-05-08 09:21:53 -0700555 {
Till Westmann14a20a72013-05-09 00:06:24 -0700556 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700557 cis.setIfNotExists(ifNotExists);
558 cis.setDataverseName(nameComponents.first);
559 cis.setDatasetName(nameComponents.second);
560 if (indexType != null) {
561 cis.setIndexType(indexType.type);
562 cis.setGramLength(indexType.gramLength);
563 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700564 cis.setEnforced(enforced);
Till Westmann31c21f92013-05-08 09:21:53 -0700565 return cis;
566 }
567}
568
salsubaiee0b423fa2013-09-19 19:16:48 -0700569String CompactionPolicy() throws ParseException :
570{
571 String compactionPolicy = null;
572}
573{
574 compactionPolicy = Identifier()
575 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800576 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700577 }
578}
579
salsubaieea5af4e02014-07-08 15:20:02 -0700580String FilterField() throws ParseException :
581{
582 String filterField = null;
583}
584{
585 filterField = Identifier()
586 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800587 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700588 }
589}
590
Till Westmann31c21f92013-05-08 09:21:53 -0700591IndexParams IndexType() throws ParseException:
592{
593 IndexType type = null;
594 int gramLength = 0;
595}
596{
597 ("btree"
598 {
599 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800600 }
Till Westmann31c21f92013-05-08 09:21:53 -0700601 | "rtree"
602 {
603 type = IndexType.RTREE;
604 }
605 | "keyword"
606 {
JIMAHNb75446d2013-06-03 08:35:27 -0700607 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700608 }
609 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
610 {
JIMAHNb75446d2013-06-03 08:35:27 -0700611 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700612 gramLength = Integer.valueOf(token.image);
613 }
614 <RIGHTPAREN>)
615 {
616 return new IndexParams(type, gramLength);
617 }
618}
619
620CreateDataverseStatement DataverseSpecification() throws ParseException :
621{
Till Westmann14a20a72013-05-09 00:06:24 -0700622 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700623 boolean ifNotExists = false;
624 String format = null;
625}
626{
Till Westmanna4242bc2013-05-08 17:49:55 -0700627 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700628 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700629 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700630 {
Till Westmann14a20a72013-05-09 00:06:24 -0700631 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700632 }
633}
634
635CreateFunctionStatement FunctionSpecification() throws ParseException:
636{
637 FunctionSignature signature;
638 boolean ifNotExists = false;
639 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
640 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700641 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700642 Expression functionBodyExpr;
643 Token beginPos;
644 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700645 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800646
Till Westmann31c21f92013-05-08 09:21:53 -0700647 createNewScope();
648}
649{
ramangrover299f76a5e2013-06-18 10:25:17 -0700650 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700651 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700652 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700653 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530654 {
655 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800656 }
Till Westmann96c1f172013-08-01 02:05:48 -0700657 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700658 {
659 endPos = token;
660 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700661 // TODO use fctName.library
662 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700663 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800664 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700665 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
666 }
667}
668
ramangrover29a774ef22013-07-17 09:29:18 -0700669CreateFeedStatement FeedSpecification() throws ParseException:
670{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800671 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700672 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700673 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700674 Map<String,String> properties = null;
675 FunctionSignature appliedFunction = null;
676 CreateFeedStatement cfs = null;
ramangrover29ae85a1d2015-06-26 17:26:05 -0700677 Pair<Identifier,Identifier> sourceNameComponents = null;
678
ramangrover29a774ef22013-07-17 09:29:18 -0700679}
680{
681 (
ramangrover29ae85a1d2015-06-26 17:26:05 -0700682 "secondary" "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
683 <FROM> "feed" sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())?
ramangrover29a774ef22013-07-17 09:29:18 -0700684 {
ramangrover29ae85a1d2015-06-26 17:26:05 -0700685 cfs = new CreateSecondaryFeedStatement(nameComponents,
686 sourceNameComponents, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800687 }
ramangrover29ae85a1d2015-06-26 17:26:05 -0700688 |
689 ("primary")? "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
690 "using" adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())?
691 {
692 cfs = new CreatePrimaryFeedStatement(nameComponents,
693 adapterName, properties, appliedFunction, ifNotExists);
694 }
ramangrover29a774ef22013-07-17 09:29:18 -0700695 )
696 {
697 return cfs;
698 }
699}
700
ramangrover29ae85a1d2015-06-26 17:26:05 -0700701CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
702{
703 String policyName = null;
704 String basePolicyName = null;
705 String sourcePolicyFile = null;
706 String definition = null;
707 boolean ifNotExists = false;
708 Map<String,String> properties = null;
709 CreateFeedPolicyStatement cfps = null;
710}
711{
712 (
713 "ingestion" "policy" policyName = Identifier() ifNotExists = IfNotExists()
714 <FROM>
715 ("policy" basePolicyName = Identifier() properties = Configuration() ("definition" definition = StringLiteral())?
716 {
717 cfps = new CreateFeedPolicyStatement(policyName,
718 basePolicyName, properties, definition, ifNotExists);
719 }
720 | "path" sourcePolicyFile = Identifier() ("definition" definition = StringLiteral())?
721 {
722 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
723 }
724 )
725
726 )
727 {
728 return cfps;
729 }
730}
731
ramangrover29a774ef22013-07-17 09:29:18 -0700732
733
Till Westmannd7dcb122013-05-16 13:19:09 -0700734List<VarIdentifier> ParameterList() throws ParseException:
735{
736 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
737 VarIdentifier var = null;
738}
739{
Till Westmann31c21f92013-05-08 09:21:53 -0700740 <LEFTPAREN> (<VARIABLE>
741 {
742 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700743 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700744 paramList.add(var);
745 getCurrentScope().addNewVarSymbolToScope(var);
746 }
Till Westmann96c1f172013-08-01 02:05:48 -0700747 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700748 {
749 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700750 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700751 paramList.add(var);
752 getCurrentScope().addNewVarSymbolToScope(var);
753 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700754 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700755 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700756 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700757 }
758}
759
760boolean IfNotExists() throws ParseException:
761{
762}
763{
764 ( "if not exists"
765 {
766 return true;
767 }
768 )?
769 {
770 return false;
771 }
772}
773
774FunctionSignature ApplyFunction() throws ParseException:
775{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530776 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700777 FunctionSignature funcSig = null;
778}
779{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530780 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700781 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530782 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
783 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700784 }
785}
786
ramangrover29566b3a92013-05-28 09:07:10 -0700787String GetPolicy() throws ParseException:
788{
789 String policy = null;
790}
791{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800792 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700793 {
794 return policy;
795 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800796
797}
ramangrover29566b3a92013-05-28 09:07:10 -0700798
Till Westmann31c21f92013-05-08 09:21:53 -0700799FunctionSignature FunctionSignature() throws ParseException:
800{
ramangrover299f76a5e2013-06-18 10:25:17 -0700801 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700802 int arity = 0;
803}
804{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800805 fctName = FunctionName() "@" <INTEGER_LITERAL>
806 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700807 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700808 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
809 throw new ParseException(" invalid arity:" + arity);
810 }
811
ramangrover299f76a5e2013-06-18 10:25:17 -0700812 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800813 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700814 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700815 }
816}
817
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700818List<List<String>> PrimaryKey() throws ParseException:
Till Westmann31c21f92013-05-08 09:21:53 -0700819{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700820 List<String> tmp = null;
821 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Till Westmann31c21f92013-05-08 09:21:53 -0700822}
823{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700824 "primary" "key" tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700825 {
Till Westmann14a20a72013-05-09 00:06:24 -0700826 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700827 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700828 ( <COMMA> tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700829 {
Till Westmann14a20a72013-05-09 00:06:24 -0700830 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700831 }
832 )*
833 {
834 return primaryKeyFields;
835 }
836}
837
838Statement DropStatement() throws ParseException:
839{
Till Westmann14a20a72013-05-09 00:06:24 -0700840 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700841 Pair<Identifier,Identifier> pairId = null;
842 Triple<Identifier,Identifier,Identifier> tripleId = null;
843 FunctionSignature funcSig = null;
844 boolean ifExists = false;
845 Statement stmt = null;
846}
847{
848 "drop"
849 (
850 <DATASET> pairId = QualifiedName() ifExists = IfExists()
851 {
852 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
853 }
854 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
855 {
856 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
857 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700858 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700859 {
Till Westmann14a20a72013-05-09 00:06:24 -0700860 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700861 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700862 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700863 {
864 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
865 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700866 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700867 {
Till Westmann14a20a72013-05-09 00:06:24 -0700868 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700869 }
870 | "function" funcSig = FunctionSignature() ifExists = IfExists()
871 {
872 stmt = new FunctionDropStatement(funcSig, ifExists);
873 }
ramangrover29a774ef22013-07-17 09:29:18 -0700874 | "feed" pairId = QualifiedName() ifExists = IfExists()
875 {
876 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800877 }
Till Westmann31c21f92013-05-08 09:21:53 -0700878 )
879 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800880 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700881 }
882}
883
884boolean IfExists() throws ParseException :
885{
886}
887{
Till Westmann96c1f172013-08-01 02:05:48 -0700888 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700889 {
890 return true;
891 }
892 )?
893 {
894 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000895 }
896}
897
898InsertStatement InsertStatement() throws ParseException:
899{
Till Westmann31c21f92013-05-08 09:21:53 -0700900 Pair<Identifier,Identifier> nameComponents = null;
901 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000902}
903{
Till Westmann31c21f92013-05-08 09:21:53 -0700904 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
905 {
906 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
907 }
vinayakb38b7ca42012-03-05 05:44:15 +0000908}
909
910DeleteStatement DeleteStatement() throws ParseException:
911{
Till Westmann31c21f92013-05-08 09:21:53 -0700912 VariableExpr var = null;
913 Expression condition = null;
914 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300915 // This is related to the new metadata lock management
916 setDataverses(new ArrayList<String>());
917 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800918
vinayakb38b7ca42012-03-05 05:44:15 +0000919}
920{
Till Westmann31c21f92013-05-08 09:21:53 -0700921 "delete" var = Variable()
922 {
923 getCurrentScope().addNewVarSymbolToScope(var.getVar());
924 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800925 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800926 (<WHERE> condition = Expression())?
927 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300928 // First we get the dataverses and datasets that we want to lock
929 List<String> dataverses = getDataverses();
930 List<String> datasets = getDatasets();
931 // we remove the pointer to the dataverses and datasets
932 setDataverses(null);
933 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800934 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
935 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700936 }
vinayakb38b7ca42012-03-05 05:44:15 +0000937}
938
939UpdateStatement UpdateStatement() throws ParseException:
940{
Till Westmann31c21f92013-05-08 09:21:53 -0700941 VariableExpr vars;
942 Expression target;
943 Expression condition;
944 UpdateClause uc;
945 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000946}
947{
Till Westmann96c1f172013-08-01 02:05:48 -0700948 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800949 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700950 <LEFTPAREN> (uc = UpdateClause()
951 {
952 ucs.add(uc);
953 }
Till Westmann96c1f172013-08-01 02:05:48 -0700954 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700955 {
956 ucs.add(uc);
957 }
958 )*) <RIGHTPAREN>
959 {
960 return new UpdateStatement(vars, target, condition, ucs);
961 }
vinayakb38b7ca42012-03-05 05:44:15 +0000962}
963
vinayakb38b7ca42012-03-05 05:44:15 +0000964UpdateClause UpdateClause() throws ParseException:
965{
Till Westmann31c21f92013-05-08 09:21:53 -0700966 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800967 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700968 InsertStatement is = null;
969 DeleteStatement ds = null;
970 UpdateStatement us = null;
971 Expression condition = null;
972 UpdateClause ifbranch = null;
973 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000974}
975{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800976 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700977 | is = InsertStatement()
978 | ds = DeleteStatement()
979 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700980 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
981 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800982 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700983 {
984 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
985 }
vinayakb38b7ca42012-03-05 05:44:15 +0000986}
987
vinayakb38b7ca42012-03-05 05:44:15 +0000988Statement SetStatement() throws ParseException:
989{
990 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700991 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000992}
993{
Till Westmann7d535322013-05-09 00:40:02 -0700994 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700995 {
Till Westmann31c21f92013-05-08 09:21:53 -0700996 return new SetStatement(pn, pv);
997 }
vinayakb38b7ca42012-03-05 05:44:15 +0000998}
999
1000Statement WriteStatement() throws ParseException:
1001{
Till Westmann14a20a72013-05-09 00:06:24 -07001002 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001003 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001004 Query query;
1005 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001006 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001007}
1008{
Till Westmann96c1f172013-08-01 02:05:48 -07001009 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -07001010 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001011 {
1012 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +00001013 }
1014}
1015
zheilbron28e026f2013-11-20 10:15:15 -08001016LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001017{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001018 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001019 Identifier datasetName = null;
1020 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +00001021 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001022 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001023 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001024}
1025{
Till Westmann31c21f92013-05-08 09:21:53 -07001026 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +00001027 {
Till Westmann31c21f92013-05-08 09:21:53 -07001028 dataverseName = nameComponents.first;
1029 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001030 }
Till Westmann31c21f92013-05-08 09:21:53 -07001031 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001032 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +00001033 {
Till Westmann31c21f92013-05-08 09:21:53 -07001034 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001035 }
1036 )?
Till Westmann31c21f92013-05-08 09:21:53 -07001037 {
zheilbron28e026f2013-11-20 10:15:15 -08001038 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001039 }
vinayakb38b7ca42012-03-05 05:44:15 +00001040}
1041
vinayakb38b7ca42012-03-05 05:44:15 +00001042
Till Westmann31c21f92013-05-08 09:21:53 -07001043String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001044{
ramangrover29669d8f62013-02-11 06:03:32 +00001045 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001046}
1047{
Till Westmann68d99652013-05-09 11:15:21 -07001048 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +00001049 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001050 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001051 }
vinayakb38b7ca42012-03-05 05:44:15 +00001052}
1053
salsubaiee0b423fa2013-09-19 19:16:48 -07001054Statement CompactStatement() throws ParseException:
1055{
1056 Pair<Identifier,Identifier> nameComponents = null;
1057 Statement stmt = null;
1058}
1059{
1060 "compact" <DATASET> nameComponents = QualifiedName()
1061 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001062 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -07001063 }
1064 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001065 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -07001066 }
1067}
1068
Till Westmann31c21f92013-05-08 09:21:53 -07001069Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001070{
ramangrover29a774ef22013-07-17 09:29:18 -07001071 Pair<Identifier,Identifier> feedNameComponents = null;
1072 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001073
Till Westmann31c21f92013-05-08 09:21:53 -07001074 Map<String,String> configuration = null;
1075 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -07001076 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001077}
1078{
Till Westmann31c21f92013-05-08 09:21:53 -07001079 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001080 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -07001081 {
ramangrover29a774ef22013-07-17 09:29:18 -07001082 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -07001083 }
buyingyi2fd7fa62014-11-24 19:31:55 -08001084 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -07001085 {
ramangrover29a774ef22013-07-17 09:29:18 -07001086 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -07001087 }
1088 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001089 {
Till Westmann31c21f92013-05-08 09:21:53 -07001090 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001091 }
1092}
1093
Till Westmann31c21f92013-05-08 09:21:53 -07001094Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001095{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001096 Map<String,String> configuration = new LinkedHashMap<String,String>();
1097 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001098}
1099{
Till Westmann31c21f92013-05-08 09:21:53 -07001100 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001101 {
Till Westmann31c21f92013-05-08 09:21:53 -07001102 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001103 }
Till Westmann96c1f172013-08-01 02:05:48 -07001104 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001105 {
Till Westmann31c21f92013-05-08 09:21:53 -07001106 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001107 }
Till Westmann31c21f92013-05-08 09:21:53 -07001108 )* )? <RIGHTPAREN>
1109 {
1110 return configuration;
1111 }
1112}
1113
1114Pair<String, String> KeyValuePair() throws ParseException:
1115{
1116 String key;
1117 String value;
1118}
1119{
Till Westmann96c1f172013-08-01 02:05:48 -07001120 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -07001121 {
1122 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001123 }
Till Westmann31c21f92013-05-08 09:21:53 -07001124}
1125
1126Map<String,String> Properties() throws ParseException:
1127{
1128 Map<String,String> properties = new HashMap<String,String>();
1129 Pair<String, String> property;
1130}
1131{
1132 ( <LEFTPAREN> property = Property()
1133 {
1134 properties.put(property.first, property.second);
1135 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001136 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -07001137 {
1138 properties.put(property.first, property.second);
1139 }
1140 )* <RIGHTPAREN> )?
1141 {
1142 return properties;
1143 }
1144}
1145
1146Pair<String, String> Property() throws ParseException:
1147{
1148 String key;
1149 String value;
1150}
1151{
Till Westmann96c1f172013-08-01 02:05:48 -07001152 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001153 {
1154 try {
1155 value = "" + Long.valueOf(token.image);
1156 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001157 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001158 }
1159 }
1160 )
1161 {
1162 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001163 }
vinayakb38b7ca42012-03-05 05:44:15 +00001164}
1165
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001166TypeExpression IndexedTypeExpr() throws ParseException:
1167{
1168 TypeExpression typeExpr = null;
1169}
1170{
1171 (
1172 typeExpr = TypeReference()
1173 | typeExpr = OrderedListTypeDef()
1174 | typeExpr = UnorderedListTypeDef()
1175 )
1176 {
1177 return typeExpr;
1178 }
1179}
1180
vinayakb38b7ca42012-03-05 05:44:15 +00001181TypeExpression TypeExpr() throws ParseException:
1182{
1183 TypeExpression typeExpr = null;
1184}
1185{
1186 (
1187 typeExpr = RecordTypeDef()
1188 | typeExpr = TypeReference()
1189 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001190 | typeExpr = UnorderedListTypeDef()
1191 )
vinayakb38b7ca42012-03-05 05:44:15 +00001192 {
1193 return typeExpr;
1194 }
1195}
1196
1197RecordTypeDefinition RecordTypeDef() throws ParseException:
1198{
1199 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001200 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001201}
1202{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001203 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001204 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001205 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001206 {
1207 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001208 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001209 String splits[] = hint.split(" +");
1210 if (splits[0].equals(GEN_FIELDS_HINT)) {
1211 if (splits.length != 5) {
1212 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1213 }
1214 if (!splits[1].equals("int")) {
1215 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001216 }
1217 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001218 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001219 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001220 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001221 }
1222
vinayakb38b7ca42012-03-05 05:44:15 +00001223 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001224 (
1225 RecordField(recType)
1226 ( <COMMA> RecordField(recType) )*
1227 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001228 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001229 {
1230 if (recordKind == null) {
1231 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1232 }
1233 recType.setRecordKind(recordKind);
1234 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001235 }
vinayakb38b7ca42012-03-05 05:44:15 +00001236}
1237
1238void RecordField(RecordTypeDefinition recType) throws ParseException:
1239{
Till Westmann77cb2f42013-07-15 16:44:19 -07001240 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001241 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001242 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001243}
1244{
Till Westmann77cb2f42013-07-15 16:44:19 -07001245 fieldName = Identifier()
1246 {
1247 String hint = getHint(token);
1248 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1249 }
Till Westmann96c1f172013-08-01 02:05:48 -07001250 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001251 {
1252 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001253 }
vinayakb38b7ca42012-03-05 05:44:15 +00001254}
1255
1256TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001257{
Till Westmann14a20a72013-05-09 00:06:24 -07001258 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001259}
1260{
1261 id = Identifier()
1262 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001263 if (id.equalsIgnoreCase("int")) {
1264 id = "int64";
1265 }
1266
Till Westmann14a20a72013-05-09 00:06:24 -07001267 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001268 }
vinayakb38b7ca42012-03-05 05:44:15 +00001269}
1270
1271OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001272{
vinayakb38b7ca42012-03-05 05:44:15 +00001273 TypeExpression type = null;
1274}
1275{
Till Westmann96c1f172013-08-01 02:05:48 -07001276 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001277 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001278 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001279 {
1280 return new OrderedListTypeDefinition(type);
1281 }
1282}
1283
1284
1285UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001286{
vinayakb38b7ca42012-03-05 05:44:15 +00001287 TypeExpression type = null;
1288}
1289{
Till Westmann96c1f172013-08-01 02:05:48 -07001290 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001291 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001292 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001293 {
1294 return new UnorderedListTypeDefinition(type);
1295 }
1296}
1297
ramangrover299f76a5e2013-06-18 10:25:17 -07001298FunctionName FunctionName() throws ParseException:
1299{
1300 String first = null;
1301 String second = null;
1302 String third = null;
1303 boolean secondAfterDot = false;
1304}
1305{
zheilbron555dc9d2013-08-14 19:58:00 -07001306 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001307 {
1308 secondAfterDot = true;
1309 }
1310 ("#" third = Identifier())? | "#" second = Identifier() )?
1311 {
1312 FunctionName result = new FunctionName();
1313 if (second == null) {
1314 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001315 result.library = null;
1316 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001317 } else if (third == null) {
1318 if (secondAfterDot) {
1319 result.dataverse = first;
1320 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001321 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001322 } else {
1323 result.dataverse = defaultDataverse;
1324 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001325 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001326 }
1327 } else {
1328 result.dataverse = first;
1329 result.library = second;
1330 result.function = third;
1331 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001332
1333 if (result.function.equalsIgnoreCase("int")) {
1334 result.function = "int64";
1335 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001336 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001337 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001338}
Till Westmann31c21f92013-05-08 09:21:53 -07001339
ramangrover299f76a5e2013-06-18 10:25:17 -07001340
1341Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001342{
Till Westmann31c21f92013-05-08 09:21:53 -07001343 Pair<Identifier,Identifier> name = null;
1344}
1345{
1346 name = QualifiedName()
1347 {
1348 if (name.first == null) {
1349 name.first = new Identifier(defaultDataverse);
1350 }
1351 return name;
1352 }
1353}
1354
Till Westmann14a20a72013-05-09 00:06:24 -07001355String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001356{
Till Westmann68d99652013-05-09 11:15:21 -07001357 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001358}
1359{
1360 <IDENTIFIER>
1361 {
Till Westmann14a20a72013-05-09 00:06:24 -07001362 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001363 }
Till Westmann68d99652013-05-09 11:15:21 -07001364 | lit = StringLiteral()
1365 {
1366 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001367 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001368}
1369
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001370Pair<List<String>, TypeExpression> OpenField() throws ParseException:
1371{
1372 TypeExpression fieldType = null;
1373 List<String> fieldList = null;
1374}
1375{
1376 fieldList = NestedField()
1377 ( <COLON> fieldType = IndexedTypeExpr() )?
1378 {
1379 return new Pair<List<String>, TypeExpression>(fieldList, fieldType);
1380 }
1381}
1382
1383List<String> NestedField() throws ParseException:
1384{
1385 List<String> exprList = new ArrayList<String>();
1386 String lit = null;
1387}
1388{
1389 lit = Identifier()
1390 {
1391 exprList.add(lit);
1392 }
1393 (<DOT>
1394 lit = Identifier()
1395 {
1396 exprList.add(lit);
1397 }
1398 )*
1399 {
1400 return exprList;
1401 }
1402}
1403
1404
1405
Till Westmann7d535322013-05-09 00:40:02 -07001406String StringLiteral() throws ParseException:
1407{
1408}
1409{
1410 <STRING_LITERAL>
1411 {
1412 return removeQuotesAndEscapes(token.image);
1413 }
1414}
1415
Till Westmann31c21f92013-05-08 09:21:53 -07001416Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1417{
Till Westmann14a20a72013-05-09 00:06:24 -07001418 String first = null;
1419 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001420}
1421{
Till Westmann96c1f172013-08-01 02:05:48 -07001422 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001423 {
Till Westmann14a20a72013-05-09 00:06:24 -07001424 Identifier id1 = null;
1425 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001426 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001427 id2 = new Identifier(first);
1428 } else
1429 {
1430 id1 = new Identifier(first);
1431 id2 = new Identifier(second);
1432 }
1433 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001434 }
1435}
1436
Till Westmann31c21f92013-05-08 09:21:53 -07001437Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001438{
Till Westmann14a20a72013-05-09 00:06:24 -07001439 String first = null;
1440 String second = null;
1441 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001442}
1443{
Till Westmann96c1f172013-08-01 02:05:48 -07001444 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001445 {
Till Westmann14a20a72013-05-09 00:06:24 -07001446 Identifier id1 = null;
1447 Identifier id2 = null;
1448 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001449 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001450 id2 = new Identifier(first);
1451 id3 = new Identifier(second);
1452 } else {
1453 id1 = new Identifier(first);
1454 id2 = new Identifier(second);
1455 id3 = new Identifier(third);
1456 }
1457 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001458 }
1459}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001460
vinayakb38b7ca42012-03-05 05:44:15 +00001461FunctionDecl FunctionDeclaration() throws ParseException:
1462{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001463 FunctionDecl funcDecl;
1464 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001465 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001466 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1467 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001468 createNewScope();
1469}
1470{
Till Westmannd7dcb122013-05-16 13:19:09 -07001471 "declare" "function" functionName = Identifier()
1472 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001473 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001474 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001475 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001476 getCurrentScope().addFunctionDescriptor(signature, false);
1477 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001478 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001479 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001480 }
1481}
1482
vinayakb38b7ca42012-03-05 05:44:15 +00001483
Till Westmann31c21f92013-05-08 09:21:53 -07001484Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001485{
1486 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001487 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1488 setDataverses(query.getDataverses());
1489 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001490 Expression expr;
1491}
1492{
Till Westmann31c21f92013-05-08 09:21:53 -07001493 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001494 {
1495 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001496 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001497 // we remove the pointers to the locked entities before we return the query object
1498 setDataverses(null);
1499 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001500 return query;
1501 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001502
vinayakb38b7ca42012-03-05 05:44:15 +00001503}
1504
1505
1506
1507Expression Expression():
1508{
1509 Expression expr = null;
1510 Expression exprP = null;
1511}
1512{
1513(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001514
vinayakb38b7ca42012-03-05 05:44:15 +00001515//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1516 expr = OperatorExpr()
1517 | expr = IfThenElse()
1518 | expr = FLWOGR()
1519 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001520
vinayakb38b7ca42012-03-05 05:44:15 +00001521
1522)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001523 {
1524 return (exprP==null) ? expr : exprP;
1525 }
vinayakb38b7ca42012-03-05 05:44:15 +00001526}
1527
1528
1529
1530Expression OperatorExpr()throws ParseException:
1531{
1532 OperatorExpr op = null;
1533 Expression operand = null;
1534}
1535{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001536 operand = AndExpr()
1537 (
1538
1539 <OR>
1540 {
1541 if (op == null) {
1542 op = new OperatorExpr();
1543 op.addOperand(operand);
1544 op.setCurrentop(true);
1545 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001546 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001547 }
vinayakb38b7ca42012-03-05 05:44:15 +00001548
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001549 operand = AndExpr()
1550 {
1551 op.addOperand(operand);
1552 }
vinayakb38b7ca42012-03-05 05:44:15 +00001553
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001554 )*
1555
1556 {
1557 return op==null? operand: op;
1558 }
vinayakb38b7ca42012-03-05 05:44:15 +00001559}
1560
1561Expression AndExpr()throws ParseException:
1562{
1563 OperatorExpr op = null;
1564 Expression operand = null;
1565}
1566{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001567 operand = RelExpr()
1568 (
1569
1570 <AND>
1571 {
1572 if (op == null) {
1573 op = new OperatorExpr();
1574 op.addOperand(operand);
1575 op.setCurrentop(true);
1576 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001577 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001578 }
vinayakb38b7ca42012-03-05 05:44:15 +00001579
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001580 operand = RelExpr()
1581 {
1582 op.addOperand(operand);
1583 }
vinayakb38b7ca42012-03-05 05:44:15 +00001584
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001585 )*
1586
1587 {
1588 return op==null? operand: op;
1589 }
vinayakb38b7ca42012-03-05 05:44:15 +00001590}
1591
1592
1593
1594Expression RelExpr()throws ParseException:
1595{
1596 OperatorExpr op = null;
1597 Expression operand = null;
1598 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001599 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001600}
1601{
1602 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001603 {
1604 if (operand instanceof VariableExpr) {
1605 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001606 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001607 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001608 }
1609 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001610 }
vinayakb38b7ca42012-03-05 05:44:15 +00001611
1612 (
Till Westmann96c1f172013-08-01 02:05:48 -07001613 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001614 {
1615 String mhint = getHint(token);
1616 if (mhint != null) {
1617 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001618 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1619 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1620 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1621 }
alexander.behm07617fd2012-07-25 10:13:50 +00001622 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001623 if (op == null) {
1624 op = new OperatorExpr();
1625 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001626 op.setCurrentop(true);
1627 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001628 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001629 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001630 }
1631
1632 operand = AddExpr()
1633 {
1634 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001635 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001636 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001637 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1638 broadcast = true;
1639 }
alexander.behm07617fd2012-07-25 10:13:50 +00001640 }
vinayakb38b7ca42012-03-05 05:44:15 +00001641 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001642 }
vinayakb38b7ca42012-03-05 05:44:15 +00001643 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001644
1645 {
1646 if (annotation != null) {
1647 op.addHint(annotation);
1648 }
1649 return op==null? operand: op;
1650 }
vinayakb38b7ca42012-03-05 05:44:15 +00001651}
1652
1653Expression AddExpr()throws ParseException:
1654{
1655 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001656 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001657}
1658{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001659 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001660
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001661 ( (<PLUS> | <MINUS>)
1662 {
1663 if (op == null) {
1664 op = new OperatorExpr();
1665 op.addOperand(operand);
1666 op.setCurrentop(true);
1667 }
1668 ((OperatorExpr)op).addOperator(token.image);
1669 }
vinayakb38b7ca42012-03-05 05:44:15 +00001670
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001671 operand = MultExpr()
1672 {
1673 op.addOperand(operand);
1674 }
1675 )*
1676
1677 {
1678 return op==null? operand: op;
1679 }
vinayakb38b7ca42012-03-05 05:44:15 +00001680}
1681
1682Expression MultExpr()throws ParseException:
1683{
1684 OperatorExpr op = null;
1685 Expression operand = null;
1686}
1687{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001688 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001689
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001690 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1691 {
1692 if (op == null) {
1693 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001694 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001695 op.setCurrentop(true);
1696 }
1697 op.addOperator(token.image);
1698 }
1699 operand = UnionExpr()
1700 {
1701 op.addOperand(operand);
1702 }
1703 )*
1704
1705 {
1706 return op==null?operand:op;
1707 }
vinayakb38b7ca42012-03-05 05:44:15 +00001708}
1709
1710Expression UnionExpr() throws ParseException:
1711{
1712 UnionExpr union = null;
1713 Expression operand1 = null;
1714 Expression operand2 = null;
1715}
1716{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001717 operand1 = UnaryExpr()
1718 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001719 (operand2 = UnaryExpr()) {
1720 if (union == null) {
1721 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001722 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001723 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001724 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001725 } )*
1726 {
1727 return (union == null)? operand1: union;
1728 }
1729}
1730
1731Expression UnaryExpr() throws ParseException:
1732{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001733 Expression uexpr = null;
1734 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001735}
1736{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001737 ( (<PLUS> | <MINUS>)
1738 {
1739 uexpr = new UnaryExpr();
1740 if("+".equals(token.image))
1741 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1742 else if("-".equals(token.image))
1743 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1744 else
1745 throw new ParseException();
1746 }
1747 )?
1748
1749 expr = ValueExpr()
1750 {
1751 if(uexpr!=null){
1752 ((UnaryExpr)uexpr).setExpr(expr);
1753 return uexpr;
1754 }
1755 else{
1756 return expr;
1757 }
1758 }
vinayakb38b7ca42012-03-05 05:44:15 +00001759}
1760
Till Westmann04478e72013-05-13 23:01:34 -07001761Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001762{
1763 Expression expr = null;
1764 Identifier ident = null;
1765 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001766 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001767}
1768{
Till Westmann04478e72013-05-13 23:01:34 -07001769 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001770 {
1771 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001772 : new FieldAccessor(fa, ident));
1773 }
icetindila611ac72014-05-16 10:10:11 -07001774 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001775 {
icetindila611ac72014-05-16 10:10:11 -07001776 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1777 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001778 }
1779 )*
1780 {
1781 return fa == null ? expr : fa;
1782 }
vinayakb38b7ca42012-03-05 05:44:15 +00001783}
1784
1785Identifier Field() throws ParseException:
1786{
Till Westmann14a20a72013-05-09 00:06:24 -07001787 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001788}
1789{
Till Westmann96c1f172013-08-01 02:05:48 -07001790 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001791 {
Till Westmann14a20a72013-05-09 00:06:24 -07001792 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001793 }
vinayakb38b7ca42012-03-05 05:44:15 +00001794}
1795
icetindila611ac72014-05-16 10:10:11 -07001796Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001797{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001798 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001799}
1800{
Till Westmann96c1f172013-08-01 02:05:48 -07001801 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001802 {
1803 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1804 {
1805 Literal lit = ((LiteralExpr)expr).getValue();
1806 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1807 lit.getLiteralType() != Literal.Type.LONG) {
1808 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001809 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001810 }
1811 }
vinayakb38b7ca42012-03-05 05:44:15 +00001812
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001813 | <QUES> // ANY
1814
1815 )
vinayakb38b7ca42012-03-05 05:44:15 +00001816
Till Westmann96c1f172013-08-01 02:05:48 -07001817 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001818 {
1819 return expr;
1820 }
vinayakb38b7ca42012-03-05 05:44:15 +00001821}
1822
1823
1824Expression PrimaryExpr()throws ParseException:
1825{
1826 Expression expr = null;
1827}
1828{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001829 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001830 expr = FunctionCallExpr()
1831 | expr = Literal()
1832 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001833 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001834 {
1835 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001836 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001837 }
Till Westmann68d99652013-05-09 11:15:21 -07001838 | expr = ListConstructor()
1839 | expr = RecordConstructor()
1840 | expr = ParenthesizedExpression()
1841 )
1842 {
1843 return expr;
1844 }
vinayakb38b7ca42012-03-05 05:44:15 +00001845}
1846
1847Expression Literal() throws ParseException:
1848{
vinayakb38b7ca42012-03-05 05:44:15 +00001849 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001850 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001851}
1852{
Till Westmann7d535322013-05-09 00:40:02 -07001853 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001854 {
Till Westmann7d535322013-05-09 00:40:02 -07001855 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001856 }
1857 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001858 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001859 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001860 }
1861 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001862 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001863 lit.setValue(new FloatLiteral(new Float(token.image)));
1864 }
1865 | <DOUBLE_LITERAL>
1866 {
1867 lit.setValue(new DoubleLiteral(new Double(token.image)));
1868 }
1869 | <NULL>
1870 {
1871 lit.setValue(NullLiteral.INSTANCE);
1872 }
1873 | <TRUE>
1874 {
1875 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001876 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001877 | <FALSE>
1878 {
1879 lit.setValue(FalseLiteral.INSTANCE);
1880 }
1881 )
vinayakb38b7ca42012-03-05 05:44:15 +00001882 {
1883 return lit;
1884 }
1885}
1886
1887
1888VariableExpr VariableRef() throws ParseException:
1889{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001890 VariableExpr varExp = new VariableExpr();
1891 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001892}
1893{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001894 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001895 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001896 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001897 Identifier ident = lookupSymbol(varName);
1898 if (isInForbiddenScopes(varName)) {
1899 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.");
1900 }
1901 if(ident != null) { // exist such ident
1902 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001903 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001904 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001905 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001906 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001907 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001908 return varExp;
1909 }
1910}
1911
1912
1913VariableExpr Variable() throws ParseException:
1914{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001915 VariableExpr varExp = new VariableExpr();
1916 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001917}
1918{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001919 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001920 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001921 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001922 if(ident != null) { // exist such ident
1923 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001924 }
1925 varExp.setVar(var);
1926 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001927 return varExp;
1928 }
1929}
1930
1931Expression ListConstructor() throws ParseException:
1932{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001933 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001934}
1935{
1936 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001937 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001938 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001939
vinayakb38b7ca42012-03-05 05:44:15 +00001940 {
1941 return expr;
1942 }
1943}
1944
1945
1946ListConstructor OrderedListConstructor() throws ParseException:
1947{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001948 ListConstructor expr = new ListConstructor();
Till Westmann812f69c2015-10-21 10:14:14 -07001949 List<Expression> exprList = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001950 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001951}
1952{
Till Westmann812f69c2015-10-21 10:14:14 -07001953 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001954 {
1955 expr.setExprList(exprList);
1956 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001957 }
vinayakb38b7ca42012-03-05 05:44:15 +00001958}
1959
1960ListConstructor UnorderedListConstructor() throws ParseException:
1961{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001962 ListConstructor expr = new ListConstructor();
Till Westmann812f69c2015-10-21 10:14:14 -07001963 List<Expression> exprList = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001964 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001965}
1966{
Till Westmann812f69c2015-10-21 10:14:14 -07001967 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001968 {
1969 expr.setExprList(exprList);
1970 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001971 }
vinayakb38b7ca42012-03-05 05:44:15 +00001972}
1973
Till Westmann812f69c2015-10-21 10:14:14 -07001974List<Expression> ExpressionList() throws ParseException:
1975{
1976 Expression expr = null;
1977 List<Expression> list = null;
1978 List<Expression> exprList = new ArrayList<Expression>();
1979}
1980{
1981 ( LOOKAHEAD(2)
1982 expr = Expression() { exprList.add(expr); }
1983 (<COMMA> list = ExpressionList() { exprList.addAll(list); })?
1984 )?
1985 (Comma())?
1986 {
1987 return exprList;
1988 }
1989}
1990
1991void Comma():
1992{}
1993{
1994 <COMMA>
1995}
1996
vinayakb38b7ca42012-03-05 05:44:15 +00001997RecordConstructor RecordConstructor() throws ParseException:
1998{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001999 RecordConstructor expr = new RecordConstructor();
2000 FieldBinding tmp = null;
2001 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00002002}
2003{
Till Westmann96c1f172013-08-01 02:05:48 -07002004 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00002005 {
2006 fbList.add(tmp);
2007 }
Till Westmann96c1f172013-08-01 02:05:48 -07002008 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002009 {
2010 expr.setFbList(fbList);
2011 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002012 }
vinayakb38b7ca42012-03-05 05:44:15 +00002013}
2014
2015FieldBinding FieldBinding() throws ParseException:
2016{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002017 FieldBinding fb = new FieldBinding();
2018 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00002019}
2020{
Till Westmann96c1f172013-08-01 02:05:48 -07002021 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002022 {
2023 fb.setLeftExpr(left);
2024 fb.setRightExpr(right);
2025 return fb;
2026 }
2027}
2028
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002029
vinayakb38b7ca42012-03-05 05:44:15 +00002030Expression FunctionCallExpr() throws ParseException:
2031{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002032 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002033 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002034 Expression tmp;
2035 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07002036 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07002037 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002038}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002039{
ramangrover299f76a5e2013-06-18 10:25:17 -07002040 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00002041 {
Till Westmann31c21f92013-05-08 09:21:53 -07002042 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002043 }
Till Westmann31c21f92013-05-08 09:21:53 -07002044 <LEFTPAREN> (tmp = Expression()
2045 {
2046 argList.add(tmp);
2047 arity ++;
2048 }
Till Westmann96c1f172013-08-01 02:05:48 -07002049 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07002050 {
2051 argList.add(tmp);
2052 arity++;
2053 }
2054 )*)? <RIGHTPAREN>
2055 {
ramangrover299f76a5e2013-06-18 10:25:17 -07002056 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07002057 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07002058 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07002059 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002060 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07002061 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002062 }
2063 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08002064 if (hint != null) {
2065 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2066 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2067 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2068 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2069 }
Till Westmann31c21f92013-05-08 09:21:53 -07002070 }
2071 return callExpr;
2072 }
vinayakb38b7ca42012-03-05 05:44:15 +00002073}
2074
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002075
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002076Expression DatasetAccessExpression() throws ParseException:
2077{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002078 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07002079 String arg1 = null;
2080 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002081 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002082}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002083{
Till Westmann14a20a72013-05-09 00:06:24 -07002084 <DATASET>
2085 {
Till Westmann14a20a72013-05-09 00:06:24 -07002086 funcName = token.image;
2087 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002088 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07002089 {
2090 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07002091 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07002092 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07002093 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002094 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002095 addDataverse(arg1.toString());
2096 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002097 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002098 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002099 }
Till Westmann14a20a72013-05-09 00:06:24 -07002100 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002101 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07002102 {
Till Westmann1f7a2362013-05-24 08:43:40 -07002103 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2104 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2105 if (signature == null) {
2106 signature = new FunctionSignature(dataverse, funcName, 1);
2107 }
2108 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07002109 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07002110 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07002111 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002112}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002113
vinayakb38b7ca42012-03-05 05:44:15 +00002114Expression ParenthesizedExpression() throws ParseException:
2115{
2116 Expression expr;
2117}
2118{
2119 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2120 {
2121 return expr;
2122 }
2123}
2124
2125Expression IfThenElse() throws ParseException:
2126{
2127 Expression condExpr;
2128 Expression thenExpr;
2129 Expression elseExpr;
2130 IfExpr ifExpr = new IfExpr();
2131}
2132{
Till Westmann96c1f172013-08-01 02:05:48 -07002133 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002134
2135 {
2136 ifExpr.setCondExpr(condExpr);
2137 ifExpr.setThenExpr(thenExpr);
2138 ifExpr.setElseExpr(elseExpr);
2139 return ifExpr;
2140 }
2141}
2142
2143Expression FLWOGR() throws ParseException:
2144{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002145 FLWOGRExpression flworg = new FLWOGRExpression();
2146 List<Clause> clauseList = new ArrayList<Clause>();
2147 Expression returnExpr;
2148 Clause tmp;
2149 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002150}
2151{
2152 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08002153 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002154
2155 {
2156 flworg.setClauseList(clauseList);
2157 flworg.setReturnExpr(returnExpr);
2158 removeCurrentScope();
2159 return flworg;
2160 }
2161}
2162
2163Clause Clause()throws ParseException :
2164{
2165 Clause clause;
2166}
2167{
2168 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002169 clause = ForClause()
2170 | clause = LetClause()
2171 | clause = WhereClause()
2172 | clause = OrderbyClause()
2173 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002174 | clause = LimitClause()
2175 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002176 )
2177 {
2178 return clause;
2179 }
2180}
2181
2182Clause ForClause()throws ParseException :
2183{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002184 ForClause fc = new ForClause();
2185 VariableExpr varExp;
2186 VariableExpr varPos = null;
2187 Expression inExp;
2188 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002189}
2190{
buyingyi2fd7fa62014-11-24 19:31:55 -08002191 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00002192 {
2193 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07002194 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002195 fc.setInExpr(inExp);
2196 if (varPos != null) {
2197 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002198 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002199 }
2200 return fc;
2201 }
2202}
2203
2204Clause LetClause() throws ParseException:
2205{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002206 LetClause lc = new LetClause();
2207 VariableExpr varExp;
2208 Expression beExp;
2209 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002210}
2211{
buyingyi2fd7fa62014-11-24 19:31:55 -08002212 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002213 {
2214 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002215 lc.setVarExpr(varExp);
2216 lc.setBeExpr(beExp);
2217 return lc;
2218 }
2219}
2220
2221Clause WhereClause()throws ParseException :
2222{
2223 WhereClause wc = new WhereClause();
2224 Expression whereExpr;
2225}
2226{
salsubaieedf89fbc2013-12-21 19:51:42 -08002227 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002228 {
2229 wc.setWhereExpr(whereExpr);
2230 return wc;
2231 }
2232}
2233
2234Clause OrderbyClause()throws ParseException :
2235{
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002236 OrderbyClause oc = new OrderbyClause();
2237 Expression orderbyExpr;
2238 List<Expression> orderbyList = new ArrayList<Expression>();
2239 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2240 int numOfOrderby = 0;
vinayakb38b7ca42012-03-05 05:44:15 +00002241}
2242{
2243 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002244 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002245 {
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002246 String hint = getHint(token);
2247 if (hint != null) {
2248 if (hint.startsWith(INMEMORY_HINT)) {
2249 String splits[] = hint.split(" +");
2250 int numFrames = Integer.parseInt(splits[1]);
2251 int numTuples = Integer.parseInt(splits[2]);
2252 oc.setNumFrames(numFrames);
2253 oc.setNumTuples(numTuples);
2254 }
2255 if (hint.startsWith(RANGE_HINT)) {
2256 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
2257 }
2258 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002259 }
Till Westmann96c1f172013-08-01 02:05:48 -07002260 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002261 {
2262 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002263 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002264 }
Till Westmann96c1f172013-08-01 02:05:48 -07002265 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2266 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002267 {
2268 modifierList.add(modif);
2269 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002270
Till Westmann96c1f172013-08-01 02:05:48 -07002271 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002272 {
2273 orderbyList.add(orderbyExpr);
2274 modif = OrderbyClause.OrderModifier.ASC;
2275 }
Till Westmann96c1f172013-08-01 02:05:48 -07002276 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2277 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002278 {
2279 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002280 }
vinayakb38b7ca42012-03-05 05:44:15 +00002281 )*
2282)
2283 {
2284 oc.setModifierList(modifierList);
2285 oc.setOrderbyList(orderbyList);
2286 return oc;
2287 }
2288}
2289Clause GroupClause()throws ParseException :
2290{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002291 GroupbyClause gbc = new GroupbyClause();
2292 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2293 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002294 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002295 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2296 VariableExpr var = null;
2297 VariableExpr withVar = null;
2298 Expression expr = null;
2299 VariableExpr decorVar = null;
2300 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002301}
2302{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002303 {
2304 Scope newScope = extendCurrentScopeNoPush(true);
2305 // extendCurrentScope(true);
2306 }
Till Westmann96c1f172013-08-01 02:05:48 -07002307 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002308 {
2309 String hint = getHint(token);
2310 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002311 gbc.setHashGroupByHint(true);
2312 }
2313 }
Till Westmann96c1f172013-08-01 02:05:48 -07002314 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002315 {
2316 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002317 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002318 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002319 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002320 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002321 vePairList.add(pair1);
2322 }
Till Westmann96c1f172013-08-01 02:05:48 -07002323 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002324 {
2325 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002326 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002327 expr = Expression()
2328 {
2329 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002330 vePairList.add(pair2);
2331 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002332 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002333 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002334 {
2335 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002336 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2337 decorPairList.add(pair3);
2338 }
Till Westmann96c1f172013-08-01 02:05:48 -07002339 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002340 {
2341 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002342 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002343 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002344 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002345 )*
2346 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002347 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002348 {
2349 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002350 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002351 withVarList.add(withVar);
2352 newScope.addNewVarSymbolToScope(withVar.getVar());
2353 }
Till Westmann96c1f172013-08-01 02:05:48 -07002354 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002355 {
2356 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002357 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002358 withVarList.add(withVar);
2359 newScope.addNewVarSymbolToScope(withVar.getVar());
2360 })*
2361 {
2362 gbc.setGbyPairList(vePairList);
2363 gbc.setDecorPairList(decorPairList);
2364 gbc.setWithVarList(withVarList);
2365 replaceCurrentScope(newScope);
2366 return gbc;
2367 }
2368}
2369
2370
2371LimitClause LimitClause() throws ParseException:
2372{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002373 LimitClause lc = new LimitClause();
2374 Expression expr;
2375 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002376}
2377{
Till Westmann96c1f172013-08-01 02:05:48 -07002378 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2379 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002380
2381 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002382 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002383 return lc;
2384 }
2385}
2386
2387DistinctClause DistinctClause() throws ParseException:
2388{
2389 List<Expression> exprs = new ArrayList<Expression>();
2390 Expression expr;
2391}
2392{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002393 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002394 {
2395 exprs.add(expr);
2396 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002397 (<COMMA> expr = Expression()
2398 {
2399 exprs.add(expr);
2400 }
vinayakb38b7ca42012-03-05 05:44:15 +00002401 )*
2402 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002403 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002404 }
2405}
2406
vinayakb38b7ca42012-03-05 05:44:15 +00002407QuantifiedExpression QuantifiedExpression()throws ParseException:
2408{
2409 QuantifiedExpression qc = new QuantifiedExpression();
2410 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2411 Expression satisfiesExpr;
2412 VariableExpr var;
2413 Expression inExpr;
2414 QuantifiedPair pair;
2415}
2416{
2417 {
2418 createNewScope();
2419 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002420
Till Westmann96c1f172013-08-01 02:05:48 -07002421 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002422 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2423 var = Variable() <IN> inExpr = Expression()
2424 {
vinayakb38b7ca42012-03-05 05:44:15 +00002425 pair = new QuantifiedPair(var, inExpr);
2426 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002427 quantifiedList.add(pair);
2428 }
2429 (
2430 <COMMA> var = Variable() <IN> inExpr = Expression()
2431 {
2432 pair = new QuantifiedPair(var, inExpr);
2433 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2434 quantifiedList.add(pair);
2435 }
2436 )*
2437 <SATISFIES> satisfiesExpr = Expression()
2438 {
2439 qc.setSatisfiesExpr(satisfiesExpr);
2440 qc.setQuantifiedList(quantifiedList);
2441 removeCurrentScope();
2442 return qc;
2443 }
vinayakb38b7ca42012-03-05 05:44:15 +00002444}
2445
2446TOKEN_MGR_DECLS:
2447{
Till Westmann96c1f172013-08-01 02:05:48 -07002448 public int commentDepth = 0;
2449 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002450
Till Westmann96c1f172013-08-01 02:05:48 -07002451 public void pushState() {
2452 lexerStateStack.push( curLexState );
2453 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002454
Till Westmannfd733ee2014-07-10 00:57:37 -07002455 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002456 if (lexerStateStack.size() > 0) {
2457 SwitchTo( lexerStateStack.pop() );
2458 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002459 int errorLine = input_stream.getEndLine();
2460 int errorColumn = input_stream.getEndColumn();
2461 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2462 + "\" but state stack is empty.";
2463 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002464 }
2465 }
vinayakb38b7ca42012-03-05 05:44:15 +00002466}
2467
Till Westmann96c1f172013-08-01 02:05:48 -07002468<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002469TOKEN :
2470{
Till Westmann5df7b452013-08-02 13:07:16 -07002471 <ASC : "asc">
2472 | <AT : "at">
2473 | <BY : "by">
2474 | <DATASET : "dataset">
2475 | <DECOR : "decor">
2476 | <DESC : "desc">
2477 | <DISTINCT : "distinct">
2478 | <ELSE : "else">
2479 | <EVERY : "every">
2480 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002481 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002482 | <GROUP : "group">
2483 | <IF : "if">
2484 | <IN : "in">
2485 | <LET : "let">
2486 | <LIMIT : "limit">
2487 | <OFFSET : "offset">
2488 | <ORDER : "order">
2489 | <RETURN : "return">
2490 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002491 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002492 | <SOME : "some">
2493 | <THEN : "then">
2494 | <UNION : "union">
2495 | <WHERE : "where">
2496 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002497 | <KEEPING : "keeping">
vinayakb38b7ca42012-03-05 05:44:15 +00002498}
2499
Till Westmann96c1f172013-08-01 02:05:48 -07002500<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002501TOKEN :
2502{
Till Westmann5df7b452013-08-02 13:07:16 -07002503 <CARET : "^">
2504 | <DIV : "/">
2505 | <IDIV : "idiv">
2506 | <MINUS : "-">
2507 | <MOD : "%">
2508 | <MUL : "*">
2509 | <PLUS : "+">
2510
2511 | <LEFTPAREN : "(">
2512 | <RIGHTPAREN : ")">
2513 | <LEFTBRACKET : "[">
2514 | <RIGHTBRACKET : "]">
2515
2516 | <COLON : ":">
2517 | <COMMA : ",">
2518 | <DOT : ".">
2519 | <QUES : "?">
2520
2521 | <LT : "<">
2522 | <GT : ">">
2523 | <LE : "<=">
2524 | <GE : ">=">
2525 | <EQ : "=">
2526 | <NE : "!=">
2527 | <SIMILAR : "~=">
2528 | <ASSIGN : ":=">
2529
2530 | <AND : "and">
2531 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002532}
2533
Till Westmann96c1f172013-08-01 02:05:48 -07002534<DEFAULT,IN_DBL_BRACE>
2535TOKEN :
2536{
Till Westmann5df7b452013-08-02 13:07:16 -07002537 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002538}
2539
2540<DEFAULT>
2541TOKEN :
2542{
Till Westmannfd733ee2014-07-10 00:57:37 -07002543 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002544}
2545
Till Westmann96c1f172013-08-01 02:05:48 -07002546<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002547TOKEN :
2548{
Till Westmann5df7b452013-08-02 13:07:16 -07002549 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002550}
2551
Till Westmann96c1f172013-08-01 02:05:48 -07002552<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002553TOKEN :
2554{
Till Westmannfd733ee2014-07-10 00:57:37 -07002555 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002556}
2557
Till Westmann96c1f172013-08-01 02:05:48 -07002558<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002559TOKEN :
2560{
Till Westmann5df7b452013-08-02 13:07:16 -07002561 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002562}
2563
Till Westmann96c1f172013-08-01 02:05:48 -07002564<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002565TOKEN :
2566{
Till Westmann5df7b452013-08-02 13:07:16 -07002567 <NULL : "null">
2568 | <TRUE : "true">
2569 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002570}
2571
Till Westmann96c1f172013-08-01 02:05:48 -07002572<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002573TOKEN :
2574{
Till Westmann5df7b452013-08-02 13:07:16 -07002575 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002576}
2577
Till Westmann96c1f172013-08-01 02:05:48 -07002578<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002579TOKEN:
2580{
Till Westmann5df7b452013-08-02 13:07:16 -07002581 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002582 | <DIGITS> ( "." <DIGITS> )?
2583 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002584 >
2585 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002586 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2587 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002588 >
2589 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002590}
2591
Till Westmann96c1f172013-08-01 02:05:48 -07002592<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002593TOKEN :
2594{
Till Westmann5df7b452013-08-02 13:07:16 -07002595 <#LETTER : ["A" - "Z", "a" - "z"]>
2596 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002597}
2598
Till Westmann96c1f172013-08-01 02:05:48 -07002599<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002600TOKEN :
2601{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002602 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2603 <STRING_LITERAL : ("\"" (
2604 <EscapeQuot>
2605 | <EscapeBslash>
2606 | <EscapeSlash>
2607 | <EscapeBspace>
2608 | <EscapeFormf>
2609 | <EscapeNl>
2610 | <EscapeCr>
2611 | <EscapeTab>
2612 | ~["\"","\\"])* "\"")
2613 | ("\'"(
2614 <EscapeApos>
2615 | <EscapeBslash>
2616 | <EscapeSlash>
2617 | <EscapeBspace>
2618 | <EscapeFormf>
2619 | <EscapeNl>
2620 | <EscapeCr>
2621 | <EscapeTab>
2622 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002623 | < #EscapeQuot: "\\\"" >
2624 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002625 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002626 | < #EscapeSlash: "\\/" >
2627 | < #EscapeBspace: "\\b" >
2628 | < #EscapeFormf: "\\f" >
2629 | < #EscapeNl: "\\n" >
2630 | < #EscapeCr: "\\r" >
2631 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002632}
2633
Till Westmann96c1f172013-08-01 02:05:48 -07002634<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002635TOKEN :
2636{
Till Westmann5df7b452013-08-02 13:07:16 -07002637 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002638}
2639
Till Westmann96c1f172013-08-01 02:05:48 -07002640<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002641TOKEN :
2642{
Till Westmann5df7b452013-08-02 13:07:16 -07002643 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002644}
2645
Till Westmann96c1f172013-08-01 02:05:48 -07002646<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002647SKIP:
2648{
2649 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002650 | "\t"
2651 | "\r"
2652 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002653}
2654
Till Westmann96c1f172013-08-01 02:05:48 -07002655<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002656SKIP:
2657{
Till Westmann5df7b452013-08-02 13:07:16 -07002658 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002659}
2660
Till Westmann96c1f172013-08-01 02:05:48 -07002661<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002662SKIP:
2663{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002664 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002665}
2666
Till Westmann96c1f172013-08-01 02:05:48 -07002667<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002668SKIP:
2669{
Till Westmann96c1f172013-08-01 02:05:48 -07002670 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002671}
2672
2673<INSIDE_COMMENT>
2674SPECIAL_TOKEN:
2675{
Till Westmann5df7b452013-08-02 13:07:16 -07002676 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002677}
2678
2679<INSIDE_COMMENT>
2680SKIP:
2681{
Till Westmann96c1f172013-08-01 02:05:48 -07002682 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002683}
2684
2685<INSIDE_COMMENT>
2686SKIP:
2687{
Till Westmannfd733ee2014-07-10 00:57:37 -07002688 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002689 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002690}