blob: db63abb950cfd134724d63caa1c992338c338b72 [file] [log] [blame]
Michael Blow82464fb2017-03-28 18:48:13 -04001//
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//
Yingyi Bu391f09e2015-10-29 13:49:39 -070019options {
20
21
22 STATIC = false;
23
24}
25
26
27PARSER_BEGIN(AQLParser)
28
29package org.apache.asterix.lang.aql.parser;
30
31// For AQLParserTokenManager
Till Westmanne9b2adf2016-10-15 12:39:01 -070032import java.util.ArrayDeque;
Yingyi Bu391f09e2015-10-29 13:49:39 -070033
34import java.io.BufferedReader;
35import java.io.File;
36import java.io.FileInputStream;
37import java.io.FileNotFoundException;
38import java.io.IOException;
39import java.io.InputStreamReader;
40import java.io.Reader;
41import java.io.StringReader;
42import java.util.ArrayList;
43import java.util.HashMap;
44import java.util.LinkedHashMap;
45import java.util.List;
46import java.util.Map;
47
48import org.apache.asterix.common.annotations.AutoDataGen;
49import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
50import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
51import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
52import org.apache.asterix.common.annotations.FieldIntervalDataGen;
53import org.apache.asterix.common.annotations.FieldValFileDataGen;
54import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
55import org.apache.asterix.common.annotations.IRecordFieldDataGen;
56import org.apache.asterix.common.annotations.InsertRandIntDataGen;
57import org.apache.asterix.common.annotations.ListDataGen;
58import org.apache.asterix.common.annotations.ListValFileDataGen;
59import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
60import org.apache.asterix.common.annotations.TypeDataGen;
61import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
62import org.apache.asterix.common.config.DatasetConfig.DatasetType;
63import org.apache.asterix.common.config.DatasetConfig.IndexType;
Taewoo Kime65e6ca2017-01-14 17:53:28 -080064import org.apache.asterix.common.exceptions.CompilationException;
Yingyi Bu391f09e2015-10-29 13:49:39 -070065import org.apache.asterix.common.functions.FunctionSignature;
66import org.apache.asterix.lang.aql.clause.DistinctClause;
67import org.apache.asterix.lang.aql.clause.ForClause;
68import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
69import org.apache.asterix.lang.aql.expression.UnionExpr;
70import org.apache.asterix.lang.aql.util.RangeMapBuilder;
Yingyi Bucb5bf332017-01-02 22:19:50 -080071import org.apache.asterix.lang.aql.util.AQLFormatPrintUtil;
Yingyi Bu391f09e2015-10-29 13:49:39 -070072import org.apache.asterix.lang.common.base.Clause;
73import org.apache.asterix.lang.common.base.Expression;
Yingyi Bucb5bf332017-01-02 22:19:50 -080074import org.apache.asterix.lang.common.base.ILangExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -070075import org.apache.asterix.lang.common.base.IParser;
76import org.apache.asterix.lang.common.base.Literal;
77import org.apache.asterix.lang.common.base.Statement;
78import org.apache.asterix.lang.common.clause.GroupbyClause;
79import org.apache.asterix.lang.common.clause.LetClause;
80import org.apache.asterix.lang.common.clause.LimitClause;
81import org.apache.asterix.lang.common.clause.OrderbyClause;
82import org.apache.asterix.lang.common.clause.UpdateClause;
83import org.apache.asterix.lang.common.clause.WhereClause;
84import org.apache.asterix.lang.common.context.RootScopeFactory;
85import org.apache.asterix.lang.common.context.Scope;
86import org.apache.asterix.lang.common.expression.AbstractAccessor;
87import org.apache.asterix.lang.common.expression.CallExpr;
88import org.apache.asterix.lang.common.expression.FieldAccessor;
89import org.apache.asterix.lang.common.expression.FieldBinding;
90import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
91import org.apache.asterix.lang.common.expression.IfExpr;
92import org.apache.asterix.lang.common.expression.IndexAccessor;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -070093import org.apache.asterix.lang.common.expression.IndexedTypeExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -070094import org.apache.asterix.lang.common.expression.ListConstructor;
95import org.apache.asterix.lang.common.expression.LiteralExpr;
96import org.apache.asterix.lang.common.expression.OperatorExpr;
97import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
98import org.apache.asterix.lang.common.expression.QuantifiedExpression;
99import org.apache.asterix.lang.common.expression.RecordConstructor;
100import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
101import org.apache.asterix.lang.common.expression.TypeExpression;
102import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
103import org.apache.asterix.lang.common.expression.UnaryExpr;
104import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
105import org.apache.asterix.lang.common.expression.VariableExpr;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700106import org.apache.asterix.lang.common.literal.DoubleLiteral;
107import org.apache.asterix.lang.common.literal.FalseLiteral;
108import org.apache.asterix.lang.common.literal.FloatLiteral;
109import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
Yingyi Bu535d86b2016-05-23 16:44:25 -0700110import org.apache.asterix.lang.common.literal.MissingLiteral;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700111import org.apache.asterix.lang.common.literal.NullLiteral;
112import org.apache.asterix.lang.common.literal.StringLiteral;
113import org.apache.asterix.lang.common.literal.TrueLiteral;
114import org.apache.asterix.lang.common.parser.ScopeChecker;
115import org.apache.asterix.lang.common.statement.CompactStatement;
116import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
117import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
118import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
119import org.apache.asterix.lang.common.statement.CreateFeedStatement;
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800120import org.apache.asterix.lang.common.statement.StartFeedStatement;
121import org.apache.asterix.lang.common.statement.StopFeedStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700122import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
123import org.apache.asterix.lang.common.statement.CreateIndexStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700124import org.apache.asterix.lang.common.statement.DatasetDecl;
125import org.apache.asterix.lang.common.statement.DataverseDecl;
126import org.apache.asterix.lang.common.statement.DataverseDropStatement;
127import org.apache.asterix.lang.common.statement.DeleteStatement;
128import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
Yingyi Buab817482016-08-19 21:29:31 -0700129import org.apache.asterix.lang.common.statement.DropDatasetStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700130import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
131import org.apache.asterix.lang.common.statement.FeedDropStatement;
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300132import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700133import org.apache.asterix.lang.common.statement.FunctionDecl;
134import org.apache.asterix.lang.common.statement.FunctionDropStatement;
135import org.apache.asterix.lang.common.statement.IndexDropStatement;
136import org.apache.asterix.lang.common.statement.InsertStatement;
137import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
138import org.apache.asterix.lang.common.statement.LoadStatement;
139import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
140import org.apache.asterix.lang.common.statement.NodegroupDecl;
141import org.apache.asterix.lang.common.statement.Query;
142import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
143import org.apache.asterix.lang.common.statement.RunStatement;
144import org.apache.asterix.lang.common.statement.SetStatement;
145import org.apache.asterix.lang.common.statement.TypeDecl;
146import org.apache.asterix.lang.common.statement.TypeDropStatement;
147import org.apache.asterix.lang.common.statement.UpdateStatement;
Abdullah Alamoudi5dc958c2016-01-30 11:15:23 +0300148import org.apache.asterix.lang.common.statement.UpsertStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700149import org.apache.asterix.lang.common.statement.WriteStatement;
150import org.apache.asterix.lang.common.struct.Identifier;
151import org.apache.asterix.lang.common.struct.QuantifiedPair;
152import org.apache.asterix.lang.common.struct.VarIdentifier;
Yingyi Buab817482016-08-19 21:29:31 -0700153import org.apache.asterix.metadata.utils.MetadataConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700154import org.apache.hyracks.algebricks.common.utils.Pair;
155import org.apache.hyracks.algebricks.common.utils.Triple;
156import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
157import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
158import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
159
160
Yingyi Bucaea8f02015-11-16 15:12:15 -0800161class AQLParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700162
163 // optimizer hints
164 private static final String AUTO_HINT = "auto";
165 private static final String BROADCAST_JOIN_HINT = "bcast";
166 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
167 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
168 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
169 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
170 private static final String HASH_GROUP_BY_HINT = "hash";
171 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
172 private static final String INMEMORY_HINT = "inmem";
173 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
174 private static final String INTERVAL_HINT = "interval";
175 private static final String LIST_HINT = "list";
176 private static final String LIST_VAL_FILE_HINT = "list-val-file";
177 private static final String RANGE_HINT = "range";
178 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
179 private static final String VAL_FILE_HINT = "val-files";
180 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
Yingyi Bu391f09e2015-10-29 13:49:39 -0700181 private static final String GEN_FIELDS_HINT = "gen-fields";
Yingyi Bu391f09e2015-10-29 13:49:39 -0700182 // data generator hints
183 private static final String DGEN_HINT = "dgen";
184
185 private static class IndexParams {
186 public IndexType type;
187 public int gramLength;
188
189 public IndexParams(IndexType type, int gramLength) {
190 this.type = type;
191 this.gramLength = gramLength;
192 }
193 };
194
195 private static class FunctionName {
196 public String dataverse = null;
197 public String library = null;
198 public String function = null;
199 public String hint = null;
200 }
201
202 private static String getHint(Token t) {
203 if (t.specialToken == null) {
204 return null;
205 }
206 String s = t.specialToken.image;
207 int n = s.length();
208 if (n < 2) {
209 return null;
210 }
211 return s.substring(1).trim();
212 }
213
Yingyi Bucb5bf332017-01-02 22:19:50 -0800214 private static void checkBindingVariable(Expression returnExpression, VariableExpr var,
215 ILangExpression bodyExpression) throws ParseException {
216 if (returnExpression != null && var == null) {
217 try {
218 throw new ParseException("Need a binding variable for the enclosed expression: " +
219 AQLFormatPrintUtil.toString(bodyExpression));
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800220 } catch (CompilationException e){
Yingyi Bucb5bf332017-01-02 22:19:50 -0800221 throw new ParseException(e.getLocalizedMessage());
222 }
223 }
224 }
225
Yingyi Bu391f09e2015-10-29 13:49:39 -0700226 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
227 IRecordFieldDataGen rfdg = null;
228 String splits[] = hint.split(" +");
229 if (splits[0].equals(VAL_FILE_HINT)) {
230 File[] valFiles = new File[splits.length - 1];
231 for (int k=1; k<splits.length; k++) {
232 valFiles[k-1] = new File(splits[k]);
233 }
234 rfdg = new FieldValFileDataGen(valFiles);
235 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
236 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
237 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
238 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
239 } else if (splits[0].equals(LIST_HINT)) {
240 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
241 } else if (splits[0].equals(INTERVAL_HINT)) {
242 FieldIntervalDataGen.ValueType vt;
243 if (splits[1].equals("int")) {
244 vt = FieldIntervalDataGen.ValueType.INT;
245 } else if (splits[1].equals("long")) {
246 vt = FieldIntervalDataGen.ValueType.LONG;
247 } else if (splits[1].equals("float")) {
248 vt = FieldIntervalDataGen.ValueType.FLOAT;
249 } else if (splits[1].equals("double")) {
250 vt = FieldIntervalDataGen.ValueType.DOUBLE;
251 } else {
252 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
253 }
254 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
255 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
256 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
257 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
258 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
259 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
260 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
261 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
262 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
263 } else if (splits[0].equals(AUTO_HINT)) {
264 rfdg = new AutoDataGen(splits[1]);
265 }
266 return rfdg;
267 }
268
269 public AQLParser(String s){
270 this(new StringReader(s));
271 super.setInput(s);
272 }
273
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800274 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700275 File file = new File(args[0]);
276 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
277 AQLParser parser = new AQLParser(fis);
278 List<Statement> st = parser.parse();
279 //st.accept(new AQLPrintVisitor(), 0);
280 }
281
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800282 public List<Statement> parse() throws CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700283 try {
284 return Statement();
285 } catch (Error e) {
286 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
287 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800288 throw new CompilationException(new ParseException(e.getMessage()));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700289 } catch (ParseException e){
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800290 throw new CompilationException(e.getMessage());
Yingyi Bu391f09e2015-10-29 13:49:39 -0700291 }
292 }
293}
294
295PARSER_END(AQLParser)
296
297
298List<Statement> Statement() throws ParseException:
299{
300 scopeStack.push(RootScopeFactory.createRootScope(this));
301 List<Statement> decls = new ArrayList<Statement>();
302 Statement stmt = null;
303}
304{
305 ( stmt = SingleStatement() (";") ?
306 {
307 decls.add(stmt);
308 }
309 )*
Till Westmann81870d72017-03-16 18:11:23 -0700310 (";") *
Yingyi Bu391f09e2015-10-29 13:49:39 -0700311 <EOF>
312 {
313 return decls;
314 }
315}
316
317Statement SingleStatement() throws ParseException:
318{
319 Statement stmt = null;
320}
321{
322 (
323 stmt = DataverseDeclaration()
324 | stmt = FunctionDeclaration()
325 | stmt = CreateStatement()
326 | stmt = LoadStatement()
327 | stmt = DropStatement()
328 | stmt = WriteStatement()
329 | stmt = SetStatement()
330 | stmt = InsertStatement()
Yingyi Bucb5bf332017-01-02 22:19:50 -0800331 | stmt = UpsertStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700332 | stmt = DeleteStatement()
333 | stmt = UpdateStatement()
334 | stmt = FeedStatement()
335 | stmt = CompactStatement()
336 | stmt = Query()
337 | stmt = RefreshExternalDatasetStatement()
338 | stmt = RunStatement()
339 )
340 {
341 return stmt;
342 }
343}
344
345DataverseDecl DataverseDeclaration() throws ParseException:
346{
347 String dvName = null;
348}
349{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400350 <USE> <DATAVERSE> dvName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700351 {
352 defaultDataverse = dvName;
353 return new DataverseDecl(new Identifier(dvName));
354 }
355}
356
357Statement CreateStatement() throws ParseException:
358{
359 String hint = null;
360 boolean dgen = false;
361 Statement stmt = null;
362}
363{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400364 <CREATE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700365 (
366 {
367 hint = getHint(token);
368 if (hint != null && hint.startsWith(DGEN_HINT)) {
369 dgen = true;
370 }
371 }
372 stmt = TypeSpecification(hint, dgen)
373 | stmt = NodegroupSpecification()
374 | stmt = DatasetSpecification()
375 | stmt = IndexSpecification()
376 | stmt = DataverseSpecification()
377 | stmt = FunctionSpecification()
378 | stmt = FeedSpecification()
379 | stmt = FeedPolicySpecification()
380 )
381 {
382 return stmt;
383 }
384}
385
386TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
387{
388 Pair<Identifier,Identifier> nameComponents = null;
389 boolean ifNotExists = false;
390 TypeExpression typeExpr = null;
391}
392{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400393 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
394 <AS> typeExpr = TypeExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700395 {
396 long numValues = -1;
397 String filename = null;
398 if (dgen) {
399 String splits[] = hint.split(" +");
400 if (splits.length != 3) {
401 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
402 }
403 filename = splits[1];
404 numValues = Long.parseLong(splits[2]);
405 }
406 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
407 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
408 }
409}
410
411
412NodegroupDecl NodegroupSpecification() throws ParseException:
413{
414 String name = null;
415 String tmp = null;
416 boolean ifNotExists = false;
417 List<Identifier>ncNames = null;
418}
419{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400420 <NODEGROUP> name = Identifier()
421 ifNotExists = IfNotExists() <ON> tmp = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700422 {
423 ncNames = new ArrayList<Identifier>();
424 ncNames.add(new Identifier(tmp));
425 }
426 ( <COMMA> tmp = Identifier()
427 {
428 ncNames.add(new Identifier(tmp));
429 }
430 )*
431 {
432 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
433 }
434}
435
436DatasetDecl DatasetSpecification() throws ParseException:
437{
438 Pair<Identifier,Identifier> nameComponents = null;
439 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800440 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700441 String adapterName = null;
442 Map<String,String> properties = null;
443 Map<String,String> compactionPolicyProperties = null;
444 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800445 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700446 String nodeGroupName = null;
447 Map<String,String> hints = new HashMap<String,String>();
448 DatasetDecl dsetDecl = null;
449 boolean autogenerated = false;
450 String compactionPolicy = null;
451 boolean temp = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800452 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800453 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700454}
455{
456 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400457 <EXTERNAL> <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800458 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700459 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400460 <USING> adapterName = AdapterName() properties = Configuration()
461 ( <ON> nodeGroupName = Identifier() )?
462 ( <HINTS> hints = Properties() )?
463 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700464 {
465 ExternalDetailsDecl edd = new ExternalDetailsDecl();
466 edd.setAdapter(adapterName);
467 edd.setProperties(properties);
468 dsetDecl = new DatasetDecl(nameComponents.first,
469 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800470 typeComponents.first,
471 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800472 metaTypeComponents.first,
473 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700474 nodeGroupName != null? new Identifier(nodeGroupName): null,
475 compactionPolicy,
476 compactionPolicyProperties,
477 hints,
478 DatasetType.EXTERNAL,
479 edd,
480 ifNotExists);
481 }
482
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400483 | (<INTERNAL> | <TEMPORARY> {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700484 temp = token.image.toLowerCase().equals("temporary");
485 }
Yingyi Bub9169b62016-02-26 21:21:49 -0800486 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700487 <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800488 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800489 (
490 { String name; }
491 <WITH>
492 name = Identifier()
493 {
494 if(!name.equals("meta")){
495 throw new ParseException("We can only support one additional associated field called \"meta\".");
496 }
497 }
498 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
499 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700500 ifNotExists = IfNotExists()
501 primaryKeyFields = PrimaryKey()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400502 ( <AUTOGENERATED> { autogenerated = true; } )?
503 ( <ON> nodeGroupName = Identifier() )?
504 ( <HINTS> hints = Properties() )?
505 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
506 ( <WITH> <FILTER> <ON> filterField = NestedField() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700507 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800508 if(filterField!=null && filterField.first!=0){
509 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
510 }
511 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
512 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700513 autogenerated,
Yingyi Buc9bfe252016-03-01 00:02:40 -0800514 filterField == null? null : filterField.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700515 temp);
516 dsetDecl = new DatasetDecl(nameComponents.first,
517 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800518 typeComponents.first,
519 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800520 metaTypeComponents.first,
521 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700522 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
523 compactionPolicy,
524 compactionPolicyProperties,
525 hints,
526 DatasetType.INTERNAL,
527 idd,
528 ifNotExists);
529 }
530 )
531 {
532 return dsetDecl;
533 }
534}
535
536RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
537{
538 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
539 Pair<Identifier,Identifier> nameComponents = null;
540 String datasetName = null;
541}
542{
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +0300543 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400544 <REFRESH> <EXTERNAL> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700545 {
546 redss.setDataverseName(nameComponents.first);
547 redss.setDatasetName(nameComponents.second);
548 return redss;
549 }
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +0300550 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700551}
552
553RunStatement RunStatement() throws ParseException:
554{
555 String system = null;
556 String tmp;
557 ArrayList<String> parameters = new ArrayList<String>();
558 Pair<Identifier,Identifier> nameComponentsFrom = null;
559 Pair<Identifier,Identifier> nameComponentsTo = null;
560}
561{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400562 <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
Yingyi Bu391f09e2015-10-29 13:49:39 -0700563 {
564 parameters.add(tmp);
565 }
566 )*<RIGHTPAREN>
567 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400568 <TO> <DATASET> nameComponentsTo = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700569 {
570 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
571 }
572}
573
574CreateIndexStatement IndexSpecification() throws ParseException:
575{
576 CreateIndexStatement cis = new CreateIndexStatement();
577 String indexName = null;
578 boolean ifNotExists = false;
579 Pair<Identifier,Identifier> nameComponents = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -0700580 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700581 IndexParams indexType = null;
582 boolean enforced = false;
583}
584{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400585 <INDEX> indexName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700586 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400587 <ON> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700588 <LEFTPAREN> ( fieldPair = OpenField()
589 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800590 cis.addFieldExprPair(fieldPair.second);
591 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700592 }
593 ) (<COMMA> fieldPair = OpenField()
594 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800595 cis.addFieldExprPair(fieldPair.second);
596 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700597 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400598 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700599 {
600 cis.setIndexName(new Identifier(indexName));
601 cis.setIfNotExists(ifNotExists);
602 cis.setDataverseName(nameComponents.first);
603 cis.setDatasetName(nameComponents.second);
604 if (indexType != null) {
605 cis.setIndexType(indexType.type);
606 cis.setGramLength(indexType.gramLength);
607 }
608 cis.setEnforced(enforced);
609 return cis;
610 }
611}
612
613String CompactionPolicy() throws ParseException :
614{
615 String compactionPolicy = null;
616}
617{
618 compactionPolicy = Identifier()
619 {
620 return compactionPolicy;
621 }
622}
623
624String FilterField() throws ParseException :
625{
626 String filterField = null;
627}
628{
629 filterField = Identifier()
630 {
631 return filterField;
632 }
633}
634
635IndexParams IndexType() throws ParseException:
636{
637 IndexType type = null;
638 int gramLength = 0;
639}
640{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400641 (
642 <BTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700643 {
644 type = IndexType.BTREE;
645 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400646 |<RTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700647 {
648 type = IndexType.RTREE;
649 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400650 |<KEYWORD>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700651 {
652 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
653 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800654 |<FULLTEXT>
655 {
656 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
657 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400658 |<NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700659 {
660 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
661 gramLength = Integer.valueOf(token.image);
662 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400663 <RIGHTPAREN>
664 )
665 {
666 return new IndexParams(type, gramLength);
667 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700668}
669
670CreateDataverseStatement DataverseSpecification() throws ParseException :
671{
672 String dvName = null;
673 boolean ifNotExists = false;
674 String format = null;
675}
676{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400677 <DATAVERSE> dvName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700678 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400679 ( <WITH> <FORMAT> format = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700680 {
681 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
682 }
683}
684
685CreateFunctionStatement FunctionSpecification() throws ParseException:
686{
687 FunctionSignature signature;
688 boolean ifNotExists = false;
689 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
690 String functionBody;
691 VarIdentifier var = null;
692 Expression functionBodyExpr;
693 Token beginPos;
694 Token endPos;
695 FunctionName fctName = null;
696
697 createNewScope();
698}
699{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400700 <FUNCTION> fctName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700701 ifNotExists = IfNotExists()
702 paramList = ParameterList()
703 <LEFTBRACE>
704 {
705 beginPos = token;
706 }
707 functionBodyExpr = Expression() <RIGHTBRACE>
708 {
709 endPos = token;
710 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
711 // TODO use fctName.library
712 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
713 getCurrentScope().addFunctionDescriptor(signature, false);
714 removeCurrentScope();
715 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
716 }
717}
718
719CreateFeedStatement FeedSpecification() throws ParseException:
720{
721 Pair<Identifier,Identifier> nameComponents = null;
722 boolean ifNotExists = false;
723 String adapterName = null;
724 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700725 CreateFeedStatement cfs = null;
726 Pair<Identifier,Identifier> sourceNameComponents = null;
Michael Blowd6cf6412016-06-30 02:44:35 -0400727
Yingyi Bu391f09e2015-10-29 13:49:39 -0700728}
729{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800730 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
731 <USING> adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400732 {
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800733 cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists);
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400734 return cfs;
735 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700736}
737
738CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
739{
Michael Blowd6cf6412016-06-30 02:44:35 -0400740 String policyName = null;
741 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700742 String sourcePolicyFile = null;
743 String definition = null;
744 boolean ifNotExists = false;
745 Map<String,String> properties = null;
746 CreateFeedPolicyStatement cfps = null;
747}
748{
749 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400750 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
751 <FROM>
752 (
753 <POLICY> basePolicyName = Identifier() properties = Configuration() ( <DEFINITION> definition = StringLiteral())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700754 {
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400755 cfps = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700756 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300757 |<PATH> sourcePolicyFile = StringLiteral() (<DEFINITION> definition = StringLiteral())?
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400758 {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700759 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400760 }
761 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700762 )
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400763 {
764 return cfps;
765 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700766}
767
768
769
770List<VarIdentifier> ParameterList() throws ParseException:
771{
772 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
773 VarIdentifier var = null;
774}
775{
776 <LEFTPAREN> (<VARIABLE>
777 {
778 var = new VarIdentifier();
779 var.setValue(token.image);
780 paramList.add(var);
781 getCurrentScope().addNewVarSymbolToScope(var);
782 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400783 ( <COMMA> <VARIABLE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700784 {
785 var = new VarIdentifier();
786 var.setValue(token.image);
787 paramList.add(var);
788 getCurrentScope().addNewVarSymbolToScope(var);
789 }
790 )*)? <RIGHTPAREN>
791 {
792 return paramList;
793 }
794}
795
796boolean IfNotExists() throws ParseException:
797{
798}
799{
Yingyi Budcd91122016-08-10 12:13:36 -0700800 (
801 LOOKAHEAD(1)
802 <IF>
803 <IDENTIFIER>
804 (
805 {
806 if(!token.image.equals("not")){
807 throw new ParseException("Expect word \"not\" at line " + token.beginLine + ", column "
808 + token.beginColumn +"!");
809 }
810 }
811 )
812 <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700813 {
814 return true;
815 }
816 )?
817 {
818 return false;
819 }
820}
821
Xikui Wang9d63f622017-05-18 17:50:44 -0700822void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700823{
824 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700825 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700826}
827{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400828 <APPLY> <FUNCTION> functioName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700829 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700830 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
831 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
832 }
833 (
834 <COMMA> functioName = FunctionName()
835 {
836 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
837 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
838 }
839 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700840}
841
842String GetPolicy() throws ParseException:
843{
844 String policy = null;
845}
846{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400847 <USING> <POLICY> policy = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700848 {
849 return policy;
850 }
851
852}
853
854FunctionSignature FunctionSignature() throws ParseException:
855{
856 FunctionName fctName = null;
857 int arity = 0;
858}
859{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400860 fctName = FunctionName() <SYMBOLAT> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700861 {
862 arity = new Integer(token.image);
863 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
864 throw new ParseException(" invalid arity:" + arity);
865 }
866
867 // TODO use fctName.library
868 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
869 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
870 }
871}
872
Yingyi Buc9bfe252016-03-01 00:02:40 -0800873Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700874{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800875 Pair<Integer, List<String>> tmp = null;
876 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
877 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700878}
879{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400880 <PRIMARY> <KEY> tmp = NestedField()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700881 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800882 keyFieldSourceIndicators.add(tmp.first);
883 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700884 }
885 ( <COMMA> tmp = NestedField()
886 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800887 keyFieldSourceIndicators.add(tmp.first);
888 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700889 }
890 )*
891 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800892 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700893 }
894}
895
896Statement DropStatement() throws ParseException:
897{
898 String id = null;
899 Pair<Identifier,Identifier> pairId = null;
900 Triple<Identifier,Identifier,Identifier> tripleId = null;
901 FunctionSignature funcSig = null;
902 boolean ifExists = false;
903 Statement stmt = null;
904}
905{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400906 <DROP>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700907 (
908 <DATASET> pairId = QualifiedName() ifExists = IfExists()
909 {
Yingyi Buab817482016-08-19 21:29:31 -0700910 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700911 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400912 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700913 {
914 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
915 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400916 | <NODEGROUP> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700917 {
918 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
919 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400920 | <TYPE> pairId = TypeName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700921 {
922 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
923 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400924 | <DATAVERSE> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700925 {
926 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
927 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400928 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700929 {
930 stmt = new FunctionDropStatement(funcSig, ifExists);
931 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400932 | <FEED> pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700933 {
934 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
935 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300936 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
937 {
938 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
939 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700940 )
941 {
942 return stmt;
943 }
944}
945
946boolean IfExists() throws ParseException :
947{
948}
949{
Yingyi Budcd91122016-08-10 12:13:36 -0700950 (
951 LOOKAHEAD(1)
952 <IF> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700953 {
954 return true;
955 }
956 )?
957 {
958 return false;
959 }
960}
961
962InsertStatement InsertStatement() throws ParseException:
963{
964 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800965 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700966 Query query;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800967 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700968}
969{
Yingyi Bucb5bf332017-01-02 22:19:50 -0800970 <INSERT> <INTO> <DATASET> nameComponents = QualifiedName()
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -0700971 (<AS> var = Variable())?
972 {
973 if(var != null){
974 getCurrentScope().addNewVarSymbolToScope(var.getVar());
975 }
976 }
Yingyi Bucb5bf332017-01-02 22:19:50 -0800977 query = Query() ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700978 {
Yingyi Bucb5bf332017-01-02 22:19:50 -0800979 checkBindingVariable(returnExpression, var, query);
Yingyi Bucaea8f02015-11-16 15:12:15 -0800980 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -0800981 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
982 returnExpression);
983 }
984}
985
986UpsertStatement UpsertStatement() throws ParseException:
987{
988 Pair<Identifier,Identifier> nameComponents = null;
989 VariableExpr var = null;
990 Query query;
991 Expression returnExpression = null;
992}
993{
994 <UPSERT> <INTO> <DATASET> nameComponents = QualifiedName()
995 (<AS> var = Variable())?
996 {
997 if(var != null){
998 getCurrentScope().addNewVarSymbolToScope(var.getVar());
999 }
1000 }
1001 query = Query() ( <RETURNING> returnExpression = Expression())?
1002 {
1003 checkBindingVariable(returnExpression, var, query);
1004 query.setTopLevel(true);
1005 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1006 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001007 }
1008}
1009
1010DeleteStatement DeleteStatement() throws ParseException:
1011{
1012 VariableExpr var = null;
1013 Expression condition = null;
1014 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001015}
1016{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001017 <DELETE> var = Variable()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001018 {
1019 getCurrentScope().addNewVarSymbolToScope(var.getVar());
1020 }
1021 <FROM> <DATASET> nameComponents = QualifiedName()
1022 (<WHERE> condition = Expression())?
1023 {
1024 // First we get the dataverses and datasets that we want to lock
Yingyi Bu391f09e2015-10-29 13:49:39 -07001025 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001026 condition, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001027 }
1028}
1029
1030UpdateStatement UpdateStatement() throws ParseException:
1031{
1032 VariableExpr vars;
1033 Expression target;
1034 Expression condition;
1035 UpdateClause uc;
1036 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1037}
1038{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001039 <UPDATE> vars = Variable() <IN> target = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001040 <WHERE> condition = Expression()
1041 <LEFTPAREN> (uc = UpdateClause()
1042 {
1043 ucs.add(uc);
1044 }
1045 (<COMMA> uc = UpdateClause()
1046 {
1047 ucs.add(uc);
1048 }
1049 )*) <RIGHTPAREN>
1050 {
1051 return new UpdateStatement(vars, target, condition, ucs);
1052 }
1053}
1054
1055UpdateClause UpdateClause() throws ParseException:
1056{
1057 Expression target = null;
1058 Expression value = null ;
1059 InsertStatement is = null;
1060 DeleteStatement ds = null;
1061 UpdateStatement us = null;
1062 Expression condition = null;
1063 UpdateClause ifbranch = null;
1064 UpdateClause elsebranch = null;
1065}
1066{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001067 (<SET> target = Expression() <ASSIGN> value = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001068 | is = InsertStatement()
1069 | ds = DeleteStatement()
1070 | us = UpdateStatement()
1071 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1072 <THEN> ifbranch = UpdateClause()
1073 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1074 {
1075 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1076 }
1077 )
1078}
1079
1080Statement SetStatement() throws ParseException:
1081{
1082 String pn = null;
1083 String pv = null;
1084}
1085{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001086 <SET> pn = Identifier() pv = StringLiteral()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001087 {
1088 return new SetStatement(pn, pv);
1089 }
1090}
1091
1092Statement WriteStatement() throws ParseException:
1093{
1094 String nodeName = null;
1095 String fileName = null;
1096 Query query;
1097 String writerClass = null;
1098 Pair<Identifier,Identifier> nameComponents = null;
1099}
1100{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001101 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = StringLiteral()
1102 ( <USING> writerClass = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001103 {
1104 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1105 }
1106}
1107
1108LoadStatement LoadStatement() throws ParseException:
1109{
1110 Identifier dataverseName = null;
1111 Identifier datasetName = null;
1112 boolean alreadySorted = false;
1113 String adapterName;
1114 Map<String,String> properties;
1115 Pair<Identifier,Identifier> nameComponents = null;
1116}
1117{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001118 <LOAD> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001119 {
1120 dataverseName = nameComponents.first;
1121 datasetName = nameComponents.second;
1122 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001123 <USING> adapterName = AdapterName() properties = Configuration()
1124 (<PRESORTED>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001125 {
1126 alreadySorted = true;
1127 }
1128 )?
1129 {
1130 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1131 }
1132}
1133
1134
1135String AdapterName() throws ParseException :
1136{
1137 String adapterName = null;
1138}
1139{
1140 adapterName = Identifier()
1141 {
1142 return adapterName;
1143 }
1144}
1145
1146Statement CompactStatement() throws ParseException:
1147{
1148 Pair<Identifier,Identifier> nameComponents = null;
1149 Statement stmt = null;
1150}
1151{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001152 <COMPACT> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001153 {
1154 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1155 }
1156 {
1157 return stmt;
1158 }
1159}
1160
1161Statement FeedStatement() throws ParseException:
1162{
1163 Pair<Identifier,Identifier> feedNameComponents = null;
1164 Pair<Identifier,Identifier> datasetNameComponents = null;
1165
1166 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001167 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07001168 Statement stmt = null;
1169 String policy = null;
1170}
1171{
1172 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001173 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName()
Xikui Wang9d63f622017-05-18 17:50:44 -07001174 (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001175 {
Xikui Wang261dc6d2017-03-29 21:23:15 -07001176 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions, policy, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001177 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001178 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001179 {
1180 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1181 }
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001182 | <START> <FEED> feedNameComponents = QualifiedName()
1183 {
1184 stmt = new StartFeedStatement (feedNameComponents);
1185 }
1186 | <STOP> <FEED> feedNameComponents = QualifiedName()
1187 {
1188 stmt = new StopFeedStatement (feedNameComponents);
1189 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001190 )
1191 {
1192 return stmt;
1193 }
1194}
1195
1196Map<String,String> Configuration() throws ParseException :
1197{
1198 Map<String,String> configuration = new LinkedHashMap<String,String>();
1199 Pair<String, String> keyValuePair = null;
1200}
1201{
1202 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1203 {
1204 configuration.put(keyValuePair.first, keyValuePair.second);
1205 }
1206 ( <COMMA> keyValuePair = KeyValuePair()
1207 {
1208 configuration.put(keyValuePair.first, keyValuePair.second);
1209 }
1210 )* )? <RIGHTPAREN>
1211 {
1212 return configuration;
1213 }
1214}
1215
1216Pair<String, String> KeyValuePair() throws ParseException:
1217{
1218 String key;
1219 String value;
1220}
1221{
1222 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
1223 {
1224 return new Pair<String, String>(key, value);
1225 }
1226}
1227
1228Map<String,String> Properties() throws ParseException:
1229{
1230 Map<String,String> properties = new HashMap<String,String>();
1231 Pair<String, String> property;
1232}
1233{
1234 ( <LEFTPAREN> property = Property()
1235 {
1236 properties.put(property.first, property.second);
1237 }
1238 ( <COMMA> property = Property()
1239 {
1240 properties.put(property.first, property.second);
1241 }
1242 )* <RIGHTPAREN> )?
1243 {
1244 return properties;
1245 }
1246}
1247
1248Pair<String, String> Property() throws ParseException:
1249{
1250 String key;
1251 String value;
1252}
1253{
1254 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
1255 {
1256 try {
1257 value = "" + Long.valueOf(token.image);
1258 } catch (NumberFormatException nfe) {
1259 throw new ParseException("inapproriate value: " + token.image);
1260 }
1261 }
1262 )
1263 {
1264 return new Pair<String, String>(key.toUpperCase(), value);
1265 }
1266}
1267
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001268IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001269{
1270 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001271 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001272}
1273{
1274 (
1275 typeExpr = TypeReference()
1276 | typeExpr = OrderedListTypeDef()
1277 | typeExpr = UnorderedListTypeDef()
1278 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001279 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001280 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001281 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001282 }
1283}
1284
1285TypeExpression TypeExpr() throws ParseException:
1286{
1287 TypeExpression typeExpr = null;
1288}
1289{
1290 (
1291 typeExpr = RecordTypeDef()
1292 | typeExpr = TypeReference()
1293 | typeExpr = OrderedListTypeDef()
1294 | typeExpr = UnorderedListTypeDef()
1295 )
1296 {
1297 return typeExpr;
1298 }
1299}
1300
1301RecordTypeDefinition RecordTypeDef() throws ParseException:
1302{
1303 RecordTypeDefinition recType = new RecordTypeDefinition();
1304 RecordTypeDefinition.RecordKind recordKind = null;
1305}
1306{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001307 ( <CLOSED>{ recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1308 | <OPEN>{ recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001309 <LEFTBRACE>
1310 {
1311 String hint = getHint(token);
1312 if (hint != null) {
1313 String splits[] = hint.split(" +");
1314 if (splits[0].equals(GEN_FIELDS_HINT)) {
1315 if (splits.length != 5) {
1316 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1317 }
1318 if (!splits[1].equals("int")) {
1319 throw new ParseException("The only supported type for gen-fields is int.");
1320 }
1321 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1322 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1323 recType.setUndeclaredFieldsDataGen(ufdg);
1324 }
1325 }
1326
1327 }
1328 (
1329 RecordField(recType)
1330 ( <COMMA> RecordField(recType) )*
1331 )?
1332 <RIGHTBRACE>
1333 {
1334 if (recordKind == null) {
1335 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1336 }
1337 recType.setRecordKind(recordKind);
1338 return recType;
1339 }
1340}
1341
1342void RecordField(RecordTypeDefinition recType) throws ParseException:
1343{
1344 String fieldName;
1345 TypeExpression type = null;
1346 boolean nullable = false;
1347}
1348{
1349 fieldName = Identifier()
1350 {
1351 String hint = getHint(token);
1352 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1353 }
1354 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1355 {
1356 recType.addField(fieldName, type, nullable, rfdg);
1357 }
1358}
1359
1360TypeReferenceExpression TypeReference() throws ParseException:
1361{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001362 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001363}
1364{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001365 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001366 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001367 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1368 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001369 }
1370
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001371 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001372 }
1373}
1374
1375OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1376{
1377 TypeExpression type = null;
1378}
1379{
1380 <LEFTBRACKET>
1381 ( type = TypeExpr() )
1382 <RIGHTBRACKET>
1383 {
1384 return new OrderedListTypeDefinition(type);
1385 }
1386}
1387
1388
1389UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1390{
1391 TypeExpression type = null;
1392}
1393{
1394 <LEFTDBLBRACE>
1395 ( type = TypeExpr() )
1396 <RIGHTDBLBRACE>
1397 {
1398 return new UnorderedListTypeDefinition(type);
1399 }
1400}
1401
1402FunctionName FunctionName() throws ParseException:
1403{
1404 String first = null;
1405 String second = null;
1406 String third = null;
1407 boolean secondAfterDot = false;
1408}
1409{
Michael Blowd6cf6412016-06-30 02:44:35 -04001410 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001411 {
1412 FunctionName result = new FunctionName();
1413 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001414 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001415 ( <DOT> second = Identifier()
1416 {
1417 secondAfterDot = true;
1418 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001419 ( <SYMBOLHASH> third = Identifier())? | <SYMBOLHASH> second = Identifier() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001420 {
1421 if (second == null) {
1422 result.dataverse = defaultDataverse;
1423 result.library = null;
1424 result.function = first;
1425 } else if (third == null) {
1426 if (secondAfterDot) {
1427 result.dataverse = first;
1428 result.library = null;
1429 result.function = second;
1430 } else {
1431 result.dataverse = defaultDataverse;
1432 result.library = first;
1433 result.function = second;
1434 }
1435 } else {
1436 result.dataverse = first;
1437 result.library = second;
1438 result.function = third;
1439 }
1440
1441 if (result.function.equalsIgnoreCase("int")) {
1442 result.function = "int64";
1443 }
1444 return result;
1445 }
1446}
1447
1448
1449Pair<Identifier,Identifier> TypeName() throws ParseException:
1450{
1451 Pair<Identifier,Identifier> name = null;
1452}
1453{
1454 name = QualifiedName()
1455 {
1456 if (name.first == null) {
1457 name.first = new Identifier(defaultDataverse);
1458 }
1459 return name;
1460 }
1461}
1462
1463String Identifier() throws ParseException:
1464{
1465 String lit = null;
1466}
1467{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001468 ((<IDENTIFIER>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001469 {
1470 return token.image;
1471 }
1472 | lit = StringLiteral()
1473 {
1474 return lit;
1475 }
1476 )
1477}
1478
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001479Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001480{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001481 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001482 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001483}
1484{
1485 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001486 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001487 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001488 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1489 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001490 }
1491}
1492
Yingyi Buc9bfe252016-03-01 00:02:40 -08001493Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001494{
1495 List<String> exprList = new ArrayList<String>();
1496 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001497 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001498}
1499{
1500 lit = Identifier()
1501 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001502 boolean meetParens = false;
1503 }
1504 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001505 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001506 <LEFTPAREN><RIGHTPAREN>
1507 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001508 if(!lit.equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001509 throw new ParseException("The string before () has to be \"meta\".");
1510 }
1511 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001512 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001513 }
1514 )?
1515 {
1516 if(!meetParens){
1517 exprList.add(lit);
1518 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001519 }
1520 (<DOT>
1521 lit = Identifier()
1522 {
1523 exprList.add(lit);
1524 }
1525 )*
1526 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001527 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001528 }
1529}
1530
1531
1532
1533String StringLiteral() throws ParseException:
1534{
1535}
1536{
1537 <STRING_LITERAL>
1538 {
1539 return removeQuotesAndEscapes(token.image);
1540 }
1541}
1542
1543Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1544{
1545 String first = null;
1546 String second = null;
1547}
1548{
1549 first = Identifier() (<DOT> second = Identifier())?
1550 {
1551 Identifier id1 = null;
1552 Identifier id2 = null;
1553 if (second == null) {
1554 id2 = new Identifier(first);
1555 } else
1556 {
1557 id1 = new Identifier(first);
1558 id2 = new Identifier(second);
1559 }
1560 return new Pair<Identifier,Identifier>(id1, id2);
1561 }
1562}
1563
1564Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1565{
1566 String first = null;
1567 String second = null;
1568 String third = null;
1569}
1570{
1571 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1572 {
1573 Identifier id1 = null;
1574 Identifier id2 = null;
1575 Identifier id3 = null;
1576 if (third == null) {
1577 id2 = new Identifier(first);
1578 id3 = new Identifier(second);
1579 } else {
1580 id1 = new Identifier(first);
1581 id2 = new Identifier(second);
1582 id3 = new Identifier(third);
1583 }
1584 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1585 }
1586}
1587
1588FunctionDecl FunctionDeclaration() throws ParseException:
1589{
1590 FunctionDecl funcDecl;
1591 FunctionSignature signature;
1592 String functionName;
1593 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1594 Expression funcBody;
1595 createNewScope();
1596}
1597{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001598 <DECLARE> <FUNCTION> functionName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001599 paramList = ParameterList()
1600 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1601 {
1602 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1603 getCurrentScope().addFunctionDescriptor(signature, false);
1604 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1605 removeCurrentScope();
1606 return funcDecl;
1607 }
1608}
1609
1610
1611Query Query() throws ParseException:
1612{
Till Westmannef3f0272016-07-27 18:34:01 -07001613 Query query = new Query(false);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001614 Expression expr;
1615}
1616{
1617 expr = Expression()
1618 {
1619 query.setBody(expr);
1620 query.setVarCounter(getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001621 return query;
1622 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001623}
1624
1625
1626
1627Expression Expression():
1628{
1629 Expression expr = null;
1630 Expression exprP = null;
1631}
1632{
1633(
1634
1635//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1636 expr = OperatorExpr()
1637 | expr = IfThenElse()
1638 | expr = FLWOGR()
1639 | expr = QuantifiedExpression()
1640
1641
1642)
1643 {
1644 return (exprP==null) ? expr : exprP;
1645 }
1646}
1647
1648
1649
1650Expression OperatorExpr()throws ParseException:
1651{
1652 OperatorExpr op = null;
1653 Expression operand = null;
1654}
1655{
1656 operand = AndExpr()
1657 (
1658
1659 <OR>
1660 {
1661 if (op == null) {
1662 op = new OperatorExpr();
1663 op.addOperand(operand);
1664 op.setCurrentop(true);
1665 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001666 try{
1667 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001668 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001669 throw new ParseException(e.getMessage());
1670 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001671 }
1672
1673 operand = AndExpr()
1674 {
1675 op.addOperand(operand);
1676 }
1677
1678 )*
1679
1680 {
1681 return op==null? operand: op;
1682 }
1683}
1684
1685Expression AndExpr()throws ParseException:
1686{
1687 OperatorExpr op = null;
1688 Expression operand = null;
1689}
1690{
1691 operand = RelExpr()
1692 (
1693
1694 <AND>
1695 {
1696 if (op == null) {
1697 op = new OperatorExpr();
1698 op.addOperand(operand);
1699 op.setCurrentop(true);
1700 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001701 try{
1702 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001703 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001704 throw new ParseException(e.getMessage());
1705 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001706 }
1707
1708 operand = RelExpr()
1709 {
1710 op.addOperand(operand);
1711 }
1712
1713 )*
1714
1715 {
1716 return op==null? operand: op;
1717 }
1718}
1719
1720
1721
1722Expression RelExpr()throws ParseException:
1723{
1724 OperatorExpr op = null;
1725 Expression operand = null;
1726 boolean broadcast = false;
1727 IExpressionAnnotation annotation = null;
1728}
1729{
1730 operand = AddExpr()
1731 {
1732 if (operand instanceof VariableExpr) {
1733 String hint = getHint(token);
1734 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1735 broadcast = true;
1736 }
1737 }
1738 }
1739
1740 (
1741 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1742 {
1743 String mhint = getHint(token);
1744 if (mhint != null) {
1745 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1746 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1747 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1748 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1749 }
1750 }
1751 if (op == null) {
1752 op = new OperatorExpr();
1753 op.addOperand(operand, broadcast);
1754 op.setCurrentop(true);
1755 broadcast = false;
1756 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001757 try{
1758 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001759 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001760 throw new ParseException(e.getMessage());
1761 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001762 }
1763
1764 operand = AddExpr()
1765 {
1766 broadcast = false;
1767 if (operand instanceof VariableExpr) {
1768 String hint = getHint(token);
1769 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1770 broadcast = true;
1771 }
1772 }
1773 op.addOperand(operand, broadcast);
1774 }
1775 )?
1776
1777 {
1778 if (annotation != null) {
1779 op.addHint(annotation);
1780 }
1781 return op==null? operand: op;
1782 }
1783}
1784
1785Expression AddExpr()throws ParseException:
1786{
1787 OperatorExpr op = null;
1788 Expression operand = null;
1789}
1790{
1791 operand = MultExpr()
1792
1793 ( (<PLUS> | <MINUS>)
1794 {
1795 if (op == null) {
1796 op = new OperatorExpr();
1797 op.addOperand(operand);
1798 op.setCurrentop(true);
1799 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001800 try{
1801 ((OperatorExpr)op).addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001802 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001803 throw new ParseException(e.getMessage());
1804 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001805 }
1806
1807 operand = MultExpr()
1808 {
1809 op.addOperand(operand);
1810 }
1811 )*
1812
1813 {
1814 return op==null? operand: op;
1815 }
1816}
1817
1818Expression MultExpr()throws ParseException:
1819{
1820 OperatorExpr op = null;
1821 Expression operand = null;
1822}
1823{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001824 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001825
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001826 (( <MUL> | <DIV> | <MOD> | <IDIV>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001827 {
1828 if (op == null) {
1829 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001830 op.addOperand(operand);
1831 op.setCurrentop(true);
1832 }
1833 try{
1834 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001835 } catch (CompilationException e){
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001836 throw new ParseException(e.getMessage());
1837 }
1838 }
1839 operand = ExponentExpr()
1840 {
1841 op.addOperand(operand);
1842 }
1843 )*
1844
1845 {
1846 return op==null?operand:op;
1847 }
1848}
1849
1850Expression ExponentExpr()throws ParseException:
1851{
1852 OperatorExpr op = null;
1853 Expression operand = null;
1854}
1855{
1856 operand = UnionExpr()
1857
1858 ( <CARET>
1859 {
1860 if (op == null) {
1861 op = new OperatorExpr();
1862 op.addOperand(operand);
1863 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001864 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001865 try{
1866 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001867 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001868 throw new ParseException(e.getMessage());
1869 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001870 }
1871 operand = UnionExpr()
1872 {
1873 op.addOperand(operand);
1874 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001875 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001876
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001877 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001878 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001879 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001880}
1881
1882Expression UnionExpr() throws ParseException:
1883{
1884 UnionExpr union = null;
1885 Expression operand1 = null;
1886 Expression operand2 = null;
1887}
1888{
1889 operand1 = UnaryExpr()
1890 (<UNION>
1891 (operand2 = UnaryExpr()) {
1892 if (union == null) {
1893 union = new UnionExpr();
1894 union.addExpr(operand1);
1895 }
1896 union.addExpr(operand2);
1897 } )*
1898 {
1899 return (union == null)? operand1: union;
1900 }
1901}
1902
1903Expression UnaryExpr() throws ParseException:
1904{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001905 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001906 Expression expr = null;
1907}
1908{
1909 ( (<PLUS> | <MINUS>)
1910 {
1911 uexpr = new UnaryExpr();
Yingyi Bu196db5d2016-07-15 19:07:20 -07001912 try{
1913 uexpr.setExprType(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001914 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001915 throw new ParseException(e.getMessage());
1916 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001917 }
1918 )?
1919
1920 expr = ValueExpr()
1921 {
1922 if(uexpr!=null){
1923 ((UnaryExpr)uexpr).setExpr(expr);
1924 return uexpr;
1925 }
1926 else{
1927 return expr;
1928 }
1929 }
1930}
1931
1932Expression ValueExpr()throws ParseException:
1933{
1934 Expression expr = null;
1935 Identifier ident = null;
1936 AbstractAccessor fa = null;
1937 Expression indexExpr = null;
1938}
1939{
1940 expr = PrimaryExpr() ( ident = Field()
1941 {
1942 fa = (fa == null ? new FieldAccessor(expr, ident)
1943 : new FieldAccessor(fa, ident));
1944 }
1945 | indexExpr = Index()
1946 {
1947 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1948 : new IndexAccessor(fa, indexExpr));
1949 }
1950 )*
1951 {
1952 return fa == null ? expr : fa;
1953 }
1954}
1955
1956Identifier Field() throws ParseException:
1957{
1958 String ident = null;
1959}
1960{
1961 <DOT> ident = Identifier()
1962 {
1963 return new Identifier(ident);
1964 }
1965}
1966
1967Expression Index() throws ParseException:
1968{
1969 Expression expr = null;
1970}
1971{
1972 <LEFTBRACKET> ( expr = Expression()
1973 {
1974 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1975 {
1976 Literal lit = ((LiteralExpr)expr).getValue();
1977 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1978 lit.getLiteralType() != Literal.Type.LONG) {
1979 throw new ParseException("Index should be an INTEGER");
1980 }
1981 }
1982 }
1983
1984 | <QUES> // ANY
1985
1986 )
1987
1988 <RIGHTBRACKET>
1989 {
1990 return expr;
1991 }
1992}
1993
1994
1995Expression PrimaryExpr()throws ParseException:
1996{
1997 Expression expr = null;
1998}
1999{
2000 ( LOOKAHEAD(2)
2001 expr = FunctionCallExpr()
2002 | expr = Literal()
2003 | expr = DatasetAccessExpression()
2004 | expr = VariableRef()
2005 {
2006 if(((VariableExpr)expr).getIsNewVar() == true)
2007 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
2008 }
2009 | expr = ListConstructor()
2010 | expr = RecordConstructor()
2011 | expr = ParenthesizedExpression()
2012 )
2013 {
2014 return expr;
2015 }
2016}
2017
2018Expression Literal() throws ParseException:
2019{
2020 LiteralExpr lit = new LiteralExpr();
2021 String str = null;
2022}
2023{
2024 ( str = StringLiteral()
2025 {
2026 lit.setValue(new StringLiteral(str));
2027 }
2028 | <INTEGER_LITERAL>
2029 {
2030 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
2031 }
2032 | <FLOAT_LITERAL>
2033 {
2034 lit.setValue(new FloatLiteral(new Float(token.image)));
2035 }
2036 | <DOUBLE_LITERAL>
2037 {
2038 lit.setValue(new DoubleLiteral(new Double(token.image)));
2039 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002040 | <MISSING>
2041 {
2042 lit.setValue(MissingLiteral.INSTANCE);
2043 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002044 | <NULL>
2045 {
2046 lit.setValue(NullLiteral.INSTANCE);
2047 }
2048 | <TRUE>
2049 {
2050 lit.setValue(TrueLiteral.INSTANCE);
2051 }
2052 | <FALSE>
2053 {
2054 lit.setValue(FalseLiteral.INSTANCE);
2055 }
2056 )
2057 {
2058 return lit;
2059 }
2060}
2061
2062
2063VariableExpr VariableRef() throws ParseException:
2064{
2065 VariableExpr varExp = new VariableExpr();
2066 VarIdentifier var = new VarIdentifier();
2067}
2068{
2069 <VARIABLE>
2070 {
2071 String varName = token.image;
2072 Identifier ident = lookupSymbol(varName);
2073 if (isInForbiddenScopes(varName)) {
2074 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.");
2075 }
2076 if(ident != null) { // exist such ident
2077 varExp.setIsNewVar(false);
2078 varExp.setVar((VarIdentifier)ident);
2079 } else {
2080 varExp.setVar(var);
2081 }
2082 var.setValue(varName);
2083 return varExp;
2084 }
2085}
2086
2087
2088VariableExpr Variable() throws ParseException:
2089{
2090 VariableExpr varExp = new VariableExpr();
2091 VarIdentifier var = new VarIdentifier();
2092}
2093{
2094 <VARIABLE>
2095 {
2096 Identifier ident = lookupSymbol(token.image);
2097 if(ident != null) { // exist such ident
2098 varExp.setIsNewVar(false);
2099 }
2100 varExp.setVar(var);
2101 var.setValue(token.image);
2102 return varExp;
2103 }
2104}
2105
2106Expression ListConstructor() throws ParseException:
2107{
2108 Expression expr = null;
2109}
2110{
2111 (
2112 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2113 )
2114
2115 {
2116 return expr;
2117 }
2118}
2119
2120
2121ListConstructor OrderedListConstructor() throws ParseException:
2122{
2123 ListConstructor expr = new ListConstructor();
2124 List<Expression> exprList = null;
2125 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2126}
2127{
2128 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2129 {
2130 expr.setExprList(exprList);
2131 return expr;
2132 }
2133}
2134
2135ListConstructor UnorderedListConstructor() throws ParseException:
2136{
2137 ListConstructor expr = new ListConstructor();
2138 List<Expression> exprList = null;
2139 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2140}
2141{
2142 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2143 {
2144 expr.setExprList(exprList);
2145 return expr;
2146 }
2147}
2148
2149List<Expression> ExpressionList() throws ParseException:
2150{
2151 Expression expr = null;
2152 List<Expression> list = null;
2153 List<Expression> exprList = new ArrayList<Expression>();
2154}
2155{
2156 (
2157 expr = Expression() { exprList.add(expr); }
2158 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2159 )?
2160 (LOOKAHEAD(1) Comma())?
2161 {
2162 return exprList;
2163 }
2164}
2165
2166void Comma():
2167{}
2168{
2169 <COMMA>
2170}
2171
2172RecordConstructor RecordConstructor() throws ParseException:
2173{
2174 RecordConstructor expr = new RecordConstructor();
2175 FieldBinding tmp = null;
2176 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2177}
2178{
2179 <LEFTBRACE> (tmp = FieldBinding()
2180 {
2181 fbList.add(tmp);
2182 }
2183 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2184 {
2185 expr.setFbList(fbList);
2186 return expr;
2187 }
2188}
2189
2190FieldBinding FieldBinding() throws ParseException:
2191{
2192 FieldBinding fb = new FieldBinding();
2193 Expression left, right;
2194}
2195{
2196 left = Expression() <COLON> right = Expression()
2197 {
2198 fb.setLeftExpr(left);
2199 fb.setRightExpr(right);
2200 return fb;
2201 }
2202}
2203
2204
2205Expression FunctionCallExpr() throws ParseException:
2206{
2207 CallExpr callExpr;
2208 List<Expression> argList = new ArrayList<Expression>();
2209 Expression tmp;
2210 int arity = 0;
2211 FunctionName funcName = null;
2212 String hint = null;
2213}
2214{
2215 funcName = FunctionName()
2216 {
2217 hint = funcName.hint;
2218 }
2219 <LEFTPAREN> (tmp = Expression()
2220 {
2221 argList.add(tmp);
2222 arity ++;
2223 }
2224 (<COMMA> tmp = Expression()
2225 {
2226 argList.add(tmp);
2227 arity++;
2228 }
2229 )*)? <RIGHTPAREN>
2230 {
2231 // TODO use funcName.library
2232 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2233 FunctionSignature signature
2234 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2235 if (signature == null) {
2236 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2237 }
2238 callExpr = new CallExpr(signature,argList);
2239 if (hint != null) {
2240 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2241 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2242 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2243 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2244 }
2245 }
2246 return callExpr;
2247 }
2248}
2249
2250
2251Expression DatasetAccessExpression() throws ParseException:
2252{
2253 String funcName;
2254 String arg1 = null;
2255 String arg2 = null;
2256 Expression nameArg;
2257}
2258{
2259 <DATASET>
2260 {
2261 funcName = token.image;
2262 }
2263 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
2264 {
2265 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
2266 LiteralExpr ds = new LiteralExpr();
2267 ds.setValue( new StringLiteral(name) );
2268 nameArg = ds;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002269 }
2270 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
2271 {
2272 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2273 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2274 if (signature == null) {
2275 signature = new FunctionSignature(dataverse, funcName, 1);
2276 }
2277 List<Expression> argList = new ArrayList<Expression>();
2278 argList.add(nameArg);
2279 return new CallExpr(signature, argList);
2280 }
2281}
2282
2283Expression ParenthesizedExpression() throws ParseException:
2284{
2285 Expression expr;
2286}
2287{
2288 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2289 {
2290 return expr;
2291 }
2292}
2293
2294Expression IfThenElse() throws ParseException:
2295{
2296 Expression condExpr;
2297 Expression thenExpr;
2298 Expression elseExpr;
2299 IfExpr ifExpr = new IfExpr();
2300}
2301{
2302 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2303
2304 {
2305 ifExpr.setCondExpr(condExpr);
2306 ifExpr.setThenExpr(thenExpr);
2307 ifExpr.setElseExpr(elseExpr);
2308 return ifExpr;
2309 }
2310}
2311
Taewoo Kim92c0bac2017-02-11 16:38:44 -08002312// Note: if you modify this part: "tmp = LetClause() {clauseList.add(tmp);}", please also apply the necessary
2313// change to the AQLPlusExtension.jj file since it refers to this string part and may behave incorrectly if this
2314// part is modified. For more details, please refer to AQLPlusExtension.jj file.
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002315Expression FLWOGR() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002316{
2317 FLWOGRExpression flworg = new FLWOGRExpression();
2318 List<Clause> clauseList = new ArrayList<Clause>();
2319 Expression returnExpr;
2320 Clause tmp;
2321 createNewScope();
2322}
2323{
2324 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2325 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
2326
2327 {
2328 flworg.setClauseList(clauseList);
2329 flworg.setReturnExpr(returnExpr);
2330 removeCurrentScope();
2331 return flworg;
2332 }
2333}
2334
2335Clause Clause()throws ParseException :
2336{
2337 Clause clause;
2338}
2339{
2340 (
2341 clause = ForClause()
2342 | clause = LetClause()
2343 | clause = WhereClause()
2344 | clause = OrderbyClause()
2345 | clause = GroupClause()
2346 | clause = LimitClause()
2347 | clause = DistinctClause()
2348 )
2349 {
2350 return clause;
2351 }
2352}
2353
2354Clause ForClause()throws ParseException :
2355{
2356 ForClause fc = new ForClause();
2357 VariableExpr varExp;
2358 VariableExpr varPos = null;
2359 Expression inExp;
2360 extendCurrentScope();
2361}
2362{
2363 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
2364 {
2365 fc.setVarExpr(varExp);
2366 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2367 fc.setInExpr(inExp);
2368 if (varPos != null) {
2369 fc.setPosExpr(varPos);
2370 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2371 }
2372 return fc;
2373 }
2374}
2375
2376Clause LetClause() throws ParseException:
2377{
2378 LetClause lc = new LetClause();
2379 VariableExpr varExp;
2380 Expression beExp;
2381 extendCurrentScope();
2382}
2383{
2384 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
2385 {
2386 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2387 lc.setVarExpr(varExp);
2388 lc.setBindingExpr(beExp);
2389 return lc;
2390 }
2391}
2392
2393Clause WhereClause()throws ParseException :
2394{
2395 WhereClause wc = new WhereClause();
2396 Expression whereExpr;
2397}
2398{
2399 <WHERE> whereExpr = Expression()
2400 {
2401 wc.setWhereExpr(whereExpr);
2402 return wc;
2403 }
2404}
2405
2406Clause OrderbyClause()throws ParseException :
2407{
2408 OrderbyClause oc = new OrderbyClause();
2409 Expression orderbyExpr;
2410 List<Expression> orderbyList = new ArrayList<Expression>();
2411 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2412 int numOfOrderby = 0;
2413}
2414{
2415 (
2416 <ORDER>
2417 {
2418 String hint = getHint(token);
2419 if (hint != null) {
2420 if (hint.startsWith(INMEMORY_HINT)) {
2421 String splits[] = hint.split(" +");
2422 int numFrames = Integer.parseInt(splits[1]);
2423 int numTuples = Integer.parseInt(splits[2]);
2424 oc.setNumFrames(numFrames);
2425 oc.setNumTuples(numTuples);
2426 }
2427 if (hint.startsWith(RANGE_HINT)) {
2428 try{
2429 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002430 } catch (CompilationException e) {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002431 throw new ParseException(e.getMessage());
2432 }
2433 }
2434 }
2435 }
2436 <BY> orderbyExpr = Expression()
2437 {
2438 orderbyList.add(orderbyExpr);
2439 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2440 }
2441 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2442 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2443 {
2444 modifierList.add(modif);
2445 }
2446
2447 (<COMMA> orderbyExpr = Expression()
2448 {
2449 orderbyList.add(orderbyExpr);
2450 modif = OrderbyClause.OrderModifier.ASC;
2451 }
2452 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2453 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2454 {
2455 modifierList.add(modif);
2456 }
2457 )*
2458)
2459 {
2460 oc.setModifierList(modifierList);
2461 oc.setOrderbyList(orderbyList);
2462 return oc;
2463 }
2464}
2465Clause GroupClause()throws ParseException :
2466{
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002467 GroupbyClause gbc = new GroupbyClause();
2468 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2469 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002470 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002471 Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002472 VariableExpr var = null;
2473 VariableExpr withVar = null;
2474 Expression expr = null;
2475 VariableExpr decorVar = null;
2476 Expression decorExpr = null;
2477}
2478{
2479 {
2480 Scope newScope = extendCurrentScopeNoPush(true);
2481 // extendCurrentScope(true);
2482 }
2483 <GROUP>
2484 {
2485 String hint = getHint(token);
2486 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2487 gbc.setHashGroupByHint(true);
2488 }
2489 }
2490 <BY> (LOOKAHEAD(2) var = Variable()
2491 {
2492 newScope.addNewVarSymbolToScope(var.getVar());
2493 } <ASSIGN>)?
2494 expr = Expression()
2495 {
2496 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2497 vePairList.add(pair1);
2498 }
2499 (<COMMA> ( LOOKAHEAD(2) var = Variable()
2500 {
2501 newScope.addNewVarSymbolToScope(var.getVar());
2502 } <ASSIGN>)?
2503 expr = Expression()
2504 {
2505 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2506 vePairList.add(pair2);
2507 }
2508 )*
2509 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2510 {
2511 newScope.addNewVarSymbolToScope(decorVar.getVar());
2512 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2513 decorPairList.add(pair3);
2514 }
2515 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2516 {
2517 newScope.addNewVarSymbolToScope(decorVar.getVar());
2518 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2519 decorPairList.add(pair4);
2520 }
2521 )*
2522 )?
2523 (<WITH>|<KEEPING>) withVar = VariableRef()
2524 {
2525 if(withVar.getIsNewVar()==true)
2526 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002527 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002528 newScope.addNewVarSymbolToScope(withVar.getVar());
2529 }
2530 (<COMMA> withVar = VariableRef()
2531 {
2532 if(withVar.getIsNewVar()==true)
2533 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002534 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002535 newScope.addNewVarSymbolToScope(withVar.getVar());
2536 })*
2537 {
2538 gbc.setGbyPairList(vePairList);
2539 gbc.setDecorPairList(decorPairList);
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002540 gbc.setWithVarMap(withVarMap);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002541 replaceCurrentScope(newScope);
2542 return gbc;
2543 }
2544}
2545
2546
2547LimitClause LimitClause() throws ParseException:
2548{
2549 LimitClause lc = new LimitClause();
2550 Expression expr;
2551 pushForbiddenScope(getCurrentScope());
2552}
2553{
2554 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2555 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2556
2557 {
2558 popForbiddenScope();
2559 return lc;
2560 }
2561}
2562
2563DistinctClause DistinctClause() throws ParseException:
2564{
2565 List<Expression> exprs = new ArrayList<Expression>();
2566 Expression expr;
2567}
2568{
2569 <DISTINCT> <BY> expr = Expression()
2570 {
2571 exprs.add(expr);
2572 }
2573 (<COMMA> expr = Expression()
2574 {
2575 exprs.add(expr);
2576 }
2577 )*
2578 {
2579 return new DistinctClause(exprs);
2580 }
2581}
2582
2583QuantifiedExpression QuantifiedExpression()throws ParseException:
2584{
2585 QuantifiedExpression qc = new QuantifiedExpression();
2586 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2587 Expression satisfiesExpr;
2588 VariableExpr var;
2589 Expression inExpr;
2590 QuantifiedPair pair;
2591}
2592{
2593 {
2594 createNewScope();
2595 }
2596
Michael Blowd6cf6412016-06-30 02:44:35 -04002597 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2598 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07002599 var = Variable() <IN> inExpr = Expression()
2600 {
2601 pair = new QuantifiedPair(var, inExpr);
2602 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2603 quantifiedList.add(pair);
2604 }
2605 (
2606 <COMMA> var = Variable() <IN> inExpr = Expression()
2607 {
2608 pair = new QuantifiedPair(var, inExpr);
2609 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2610 quantifiedList.add(pair);
2611 }
2612 )*
2613 <SATISFIES> satisfiesExpr = Expression()
2614 {
2615 qc.setSatisfiesExpr(satisfiesExpr);
2616 qc.setQuantifiedList(quantifiedList);
2617 removeCurrentScope();
2618 return qc;
2619 }
2620}
2621
2622TOKEN_MGR_DECLS:
2623{
2624 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07002625 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002626
2627 public void pushState() {
2628 lexerStateStack.push( curLexState );
2629 }
2630
2631 public void popState(String token) {
2632 if (lexerStateStack.size() > 0) {
2633 SwitchTo( lexerStateStack.pop() );
2634 } else {
2635 int errorLine = input_stream.getEndLine();
2636 int errorColumn = input_stream.getEndColumn();
2637 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2638 + "\" but state stack is empty.";
2639 throw new TokenMgrError(msg, -1);
2640 }
2641 }
2642}
2643
2644<DEFAULT,IN_DBL_BRACE>
2645TOKEN :
2646{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002647 <APPLY : "apply">
2648 | <AS : "as">
2649 | <ASC : "asc">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002650 | <AT : "at">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002651 | <AUTOGENERATED : "autogenerated">
2652 | <BTREE : "btree">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002653 | <BY : "by">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002654 | <CLOSED : "closed">
2655 | <COMPACT : "compact">
2656 | <COMPACTION : "compaction">
2657 | <CONNECT : "connect">
2658 | <CREATE : "create">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002659 | <DATASET : "dataset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002660 | <DATAVERSE : "dataverse">
2661 | <DECLARE : "declare">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002662 | <DECOR : "decor">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002663 | <DEFINITION : "definition">
2664 | <DELETE : "delete">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002665 | <DESC : "desc">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002666 | <DISCONNECT : "disconnect">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002667 | <DISTINCT : "distinct">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002668 | <DROP : "drop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002669 | <ELSE : "else">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002670 | <ENFORCED : "enforced">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002671 | <EVERY : "every">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002672 | <EXISTS : "exists">
2673 | <EXTERNAL : "external">
2674 | <FEED : "feed">
2675 | <FILTER : "filter">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002676 | <FOR : "for">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002677 | <FORMAT : "format">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002678 | <FROM : "from">
Taewoo Kimc49405a2017-01-04 00:30:43 -08002679 | <FULLTEXT : "fulltext">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002680 | <FUNCTION : "function">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002681 | <GROUP : "group">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002682 | <HINTS : "hints">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002683 | <IF : "if">
2684 | <IN : "in">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002685 | <INDEX : "index">
2686 | <INGESTION : "ingestion">
2687 | <INSERT : "insert">
2688 | <INTERNAL : "internal">
2689 | <INTO : "into">
2690 | <KEY : "key">
2691 | <KEYWORD : "keyword">
2692 | <KEEPING : "keeping">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002693 | <LET : "let">
2694 | <LIMIT : "limit">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002695 | <LOAD : "load">
2696 | <NGRAM : "ngram">
2697 | <NODEGROUP : "nodegroup">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002698 | <OFFSET : "offset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002699 | <ON : "on">
2700 | <OPEN : "open">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002701 | <ORDER : "order">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002702 | <OUTPUT : "output">
2703 | <PATH : "path">
2704 | <POLICY : "policy">
2705 | <PRESORTED : "pre-sorted">
2706 | <PRIMARY : "primary">
2707 | <REFRESH : "refresh">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002708 | <RETURN : "return">
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -07002709 | <RETURNING : "returning">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002710 | <RTREE : "rtree">
2711 | <RUN : "run">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002712 | <SATISFIES : "satisfies">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002713 | <SECONDARY : "secondary">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002714 | <SELECT : "select">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002715 | <SET : "set">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08002716 | <START: "start">
2717 | <STOP: "stop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002718 | <SOME : "some">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002719 | <TEMPORARY : "temporary">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002720 | <THEN : "then">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002721 | <TO : "to">
2722 | <TYPE : "type">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002723 | <UNION : "union">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002724 | <UPDATE : "update">
2725 | <UPSERT : "upsert">
2726 | <USE : "use">
2727 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002728 | <WHERE : "where">
2729 | <WITH : "with">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002730 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002731}
2732
2733<DEFAULT,IN_DBL_BRACE>
2734TOKEN :
2735{
2736 <CARET : "^">
2737 | <DIV : "/">
2738 | <IDIV : "idiv">
2739 | <MINUS : "-">
2740 | <MOD : "%">
2741 | <MUL : "*">
2742 | <PLUS : "+">
2743
2744 | <LEFTPAREN : "(">
2745 | <RIGHTPAREN : ")">
2746 | <LEFTBRACKET : "[">
2747 | <RIGHTBRACKET : "]">
2748
2749 | <COLON : ":">
2750 | <COMMA : ",">
2751 | <DOT : ".">
2752 | <QUES : "?">
2753
2754 | <LT : "<">
2755 | <GT : ">">
2756 | <LE : "<=">
2757 | <GE : ">=">
2758 | <EQ : "=">
2759 | <NE : "!=">
2760 | <SIMILAR : "~=">
2761 | <ASSIGN : ":=">
2762
2763 | <AND : "and">
2764 | <OR : "or">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002765
2766 | <SYMBOLAT : "@">
2767 | <SYMBOLHASH : "#">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002768}
2769
2770<DEFAULT,IN_DBL_BRACE>
2771TOKEN :
2772{
2773 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2774}
2775
2776<DEFAULT>
2777TOKEN :
2778{
2779 <RIGHTBRACE : "}"> { popState("}"); }
2780}
2781
2782<DEFAULT,IN_DBL_BRACE>
2783TOKEN :
2784{
2785 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2786}
2787
2788<IN_DBL_BRACE>
2789TOKEN :
2790{
2791 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2792}
2793
2794<DEFAULT,IN_DBL_BRACE>
2795TOKEN :
2796{
2797 <INTEGER_LITERAL : (<DIGIT>)+ >
2798}
2799
2800<DEFAULT,IN_DBL_BRACE>
2801TOKEN :
2802{
Yingyi Bu535d86b2016-05-23 16:44:25 -07002803 < MISSING : "missing">
2804 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002805 | <TRUE : "true">
2806 | <FALSE : "false">
2807}
2808
2809<DEFAULT,IN_DBL_BRACE>
2810TOKEN :
2811{
2812 <#DIGIT : ["0" - "9"]>
2813}
2814
2815<DEFAULT,IN_DBL_BRACE>
2816TOKEN:
2817{
Yingyi Bu144453b2017-05-24 14:34:46 -07002818 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("-")? <DIGITS>)?
2819 | <DIGITS> (("e"|"E") ("-")? <DIGITS>)
2820 | "." <DIGITS> (("e"|"E") ("-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002821 >
2822 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2823 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2824 | "." <DIGITS> ( "f" | "F" )
2825 >
2826 | <DIGITS : (<DIGIT>)+ >
2827}
2828
2829<DEFAULT,IN_DBL_BRACE>
2830TOKEN :
2831{
2832 <#LETTER : ["A" - "Z", "a" - "z"]>
2833 | <SPECIALCHARS : ["$", "_", "-"]>
2834}
2835
2836<DEFAULT,IN_DBL_BRACE>
2837TOKEN :
2838{
2839 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2840 <STRING_LITERAL : ("\"" (
2841 <EscapeQuot>
2842 | <EscapeBslash>
2843 | <EscapeSlash>
2844 | <EscapeBspace>
2845 | <EscapeFormf>
2846 | <EscapeNl>
2847 | <EscapeCr>
2848 | <EscapeTab>
2849 | ~["\"","\\"])* "\"")
2850 | ("\'"(
2851 <EscapeApos>
2852 | <EscapeBslash>
2853 | <EscapeSlash>
2854 | <EscapeBspace>
2855 | <EscapeFormf>
2856 | <EscapeNl>
2857 | <EscapeCr>
2858 | <EscapeTab>
2859 | ~["\'","\\"])* "\'")>
2860 | < #EscapeQuot: "\\\"" >
2861 | < #EscapeApos: "\\\'" >
2862 | < #EscapeBslash: "\\\\" >
2863 | < #EscapeSlash: "\\/" >
2864 | < #EscapeBspace: "\\b" >
2865 | < #EscapeFormf: "\\f" >
2866 | < #EscapeNl: "\\n" >
2867 | < #EscapeCr: "\\r" >
2868 | < #EscapeTab: "\\t" >
2869}
2870
2871<DEFAULT,IN_DBL_BRACE>
2872TOKEN :
2873{
2874 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2875}
2876
2877<DEFAULT,IN_DBL_BRACE>
2878TOKEN :
2879{
2880 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
2881}
2882
2883<DEFAULT,IN_DBL_BRACE>
2884SKIP:
2885{
2886 " "
2887 | "\t"
2888 | "\r"
2889 | "\n"
2890}
2891
2892<DEFAULT,IN_DBL_BRACE>
2893SKIP:
2894{
2895 <"//" (~["\n"])* "\n">
2896}
2897
2898<DEFAULT,IN_DBL_BRACE>
2899SKIP:
2900{
2901 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2902}
2903
2904<DEFAULT,IN_DBL_BRACE>
2905SKIP:
2906{
2907 <"/*"> { pushState(); } : INSIDE_COMMENT
2908}
2909
2910<INSIDE_COMMENT>
2911SPECIAL_TOKEN:
2912{
2913 <"+"(" ")*(~["*"])*>
2914}
2915
2916<INSIDE_COMMENT>
2917SKIP:
2918{
2919 <"/*"> { pushState(); }
2920}
2921
2922<INSIDE_COMMENT>
2923SKIP:
2924{
2925 <"*/"> { popState("*/"); }
2926 | <~[]>
2927}