blob: 0cc678943b1e6daf06342c81b5dfadf8786f9e50 [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;
Ali Alsuliman8351d252017-09-24 00:43:15 -0700583 boolean isPrimaryIdx = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700584}
585{
Ali Alsuliman8351d252017-09-24 00:43:15 -0700586 (
587 (<INDEX> indexName = Identifier()
588 ifNotExists = IfNotExists()
589 <ON> nameComponents = QualifiedName()
590 <LEFTPAREN> ( fieldPair = OpenField()
591 {
592 cis.addFieldExprPair(fieldPair.second);
593 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700594 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700595 ) (<COMMA> fieldPair = OpenField()
596 {
597 cis.addFieldExprPair(fieldPair.second);
598 cis.addFieldIndexIndicator(fieldPair.first);
599 }
600 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
601 |
602 (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
603 (
604 (indexName = Identifier())? ifNotExists = IfNotExists()
605 )
606 <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
607 )
608 )
609 {
610 if (isPrimaryIdx && indexName == null) {
611 indexName = "primary_idx_" + nameComponents.second;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700612 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700613 cis.setIndexName(new Identifier(indexName));
614 cis.setIfNotExists(ifNotExists);
615 cis.setDataverseName(nameComponents.first);
616 cis.setDatasetName(nameComponents.second);
617 if (indexType != null) {
618 cis.setIndexType(indexType.type);
619 cis.setGramLength(indexType.gramLength);
620 }
621 cis.setEnforced(enforced);
622 return cis;
623 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700624}
625
626String CompactionPolicy() throws ParseException :
627{
628 String compactionPolicy = null;
629}
630{
631 compactionPolicy = Identifier()
632 {
633 return compactionPolicy;
634 }
635}
636
637String FilterField() throws ParseException :
638{
639 String filterField = null;
640}
641{
642 filterField = Identifier()
643 {
644 return filterField;
645 }
646}
647
648IndexParams IndexType() throws ParseException:
649{
650 IndexType type = null;
651 int gramLength = 0;
652}
653{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400654 (
655 <BTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700656 {
657 type = IndexType.BTREE;
658 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400659 |<RTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700660 {
661 type = IndexType.RTREE;
662 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400663 |<KEYWORD>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700664 {
665 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
666 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800667 |<FULLTEXT>
668 {
669 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
670 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400671 |<NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700672 {
673 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
674 gramLength = Integer.valueOf(token.image);
675 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400676 <RIGHTPAREN>
677 )
678 {
679 return new IndexParams(type, gramLength);
680 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700681}
682
683CreateDataverseStatement DataverseSpecification() throws ParseException :
684{
685 String dvName = null;
686 boolean ifNotExists = false;
687 String format = null;
688}
689{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400690 <DATAVERSE> dvName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700691 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400692 ( <WITH> <FORMAT> format = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700693 {
694 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
695 }
696}
697
698CreateFunctionStatement FunctionSpecification() throws ParseException:
699{
700 FunctionSignature signature;
701 boolean ifNotExists = false;
702 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
703 String functionBody;
704 VarIdentifier var = null;
705 Expression functionBodyExpr;
706 Token beginPos;
707 Token endPos;
708 FunctionName fctName = null;
709
710 createNewScope();
711}
712{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400713 <FUNCTION> fctName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700714 ifNotExists = IfNotExists()
715 paramList = ParameterList()
716 <LEFTBRACE>
717 {
718 beginPos = token;
719 }
720 functionBodyExpr = Expression() <RIGHTBRACE>
721 {
722 endPos = token;
723 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
724 // TODO use fctName.library
725 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
726 getCurrentScope().addFunctionDescriptor(signature, false);
727 removeCurrentScope();
728 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
729 }
730}
731
732CreateFeedStatement FeedSpecification() throws ParseException:
733{
734 Pair<Identifier,Identifier> nameComponents = null;
735 boolean ifNotExists = false;
736 String adapterName = null;
737 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700738 CreateFeedStatement cfs = null;
739 Pair<Identifier,Identifier> sourceNameComponents = null;
Michael Blowd6cf6412016-06-30 02:44:35 -0400740
Yingyi Bu391f09e2015-10-29 13:49:39 -0700741}
742{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800743 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
744 <USING> adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400745 {
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800746 cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists);
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400747 return cfs;
748 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700749}
750
751CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
752{
Michael Blowd6cf6412016-06-30 02:44:35 -0400753 String policyName = null;
754 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700755 String sourcePolicyFile = null;
756 String definition = null;
757 boolean ifNotExists = false;
758 Map<String,String> properties = null;
759 CreateFeedPolicyStatement cfps = null;
760}
761{
762 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400763 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
764 <FROM>
765 (
766 <POLICY> basePolicyName = Identifier() properties = Configuration() ( <DEFINITION> definition = StringLiteral())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700767 {
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400768 cfps = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700769 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300770 |<PATH> sourcePolicyFile = StringLiteral() (<DEFINITION> definition = StringLiteral())?
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400771 {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700772 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400773 }
774 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700775 )
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400776 {
777 return cfps;
778 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700779}
780
781
782
783List<VarIdentifier> ParameterList() throws ParseException:
784{
785 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
786 VarIdentifier var = null;
787}
788{
789 <LEFTPAREN> (<VARIABLE>
790 {
791 var = new VarIdentifier();
792 var.setValue(token.image);
793 paramList.add(var);
794 getCurrentScope().addNewVarSymbolToScope(var);
795 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400796 ( <COMMA> <VARIABLE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700797 {
798 var = new VarIdentifier();
799 var.setValue(token.image);
800 paramList.add(var);
801 getCurrentScope().addNewVarSymbolToScope(var);
802 }
803 )*)? <RIGHTPAREN>
804 {
805 return paramList;
806 }
807}
808
809boolean IfNotExists() throws ParseException:
810{
811}
812{
Yingyi Budcd91122016-08-10 12:13:36 -0700813 (
814 LOOKAHEAD(1)
815 <IF>
816 <IDENTIFIER>
817 (
818 {
819 if(!token.image.equals("not")){
820 throw new ParseException("Expect word \"not\" at line " + token.beginLine + ", column "
821 + token.beginColumn +"!");
822 }
823 }
824 )
825 <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700826 {
827 return true;
828 }
829 )?
830 {
831 return false;
832 }
833}
834
Xikui Wang9d63f622017-05-18 17:50:44 -0700835void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700836{
837 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700838 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700839}
840{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400841 <APPLY> <FUNCTION> functioName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700842 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700843 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
844 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
845 }
846 (
847 <COMMA> functioName = FunctionName()
848 {
849 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
850 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
851 }
852 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700853}
854
855String GetPolicy() throws ParseException:
856{
857 String policy = null;
858}
859{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400860 <USING> <POLICY> policy = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700861 {
862 return policy;
863 }
864
865}
866
867FunctionSignature FunctionSignature() throws ParseException:
868{
869 FunctionName fctName = null;
870 int arity = 0;
871}
872{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400873 fctName = FunctionName() <SYMBOLAT> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700874 {
875 arity = new Integer(token.image);
876 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
877 throw new ParseException(" invalid arity:" + arity);
878 }
879
880 // TODO use fctName.library
881 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
882 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
883 }
884}
885
Yingyi Buc9bfe252016-03-01 00:02:40 -0800886Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700887{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800888 Pair<Integer, List<String>> tmp = null;
889 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
890 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700891}
892{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400893 <PRIMARY> <KEY> tmp = NestedField()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700894 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800895 keyFieldSourceIndicators.add(tmp.first);
896 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700897 }
898 ( <COMMA> tmp = NestedField()
899 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800900 keyFieldSourceIndicators.add(tmp.first);
901 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700902 }
903 )*
904 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800905 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700906 }
907}
908
909Statement DropStatement() throws ParseException:
910{
911 String id = null;
912 Pair<Identifier,Identifier> pairId = null;
913 Triple<Identifier,Identifier,Identifier> tripleId = null;
914 FunctionSignature funcSig = null;
915 boolean ifExists = false;
916 Statement stmt = null;
917}
918{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400919 <DROP>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700920 (
921 <DATASET> pairId = QualifiedName() ifExists = IfExists()
922 {
Yingyi Buab817482016-08-19 21:29:31 -0700923 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700924 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400925 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700926 {
927 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
928 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400929 | <NODEGROUP> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700930 {
931 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
932 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400933 | <TYPE> pairId = TypeName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700934 {
935 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
936 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400937 | <DATAVERSE> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700938 {
939 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
940 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400941 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700942 {
943 stmt = new FunctionDropStatement(funcSig, ifExists);
944 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400945 | <FEED> pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700946 {
947 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
948 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300949 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
950 {
951 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
952 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700953 )
954 {
955 return stmt;
956 }
957}
958
959boolean IfExists() throws ParseException :
960{
961}
962{
Yingyi Budcd91122016-08-10 12:13:36 -0700963 (
964 LOOKAHEAD(1)
965 <IF> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700966 {
967 return true;
968 }
969 )?
970 {
971 return false;
972 }
973}
974
975InsertStatement InsertStatement() throws ParseException:
976{
977 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800978 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700979 Query query;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800980 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700981}
982{
Yingyi Bucb5bf332017-01-02 22:19:50 -0800983 <INSERT> <INTO> <DATASET> nameComponents = QualifiedName()
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -0700984 (<AS> var = Variable())?
985 {
986 if(var != null){
987 getCurrentScope().addNewVarSymbolToScope(var.getVar());
988 }
989 }
Yingyi Bucb5bf332017-01-02 22:19:50 -0800990 query = Query() ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700991 {
Yingyi Bucb5bf332017-01-02 22:19:50 -0800992 checkBindingVariable(returnExpression, var, query);
Yingyi Bucaea8f02015-11-16 15:12:15 -0800993 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -0800994 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
995 returnExpression);
996 }
997}
998
999UpsertStatement UpsertStatement() throws ParseException:
1000{
1001 Pair<Identifier,Identifier> nameComponents = null;
1002 VariableExpr var = null;
1003 Query query;
1004 Expression returnExpression = null;
1005}
1006{
1007 <UPSERT> <INTO> <DATASET> nameComponents = QualifiedName()
1008 (<AS> var = Variable())?
1009 {
1010 if(var != null){
1011 getCurrentScope().addNewVarSymbolToScope(var.getVar());
1012 }
1013 }
1014 query = Query() ( <RETURNING> returnExpression = Expression())?
1015 {
1016 checkBindingVariable(returnExpression, var, query);
1017 query.setTopLevel(true);
1018 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1019 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001020 }
1021}
1022
1023DeleteStatement DeleteStatement() throws ParseException:
1024{
1025 VariableExpr var = null;
1026 Expression condition = null;
1027 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001028}
1029{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001030 <DELETE> var = Variable()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001031 {
1032 getCurrentScope().addNewVarSymbolToScope(var.getVar());
1033 }
1034 <FROM> <DATASET> nameComponents = QualifiedName()
1035 (<WHERE> condition = Expression())?
1036 {
1037 // First we get the dataverses and datasets that we want to lock
Yingyi Bu391f09e2015-10-29 13:49:39 -07001038 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001039 condition, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001040 }
1041}
1042
1043UpdateStatement UpdateStatement() throws ParseException:
1044{
1045 VariableExpr vars;
1046 Expression target;
1047 Expression condition;
1048 UpdateClause uc;
1049 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1050}
1051{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001052 <UPDATE> vars = Variable() <IN> target = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001053 <WHERE> condition = Expression()
1054 <LEFTPAREN> (uc = UpdateClause()
1055 {
1056 ucs.add(uc);
1057 }
1058 (<COMMA> uc = UpdateClause()
1059 {
1060 ucs.add(uc);
1061 }
1062 )*) <RIGHTPAREN>
1063 {
1064 return new UpdateStatement(vars, target, condition, ucs);
1065 }
1066}
1067
1068UpdateClause UpdateClause() throws ParseException:
1069{
1070 Expression target = null;
1071 Expression value = null ;
1072 InsertStatement is = null;
1073 DeleteStatement ds = null;
1074 UpdateStatement us = null;
1075 Expression condition = null;
1076 UpdateClause ifbranch = null;
1077 UpdateClause elsebranch = null;
1078}
1079{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001080 (<SET> target = Expression() <ASSIGN> value = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001081 | is = InsertStatement()
1082 | ds = DeleteStatement()
1083 | us = UpdateStatement()
1084 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1085 <THEN> ifbranch = UpdateClause()
1086 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1087 {
1088 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1089 }
1090 )
1091}
1092
1093Statement SetStatement() throws ParseException:
1094{
1095 String pn = null;
1096 String pv = null;
1097}
1098{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001099 <SET> pn = Identifier() pv = StringLiteral()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001100 {
1101 return new SetStatement(pn, pv);
1102 }
1103}
1104
1105Statement WriteStatement() throws ParseException:
1106{
1107 String nodeName = null;
1108 String fileName = null;
1109 Query query;
1110 String writerClass = null;
1111 Pair<Identifier,Identifier> nameComponents = null;
1112}
1113{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001114 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = StringLiteral()
1115 ( <USING> writerClass = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001116 {
1117 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1118 }
1119}
1120
1121LoadStatement LoadStatement() throws ParseException:
1122{
1123 Identifier dataverseName = null;
1124 Identifier datasetName = null;
1125 boolean alreadySorted = false;
1126 String adapterName;
1127 Map<String,String> properties;
1128 Pair<Identifier,Identifier> nameComponents = null;
1129}
1130{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001131 <LOAD> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001132 {
1133 dataverseName = nameComponents.first;
1134 datasetName = nameComponents.second;
1135 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001136 <USING> adapterName = AdapterName() properties = Configuration()
1137 (<PRESORTED>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001138 {
1139 alreadySorted = true;
1140 }
1141 )?
1142 {
1143 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1144 }
1145}
1146
1147
1148String AdapterName() throws ParseException :
1149{
1150 String adapterName = null;
1151}
1152{
1153 adapterName = Identifier()
1154 {
1155 return adapterName;
1156 }
1157}
1158
1159Statement CompactStatement() throws ParseException:
1160{
1161 Pair<Identifier,Identifier> nameComponents = null;
1162 Statement stmt = null;
1163}
1164{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001165 <COMPACT> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001166 {
1167 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1168 }
1169 {
1170 return stmt;
1171 }
1172}
1173
1174Statement FeedStatement() throws ParseException:
1175{
1176 Pair<Identifier,Identifier> feedNameComponents = null;
1177 Pair<Identifier,Identifier> datasetNameComponents = null;
1178
1179 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001180 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07001181 Statement stmt = null;
1182 String policy = null;
1183}
1184{
1185 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001186 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName()
Xikui Wang9d63f622017-05-18 17:50:44 -07001187 (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001188 {
Xikui Wang261dc6d2017-03-29 21:23:15 -07001189 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions, policy, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001190 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001191 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001192 {
1193 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1194 }
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001195 | <START> <FEED> feedNameComponents = QualifiedName()
1196 {
1197 stmt = new StartFeedStatement (feedNameComponents);
1198 }
1199 | <STOP> <FEED> feedNameComponents = QualifiedName()
1200 {
1201 stmt = new StopFeedStatement (feedNameComponents);
1202 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001203 )
1204 {
1205 return stmt;
1206 }
1207}
1208
1209Map<String,String> Configuration() throws ParseException :
1210{
1211 Map<String,String> configuration = new LinkedHashMap<String,String>();
1212 Pair<String, String> keyValuePair = null;
1213}
1214{
1215 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1216 {
1217 configuration.put(keyValuePair.first, keyValuePair.second);
1218 }
1219 ( <COMMA> keyValuePair = KeyValuePair()
1220 {
1221 configuration.put(keyValuePair.first, keyValuePair.second);
1222 }
1223 )* )? <RIGHTPAREN>
1224 {
1225 return configuration;
1226 }
1227}
1228
1229Pair<String, String> KeyValuePair() throws ParseException:
1230{
1231 String key;
1232 String value;
1233}
1234{
1235 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
1236 {
1237 return new Pair<String, String>(key, value);
1238 }
1239}
1240
1241Map<String,String> Properties() throws ParseException:
1242{
1243 Map<String,String> properties = new HashMap<String,String>();
1244 Pair<String, String> property;
1245}
1246{
1247 ( <LEFTPAREN> property = Property()
1248 {
1249 properties.put(property.first, property.second);
1250 }
1251 ( <COMMA> property = Property()
1252 {
1253 properties.put(property.first, property.second);
1254 }
1255 )* <RIGHTPAREN> )?
1256 {
1257 return properties;
1258 }
1259}
1260
1261Pair<String, String> Property() throws ParseException:
1262{
1263 String key;
1264 String value;
1265}
1266{
1267 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
1268 {
1269 try {
1270 value = "" + Long.valueOf(token.image);
1271 } catch (NumberFormatException nfe) {
1272 throw new ParseException("inapproriate value: " + token.image);
1273 }
1274 }
1275 )
1276 {
1277 return new Pair<String, String>(key.toUpperCase(), value);
1278 }
1279}
1280
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001281IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001282{
1283 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001284 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001285}
1286{
1287 (
1288 typeExpr = TypeReference()
1289 | typeExpr = OrderedListTypeDef()
1290 | typeExpr = UnorderedListTypeDef()
1291 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001292 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001293 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001294 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001295 }
1296}
1297
1298TypeExpression TypeExpr() throws ParseException:
1299{
1300 TypeExpression typeExpr = null;
1301}
1302{
1303 (
1304 typeExpr = RecordTypeDef()
1305 | typeExpr = TypeReference()
1306 | typeExpr = OrderedListTypeDef()
1307 | typeExpr = UnorderedListTypeDef()
1308 )
1309 {
1310 return typeExpr;
1311 }
1312}
1313
1314RecordTypeDefinition RecordTypeDef() throws ParseException:
1315{
1316 RecordTypeDefinition recType = new RecordTypeDefinition();
1317 RecordTypeDefinition.RecordKind recordKind = null;
1318}
1319{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001320 ( <CLOSED>{ recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1321 | <OPEN>{ recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001322 <LEFTBRACE>
1323 {
1324 String hint = getHint(token);
1325 if (hint != null) {
1326 String splits[] = hint.split(" +");
1327 if (splits[0].equals(GEN_FIELDS_HINT)) {
1328 if (splits.length != 5) {
1329 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1330 }
1331 if (!splits[1].equals("int")) {
1332 throw new ParseException("The only supported type for gen-fields is int.");
1333 }
1334 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1335 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1336 recType.setUndeclaredFieldsDataGen(ufdg);
1337 }
1338 }
1339
1340 }
1341 (
1342 RecordField(recType)
1343 ( <COMMA> RecordField(recType) )*
1344 )?
1345 <RIGHTBRACE>
1346 {
1347 if (recordKind == null) {
1348 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1349 }
1350 recType.setRecordKind(recordKind);
1351 return recType;
1352 }
1353}
1354
1355void RecordField(RecordTypeDefinition recType) throws ParseException:
1356{
1357 String fieldName;
1358 TypeExpression type = null;
1359 boolean nullable = false;
1360}
1361{
1362 fieldName = Identifier()
1363 {
1364 String hint = getHint(token);
1365 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1366 }
1367 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1368 {
1369 recType.addField(fieldName, type, nullable, rfdg);
1370 }
1371}
1372
1373TypeReferenceExpression TypeReference() throws ParseException:
1374{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001375 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001376}
1377{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001378 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001379 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001380 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1381 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001382 }
1383
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001384 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001385 }
1386}
1387
1388OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1389{
1390 TypeExpression type = null;
1391}
1392{
1393 <LEFTBRACKET>
1394 ( type = TypeExpr() )
1395 <RIGHTBRACKET>
1396 {
1397 return new OrderedListTypeDefinition(type);
1398 }
1399}
1400
1401
1402UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1403{
1404 TypeExpression type = null;
1405}
1406{
1407 <LEFTDBLBRACE>
1408 ( type = TypeExpr() )
1409 <RIGHTDBLBRACE>
1410 {
1411 return new UnorderedListTypeDefinition(type);
1412 }
1413}
1414
1415FunctionName FunctionName() throws ParseException:
1416{
1417 String first = null;
1418 String second = null;
1419 String third = null;
1420 boolean secondAfterDot = false;
1421}
1422{
Michael Blowd6cf6412016-06-30 02:44:35 -04001423 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001424 {
1425 FunctionName result = new FunctionName();
1426 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001427 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001428 ( <DOT> second = Identifier()
1429 {
1430 secondAfterDot = true;
1431 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001432 ( <SYMBOLHASH> third = Identifier())? | <SYMBOLHASH> second = Identifier() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001433 {
1434 if (second == null) {
1435 result.dataverse = defaultDataverse;
1436 result.library = null;
1437 result.function = first;
1438 } else if (third == null) {
1439 if (secondAfterDot) {
1440 result.dataverse = first;
1441 result.library = null;
1442 result.function = second;
1443 } else {
1444 result.dataverse = defaultDataverse;
1445 result.library = first;
1446 result.function = second;
1447 }
1448 } else {
1449 result.dataverse = first;
1450 result.library = second;
1451 result.function = third;
1452 }
1453
1454 if (result.function.equalsIgnoreCase("int")) {
1455 result.function = "int64";
1456 }
1457 return result;
1458 }
1459}
1460
1461
1462Pair<Identifier,Identifier> TypeName() throws ParseException:
1463{
1464 Pair<Identifier,Identifier> name = null;
1465}
1466{
1467 name = QualifiedName()
1468 {
1469 if (name.first == null) {
1470 name.first = new Identifier(defaultDataverse);
1471 }
1472 return name;
1473 }
1474}
1475
1476String Identifier() throws ParseException:
1477{
1478 String lit = null;
1479}
1480{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001481 ((<IDENTIFIER>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001482 {
1483 return token.image;
1484 }
1485 | lit = StringLiteral()
1486 {
1487 return lit;
1488 }
1489 )
1490}
1491
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001492Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001493{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001494 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001495 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001496}
1497{
1498 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001499 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001500 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001501 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1502 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001503 }
1504}
1505
Yingyi Buc9bfe252016-03-01 00:02:40 -08001506Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001507{
1508 List<String> exprList = new ArrayList<String>();
1509 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001510 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001511}
1512{
1513 lit = Identifier()
1514 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001515 boolean meetParens = false;
1516 }
1517 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001518 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001519 <LEFTPAREN><RIGHTPAREN>
1520 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001521 if(!lit.equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001522 throw new ParseException("The string before () has to be \"meta\".");
1523 }
1524 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001525 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001526 }
1527 )?
1528 {
1529 if(!meetParens){
1530 exprList.add(lit);
1531 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001532 }
1533 (<DOT>
1534 lit = Identifier()
1535 {
1536 exprList.add(lit);
1537 }
1538 )*
1539 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001540 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001541 }
1542}
1543
1544
1545
1546String StringLiteral() throws ParseException:
1547{
1548}
1549{
1550 <STRING_LITERAL>
1551 {
1552 return removeQuotesAndEscapes(token.image);
1553 }
1554}
1555
1556Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1557{
1558 String first = null;
1559 String second = null;
1560}
1561{
1562 first = Identifier() (<DOT> second = Identifier())?
1563 {
1564 Identifier id1 = null;
1565 Identifier id2 = null;
1566 if (second == null) {
1567 id2 = new Identifier(first);
1568 } else
1569 {
1570 id1 = new Identifier(first);
1571 id2 = new Identifier(second);
1572 }
1573 return new Pair<Identifier,Identifier>(id1, id2);
1574 }
1575}
1576
1577Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1578{
1579 String first = null;
1580 String second = null;
1581 String third = null;
1582}
1583{
1584 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1585 {
1586 Identifier id1 = null;
1587 Identifier id2 = null;
1588 Identifier id3 = null;
1589 if (third == null) {
1590 id2 = new Identifier(first);
1591 id3 = new Identifier(second);
1592 } else {
1593 id1 = new Identifier(first);
1594 id2 = new Identifier(second);
1595 id3 = new Identifier(third);
1596 }
1597 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1598 }
1599}
1600
1601FunctionDecl FunctionDeclaration() throws ParseException:
1602{
1603 FunctionDecl funcDecl;
1604 FunctionSignature signature;
1605 String functionName;
1606 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1607 Expression funcBody;
1608 createNewScope();
1609}
1610{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001611 <DECLARE> <FUNCTION> functionName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001612 paramList = ParameterList()
1613 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1614 {
1615 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1616 getCurrentScope().addFunctionDescriptor(signature, false);
1617 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1618 removeCurrentScope();
1619 return funcDecl;
1620 }
1621}
1622
1623
1624Query Query() throws ParseException:
1625{
Till Westmannef3f0272016-07-27 18:34:01 -07001626 Query query = new Query(false);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001627 Expression expr;
1628}
1629{
1630 expr = Expression()
1631 {
1632 query.setBody(expr);
1633 query.setVarCounter(getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001634 return query;
1635 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001636}
1637
1638
1639
1640Expression Expression():
1641{
1642 Expression expr = null;
1643 Expression exprP = null;
1644}
1645{
1646(
1647
1648//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1649 expr = OperatorExpr()
1650 | expr = IfThenElse()
1651 | expr = FLWOGR()
1652 | expr = QuantifiedExpression()
1653
1654
1655)
1656 {
1657 return (exprP==null) ? expr : exprP;
1658 }
1659}
1660
1661
1662
1663Expression OperatorExpr()throws ParseException:
1664{
1665 OperatorExpr op = null;
1666 Expression operand = null;
1667}
1668{
1669 operand = AndExpr()
1670 (
1671
1672 <OR>
1673 {
1674 if (op == null) {
1675 op = new OperatorExpr();
1676 op.addOperand(operand);
1677 op.setCurrentop(true);
1678 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001679 try{
1680 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001681 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001682 throw new ParseException(e.getMessage());
1683 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001684 }
1685
1686 operand = AndExpr()
1687 {
1688 op.addOperand(operand);
1689 }
1690
1691 )*
1692
1693 {
1694 return op==null? operand: op;
1695 }
1696}
1697
1698Expression AndExpr()throws ParseException:
1699{
1700 OperatorExpr op = null;
1701 Expression operand = null;
1702}
1703{
1704 operand = RelExpr()
1705 (
1706
1707 <AND>
1708 {
1709 if (op == null) {
1710 op = new OperatorExpr();
1711 op.addOperand(operand);
1712 op.setCurrentop(true);
1713 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001714 try{
1715 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001716 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001717 throw new ParseException(e.getMessage());
1718 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001719 }
1720
1721 operand = RelExpr()
1722 {
1723 op.addOperand(operand);
1724 }
1725
1726 )*
1727
1728 {
1729 return op==null? operand: op;
1730 }
1731}
1732
1733
1734
1735Expression RelExpr()throws ParseException:
1736{
1737 OperatorExpr op = null;
1738 Expression operand = null;
1739 boolean broadcast = false;
1740 IExpressionAnnotation annotation = null;
1741}
1742{
1743 operand = AddExpr()
1744 {
1745 if (operand instanceof VariableExpr) {
1746 String hint = getHint(token);
1747 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1748 broadcast = true;
1749 }
1750 }
1751 }
1752
1753 (
1754 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1755 {
1756 String mhint = getHint(token);
1757 if (mhint != null) {
1758 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1759 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1760 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1761 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1762 }
1763 }
1764 if (op == null) {
1765 op = new OperatorExpr();
1766 op.addOperand(operand, broadcast);
1767 op.setCurrentop(true);
1768 broadcast = false;
1769 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001770 try{
1771 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001772 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001773 throw new ParseException(e.getMessage());
1774 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001775 }
1776
1777 operand = AddExpr()
1778 {
1779 broadcast = false;
1780 if (operand instanceof VariableExpr) {
1781 String hint = getHint(token);
1782 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1783 broadcast = true;
1784 }
1785 }
1786 op.addOperand(operand, broadcast);
1787 }
1788 )?
1789
1790 {
1791 if (annotation != null) {
1792 op.addHint(annotation);
1793 }
1794 return op==null? operand: op;
1795 }
1796}
1797
1798Expression AddExpr()throws ParseException:
1799{
1800 OperatorExpr op = null;
1801 Expression operand = null;
1802}
1803{
1804 operand = MultExpr()
1805
1806 ( (<PLUS> | <MINUS>)
1807 {
1808 if (op == null) {
1809 op = new OperatorExpr();
1810 op.addOperand(operand);
1811 op.setCurrentop(true);
1812 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001813 try{
1814 ((OperatorExpr)op).addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001815 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001816 throw new ParseException(e.getMessage());
1817 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001818 }
1819
1820 operand = MultExpr()
1821 {
1822 op.addOperand(operand);
1823 }
1824 )*
1825
1826 {
1827 return op==null? operand: op;
1828 }
1829}
1830
1831Expression MultExpr()throws ParseException:
1832{
1833 OperatorExpr op = null;
1834 Expression operand = null;
1835}
1836{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001837 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001838
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001839 (( <MUL> | <DIV> | <MOD> | <IDIV>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001840 {
1841 if (op == null) {
1842 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001843 op.addOperand(operand);
1844 op.setCurrentop(true);
1845 }
1846 try{
1847 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001848 } catch (CompilationException e){
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001849 throw new ParseException(e.getMessage());
1850 }
1851 }
1852 operand = ExponentExpr()
1853 {
1854 op.addOperand(operand);
1855 }
1856 )*
1857
1858 {
1859 return op==null?operand:op;
1860 }
1861}
1862
1863Expression ExponentExpr()throws ParseException:
1864{
1865 OperatorExpr op = null;
1866 Expression operand = null;
1867}
1868{
1869 operand = UnionExpr()
1870
1871 ( <CARET>
1872 {
1873 if (op == null) {
1874 op = new OperatorExpr();
1875 op.addOperand(operand);
1876 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001877 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001878 try{
1879 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001880 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001881 throw new ParseException(e.getMessage());
1882 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001883 }
1884 operand = UnionExpr()
1885 {
1886 op.addOperand(operand);
1887 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001888 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001889
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001890 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001891 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001892 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001893}
1894
1895Expression UnionExpr() throws ParseException:
1896{
1897 UnionExpr union = null;
1898 Expression operand1 = null;
1899 Expression operand2 = null;
1900}
1901{
1902 operand1 = UnaryExpr()
1903 (<UNION>
1904 (operand2 = UnaryExpr()) {
1905 if (union == null) {
1906 union = new UnionExpr();
1907 union.addExpr(operand1);
1908 }
1909 union.addExpr(operand2);
1910 } )*
1911 {
1912 return (union == null)? operand1: union;
1913 }
1914}
1915
1916Expression UnaryExpr() throws ParseException:
1917{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001918 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001919 Expression expr = null;
1920}
1921{
1922 ( (<PLUS> | <MINUS>)
1923 {
1924 uexpr = new UnaryExpr();
Yingyi Bu196db5d2016-07-15 19:07:20 -07001925 try{
1926 uexpr.setExprType(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001927 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001928 throw new ParseException(e.getMessage());
1929 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001930 }
1931 )?
1932
1933 expr = ValueExpr()
1934 {
1935 if(uexpr!=null){
1936 ((UnaryExpr)uexpr).setExpr(expr);
1937 return uexpr;
1938 }
1939 else{
1940 return expr;
1941 }
1942 }
1943}
1944
1945Expression ValueExpr()throws ParseException:
1946{
1947 Expression expr = null;
1948 Identifier ident = null;
1949 AbstractAccessor fa = null;
1950 Expression indexExpr = null;
1951}
1952{
1953 expr = PrimaryExpr() ( ident = Field()
1954 {
1955 fa = (fa == null ? new FieldAccessor(expr, ident)
1956 : new FieldAccessor(fa, ident));
1957 }
1958 | indexExpr = Index()
1959 {
1960 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1961 : new IndexAccessor(fa, indexExpr));
1962 }
1963 )*
1964 {
1965 return fa == null ? expr : fa;
1966 }
1967}
1968
1969Identifier Field() throws ParseException:
1970{
1971 String ident = null;
1972}
1973{
1974 <DOT> ident = Identifier()
1975 {
1976 return new Identifier(ident);
1977 }
1978}
1979
1980Expression Index() throws ParseException:
1981{
1982 Expression expr = null;
1983}
1984{
1985 <LEFTBRACKET> ( expr = Expression()
1986 {
1987 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1988 {
1989 Literal lit = ((LiteralExpr)expr).getValue();
1990 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1991 lit.getLiteralType() != Literal.Type.LONG) {
1992 throw new ParseException("Index should be an INTEGER");
1993 }
1994 }
1995 }
1996
1997 | <QUES> // ANY
1998
1999 )
2000
2001 <RIGHTBRACKET>
2002 {
2003 return expr;
2004 }
2005}
2006
2007
2008Expression PrimaryExpr()throws ParseException:
2009{
2010 Expression expr = null;
2011}
2012{
2013 ( LOOKAHEAD(2)
2014 expr = FunctionCallExpr()
2015 | expr = Literal()
2016 | expr = DatasetAccessExpression()
2017 | expr = VariableRef()
2018 {
2019 if(((VariableExpr)expr).getIsNewVar() == true)
2020 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
2021 }
2022 | expr = ListConstructor()
2023 | expr = RecordConstructor()
2024 | expr = ParenthesizedExpression()
2025 )
2026 {
2027 return expr;
2028 }
2029}
2030
2031Expression Literal() throws ParseException:
2032{
2033 LiteralExpr lit = new LiteralExpr();
2034 String str = null;
2035}
2036{
2037 ( str = StringLiteral()
2038 {
2039 lit.setValue(new StringLiteral(str));
2040 }
2041 | <INTEGER_LITERAL>
2042 {
2043 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
2044 }
2045 | <FLOAT_LITERAL>
2046 {
2047 lit.setValue(new FloatLiteral(new Float(token.image)));
2048 }
2049 | <DOUBLE_LITERAL>
2050 {
2051 lit.setValue(new DoubleLiteral(new Double(token.image)));
2052 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002053 | <MISSING>
2054 {
2055 lit.setValue(MissingLiteral.INSTANCE);
2056 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002057 | <NULL>
2058 {
2059 lit.setValue(NullLiteral.INSTANCE);
2060 }
2061 | <TRUE>
2062 {
2063 lit.setValue(TrueLiteral.INSTANCE);
2064 }
2065 | <FALSE>
2066 {
2067 lit.setValue(FalseLiteral.INSTANCE);
2068 }
2069 )
2070 {
2071 return lit;
2072 }
2073}
2074
2075
2076VariableExpr VariableRef() throws ParseException:
2077{
2078 VariableExpr varExp = new VariableExpr();
2079 VarIdentifier var = new VarIdentifier();
2080}
2081{
2082 <VARIABLE>
2083 {
2084 String varName = token.image;
2085 Identifier ident = lookupSymbol(varName);
2086 if (isInForbiddenScopes(varName)) {
2087 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.");
2088 }
2089 if(ident != null) { // exist such ident
2090 varExp.setIsNewVar(false);
2091 varExp.setVar((VarIdentifier)ident);
2092 } else {
2093 varExp.setVar(var);
2094 }
2095 var.setValue(varName);
2096 return varExp;
2097 }
2098}
2099
2100
2101VariableExpr Variable() throws ParseException:
2102{
2103 VariableExpr varExp = new VariableExpr();
2104 VarIdentifier var = new VarIdentifier();
2105}
2106{
2107 <VARIABLE>
2108 {
2109 Identifier ident = lookupSymbol(token.image);
2110 if(ident != null) { // exist such ident
2111 varExp.setIsNewVar(false);
2112 }
2113 varExp.setVar(var);
2114 var.setValue(token.image);
2115 return varExp;
2116 }
2117}
2118
2119Expression ListConstructor() throws ParseException:
2120{
2121 Expression expr = null;
2122}
2123{
2124 (
2125 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2126 )
2127
2128 {
2129 return expr;
2130 }
2131}
2132
2133
2134ListConstructor OrderedListConstructor() throws ParseException:
2135{
2136 ListConstructor expr = new ListConstructor();
2137 List<Expression> exprList = null;
2138 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2139}
2140{
2141 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2142 {
2143 expr.setExprList(exprList);
2144 return expr;
2145 }
2146}
2147
2148ListConstructor UnorderedListConstructor() throws ParseException:
2149{
2150 ListConstructor expr = new ListConstructor();
2151 List<Expression> exprList = null;
2152 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2153}
2154{
2155 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2156 {
2157 expr.setExprList(exprList);
2158 return expr;
2159 }
2160}
2161
2162List<Expression> ExpressionList() throws ParseException:
2163{
2164 Expression expr = null;
2165 List<Expression> list = null;
2166 List<Expression> exprList = new ArrayList<Expression>();
2167}
2168{
2169 (
2170 expr = Expression() { exprList.add(expr); }
2171 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2172 )?
2173 (LOOKAHEAD(1) Comma())?
2174 {
2175 return exprList;
2176 }
2177}
2178
2179void Comma():
2180{}
2181{
2182 <COMMA>
2183}
2184
2185RecordConstructor RecordConstructor() throws ParseException:
2186{
2187 RecordConstructor expr = new RecordConstructor();
2188 FieldBinding tmp = null;
2189 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2190}
2191{
2192 <LEFTBRACE> (tmp = FieldBinding()
2193 {
2194 fbList.add(tmp);
2195 }
2196 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2197 {
2198 expr.setFbList(fbList);
2199 return expr;
2200 }
2201}
2202
2203FieldBinding FieldBinding() throws ParseException:
2204{
2205 FieldBinding fb = new FieldBinding();
2206 Expression left, right;
2207}
2208{
2209 left = Expression() <COLON> right = Expression()
2210 {
2211 fb.setLeftExpr(left);
2212 fb.setRightExpr(right);
2213 return fb;
2214 }
2215}
2216
2217
2218Expression FunctionCallExpr() throws ParseException:
2219{
2220 CallExpr callExpr;
2221 List<Expression> argList = new ArrayList<Expression>();
2222 Expression tmp;
2223 int arity = 0;
2224 FunctionName funcName = null;
2225 String hint = null;
2226}
2227{
2228 funcName = FunctionName()
2229 {
2230 hint = funcName.hint;
2231 }
2232 <LEFTPAREN> (tmp = Expression()
2233 {
2234 argList.add(tmp);
2235 arity ++;
2236 }
2237 (<COMMA> tmp = Expression()
2238 {
2239 argList.add(tmp);
2240 arity++;
2241 }
2242 )*)? <RIGHTPAREN>
2243 {
2244 // TODO use funcName.library
2245 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2246 FunctionSignature signature
2247 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2248 if (signature == null) {
2249 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2250 }
2251 callExpr = new CallExpr(signature,argList);
2252 if (hint != null) {
2253 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2254 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2255 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2256 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2257 }
2258 }
2259 return callExpr;
2260 }
2261}
2262
2263
2264Expression DatasetAccessExpression() throws ParseException:
2265{
2266 String funcName;
2267 String arg1 = null;
2268 String arg2 = null;
2269 Expression nameArg;
2270}
2271{
2272 <DATASET>
2273 {
2274 funcName = token.image;
2275 }
2276 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
2277 {
2278 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
2279 LiteralExpr ds = new LiteralExpr();
2280 ds.setValue( new StringLiteral(name) );
2281 nameArg = ds;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002282 }
2283 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
2284 {
2285 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2286 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2287 if (signature == null) {
2288 signature = new FunctionSignature(dataverse, funcName, 1);
2289 }
2290 List<Expression> argList = new ArrayList<Expression>();
2291 argList.add(nameArg);
2292 return new CallExpr(signature, argList);
2293 }
2294}
2295
2296Expression ParenthesizedExpression() throws ParseException:
2297{
2298 Expression expr;
2299}
2300{
2301 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2302 {
2303 return expr;
2304 }
2305}
2306
2307Expression IfThenElse() throws ParseException:
2308{
2309 Expression condExpr;
2310 Expression thenExpr;
2311 Expression elseExpr;
2312 IfExpr ifExpr = new IfExpr();
2313}
2314{
2315 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2316
2317 {
2318 ifExpr.setCondExpr(condExpr);
2319 ifExpr.setThenExpr(thenExpr);
2320 ifExpr.setElseExpr(elseExpr);
2321 return ifExpr;
2322 }
2323}
2324
Taewoo Kim92c0bac2017-02-11 16:38:44 -08002325// Note: if you modify this part: "tmp = LetClause() {clauseList.add(tmp);}", please also apply the necessary
2326// change to the AQLPlusExtension.jj file since it refers to this string part and may behave incorrectly if this
2327// part is modified. For more details, please refer to AQLPlusExtension.jj file.
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002328Expression FLWOGR() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002329{
2330 FLWOGRExpression flworg = new FLWOGRExpression();
2331 List<Clause> clauseList = new ArrayList<Clause>();
2332 Expression returnExpr;
2333 Clause tmp;
2334 createNewScope();
2335}
2336{
2337 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2338 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
2339
2340 {
2341 flworg.setClauseList(clauseList);
2342 flworg.setReturnExpr(returnExpr);
2343 removeCurrentScope();
2344 return flworg;
2345 }
2346}
2347
2348Clause Clause()throws ParseException :
2349{
2350 Clause clause;
2351}
2352{
2353 (
2354 clause = ForClause()
2355 | clause = LetClause()
2356 | clause = WhereClause()
2357 | clause = OrderbyClause()
2358 | clause = GroupClause()
2359 | clause = LimitClause()
2360 | clause = DistinctClause()
2361 )
2362 {
2363 return clause;
2364 }
2365}
2366
2367Clause ForClause()throws ParseException :
2368{
2369 ForClause fc = new ForClause();
2370 VariableExpr varExp;
2371 VariableExpr varPos = null;
2372 Expression inExp;
2373 extendCurrentScope();
2374}
2375{
2376 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
2377 {
2378 fc.setVarExpr(varExp);
2379 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2380 fc.setInExpr(inExp);
2381 if (varPos != null) {
2382 fc.setPosExpr(varPos);
2383 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2384 }
2385 return fc;
2386 }
2387}
2388
2389Clause LetClause() throws ParseException:
2390{
2391 LetClause lc = new LetClause();
2392 VariableExpr varExp;
2393 Expression beExp;
2394 extendCurrentScope();
2395}
2396{
2397 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
2398 {
2399 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2400 lc.setVarExpr(varExp);
2401 lc.setBindingExpr(beExp);
2402 return lc;
2403 }
2404}
2405
2406Clause WhereClause()throws ParseException :
2407{
2408 WhereClause wc = new WhereClause();
2409 Expression whereExpr;
2410}
2411{
2412 <WHERE> whereExpr = Expression()
2413 {
2414 wc.setWhereExpr(whereExpr);
2415 return wc;
2416 }
2417}
2418
2419Clause OrderbyClause()throws ParseException :
2420{
2421 OrderbyClause oc = new OrderbyClause();
2422 Expression orderbyExpr;
2423 List<Expression> orderbyList = new ArrayList<Expression>();
2424 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2425 int numOfOrderby = 0;
2426}
2427{
2428 (
2429 <ORDER>
2430 {
2431 String hint = getHint(token);
2432 if (hint != null) {
2433 if (hint.startsWith(INMEMORY_HINT)) {
2434 String splits[] = hint.split(" +");
2435 int numFrames = Integer.parseInt(splits[1]);
2436 int numTuples = Integer.parseInt(splits[2]);
2437 oc.setNumFrames(numFrames);
2438 oc.setNumTuples(numTuples);
2439 }
2440 if (hint.startsWith(RANGE_HINT)) {
2441 try{
2442 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002443 } catch (CompilationException e) {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002444 throw new ParseException(e.getMessage());
2445 }
2446 }
2447 }
2448 }
2449 <BY> orderbyExpr = Expression()
2450 {
2451 orderbyList.add(orderbyExpr);
2452 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2453 }
2454 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2455 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2456 {
2457 modifierList.add(modif);
2458 }
2459
2460 (<COMMA> orderbyExpr = Expression()
2461 {
2462 orderbyList.add(orderbyExpr);
2463 modif = OrderbyClause.OrderModifier.ASC;
2464 }
2465 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2466 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2467 {
2468 modifierList.add(modif);
2469 }
2470 )*
2471)
2472 {
2473 oc.setModifierList(modifierList);
2474 oc.setOrderbyList(orderbyList);
2475 return oc;
2476 }
2477}
2478Clause GroupClause()throws ParseException :
2479{
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002480 GroupbyClause gbc = new GroupbyClause();
2481 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2482 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002483 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002484 Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002485 VariableExpr var = null;
2486 VariableExpr withVar = null;
2487 Expression expr = null;
2488 VariableExpr decorVar = null;
2489 Expression decorExpr = null;
2490}
2491{
2492 {
2493 Scope newScope = extendCurrentScopeNoPush(true);
2494 // extendCurrentScope(true);
2495 }
2496 <GROUP>
2497 {
2498 String hint = getHint(token);
2499 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2500 gbc.setHashGroupByHint(true);
2501 }
2502 }
2503 <BY> (LOOKAHEAD(2) var = Variable()
2504 {
2505 newScope.addNewVarSymbolToScope(var.getVar());
2506 } <ASSIGN>)?
2507 expr = Expression()
2508 {
2509 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2510 vePairList.add(pair1);
2511 }
2512 (<COMMA> ( LOOKAHEAD(2) var = Variable()
2513 {
2514 newScope.addNewVarSymbolToScope(var.getVar());
2515 } <ASSIGN>)?
2516 expr = Expression()
2517 {
2518 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2519 vePairList.add(pair2);
2520 }
2521 )*
2522 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2523 {
2524 newScope.addNewVarSymbolToScope(decorVar.getVar());
2525 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2526 decorPairList.add(pair3);
2527 }
2528 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2529 {
2530 newScope.addNewVarSymbolToScope(decorVar.getVar());
2531 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2532 decorPairList.add(pair4);
2533 }
2534 )*
2535 )?
2536 (<WITH>|<KEEPING>) withVar = VariableRef()
2537 {
2538 if(withVar.getIsNewVar()==true)
2539 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002540 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002541 newScope.addNewVarSymbolToScope(withVar.getVar());
2542 }
2543 (<COMMA> withVar = VariableRef()
2544 {
2545 if(withVar.getIsNewVar()==true)
2546 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002547 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002548 newScope.addNewVarSymbolToScope(withVar.getVar());
2549 })*
2550 {
2551 gbc.setGbyPairList(vePairList);
2552 gbc.setDecorPairList(decorPairList);
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002553 gbc.setWithVarMap(withVarMap);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002554 replaceCurrentScope(newScope);
2555 return gbc;
2556 }
2557}
2558
2559
2560LimitClause LimitClause() throws ParseException:
2561{
2562 LimitClause lc = new LimitClause();
2563 Expression expr;
2564 pushForbiddenScope(getCurrentScope());
2565}
2566{
2567 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2568 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2569
2570 {
2571 popForbiddenScope();
2572 return lc;
2573 }
2574}
2575
2576DistinctClause DistinctClause() throws ParseException:
2577{
2578 List<Expression> exprs = new ArrayList<Expression>();
2579 Expression expr;
2580}
2581{
2582 <DISTINCT> <BY> expr = Expression()
2583 {
2584 exprs.add(expr);
2585 }
2586 (<COMMA> expr = Expression()
2587 {
2588 exprs.add(expr);
2589 }
2590 )*
2591 {
2592 return new DistinctClause(exprs);
2593 }
2594}
2595
2596QuantifiedExpression QuantifiedExpression()throws ParseException:
2597{
2598 QuantifiedExpression qc = new QuantifiedExpression();
2599 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2600 Expression satisfiesExpr;
2601 VariableExpr var;
2602 Expression inExpr;
2603 QuantifiedPair pair;
2604}
2605{
2606 {
2607 createNewScope();
2608 }
2609
Michael Blowd6cf6412016-06-30 02:44:35 -04002610 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2611 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07002612 var = Variable() <IN> inExpr = Expression()
2613 {
2614 pair = new QuantifiedPair(var, inExpr);
2615 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2616 quantifiedList.add(pair);
2617 }
2618 (
2619 <COMMA> var = Variable() <IN> inExpr = Expression()
2620 {
2621 pair = new QuantifiedPair(var, inExpr);
2622 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2623 quantifiedList.add(pair);
2624 }
2625 )*
2626 <SATISFIES> satisfiesExpr = Expression()
2627 {
2628 qc.setSatisfiesExpr(satisfiesExpr);
2629 qc.setQuantifiedList(quantifiedList);
2630 removeCurrentScope();
2631 return qc;
2632 }
2633}
2634
2635TOKEN_MGR_DECLS:
2636{
2637 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07002638 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002639
2640 public void pushState() {
2641 lexerStateStack.push( curLexState );
2642 }
2643
2644 public void popState(String token) {
2645 if (lexerStateStack.size() > 0) {
2646 SwitchTo( lexerStateStack.pop() );
2647 } else {
2648 int errorLine = input_stream.getEndLine();
2649 int errorColumn = input_stream.getEndColumn();
2650 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2651 + "\" but state stack is empty.";
2652 throw new TokenMgrError(msg, -1);
2653 }
2654 }
2655}
2656
2657<DEFAULT,IN_DBL_BRACE>
2658TOKEN :
2659{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002660 <APPLY : "apply">
2661 | <AS : "as">
2662 | <ASC : "asc">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002663 | <AT : "at">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002664 | <AUTOGENERATED : "autogenerated">
2665 | <BTREE : "btree">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002666 | <BY : "by">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002667 | <CLOSED : "closed">
2668 | <COMPACT : "compact">
2669 | <COMPACTION : "compaction">
2670 | <CONNECT : "connect">
2671 | <CREATE : "create">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002672 | <DATASET : "dataset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002673 | <DATAVERSE : "dataverse">
2674 | <DECLARE : "declare">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002675 | <DECOR : "decor">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002676 | <DEFINITION : "definition">
2677 | <DELETE : "delete">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002678 | <DESC : "desc">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002679 | <DISCONNECT : "disconnect">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002680 | <DISTINCT : "distinct">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002681 | <DROP : "drop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002682 | <ELSE : "else">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002683 | <ENFORCED : "enforced">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002684 | <EVERY : "every">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002685 | <EXISTS : "exists">
2686 | <EXTERNAL : "external">
2687 | <FEED : "feed">
2688 | <FILTER : "filter">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002689 | <FOR : "for">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002690 | <FORMAT : "format">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002691 | <FROM : "from">
Taewoo Kimc49405a2017-01-04 00:30:43 -08002692 | <FULLTEXT : "fulltext">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002693 | <FUNCTION : "function">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002694 | <GROUP : "group">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002695 | <HINTS : "hints">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002696 | <IF : "if">
2697 | <IN : "in">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002698 | <INDEX : "index">
2699 | <INGESTION : "ingestion">
2700 | <INSERT : "insert">
2701 | <INTERNAL : "internal">
2702 | <INTO : "into">
2703 | <KEY : "key">
2704 | <KEYWORD : "keyword">
2705 | <KEEPING : "keeping">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002706 | <LET : "let">
2707 | <LIMIT : "limit">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002708 | <LOAD : "load">
2709 | <NGRAM : "ngram">
2710 | <NODEGROUP : "nodegroup">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002711 | <OFFSET : "offset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002712 | <ON : "on">
2713 | <OPEN : "open">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002714 | <ORDER : "order">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002715 | <OUTPUT : "output">
2716 | <PATH : "path">
2717 | <POLICY : "policy">
2718 | <PRESORTED : "pre-sorted">
2719 | <PRIMARY : "primary">
2720 | <REFRESH : "refresh">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002721 | <RETURN : "return">
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -07002722 | <RETURNING : "returning">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002723 | <RTREE : "rtree">
2724 | <RUN : "run">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002725 | <SATISFIES : "satisfies">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002726 | <SECONDARY : "secondary">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002727 | <SELECT : "select">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002728 | <SET : "set">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08002729 | <START: "start">
2730 | <STOP: "stop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002731 | <SOME : "some">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002732 | <TEMPORARY : "temporary">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002733 | <THEN : "then">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002734 | <TO : "to">
2735 | <TYPE : "type">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002736 | <UNION : "union">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002737 | <UPDATE : "update">
2738 | <UPSERT : "upsert">
2739 | <USE : "use">
2740 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002741 | <WHERE : "where">
2742 | <WITH : "with">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002743 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002744}
2745
2746<DEFAULT,IN_DBL_BRACE>
2747TOKEN :
2748{
2749 <CARET : "^">
2750 | <DIV : "/">
2751 | <IDIV : "idiv">
2752 | <MINUS : "-">
2753 | <MOD : "%">
2754 | <MUL : "*">
2755 | <PLUS : "+">
2756
2757 | <LEFTPAREN : "(">
2758 | <RIGHTPAREN : ")">
2759 | <LEFTBRACKET : "[">
2760 | <RIGHTBRACKET : "]">
2761
2762 | <COLON : ":">
2763 | <COMMA : ",">
2764 | <DOT : ".">
2765 | <QUES : "?">
2766
2767 | <LT : "<">
2768 | <GT : ">">
2769 | <LE : "<=">
2770 | <GE : ">=">
2771 | <EQ : "=">
2772 | <NE : "!=">
2773 | <SIMILAR : "~=">
2774 | <ASSIGN : ":=">
2775
2776 | <AND : "and">
2777 | <OR : "or">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002778
2779 | <SYMBOLAT : "@">
2780 | <SYMBOLHASH : "#">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002781}
2782
2783<DEFAULT,IN_DBL_BRACE>
2784TOKEN :
2785{
2786 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2787}
2788
2789<DEFAULT>
2790TOKEN :
2791{
2792 <RIGHTBRACE : "}"> { popState("}"); }
2793}
2794
2795<DEFAULT,IN_DBL_BRACE>
2796TOKEN :
2797{
2798 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2799}
2800
2801<IN_DBL_BRACE>
2802TOKEN :
2803{
2804 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2805}
2806
2807<DEFAULT,IN_DBL_BRACE>
2808TOKEN :
2809{
2810 <INTEGER_LITERAL : (<DIGIT>)+ >
2811}
2812
2813<DEFAULT,IN_DBL_BRACE>
2814TOKEN :
2815{
Yingyi Bu535d86b2016-05-23 16:44:25 -07002816 < MISSING : "missing">
2817 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002818 | <TRUE : "true">
2819 | <FALSE : "false">
2820}
2821
2822<DEFAULT,IN_DBL_BRACE>
2823TOKEN :
2824{
2825 <#DIGIT : ["0" - "9"]>
2826}
2827
2828<DEFAULT,IN_DBL_BRACE>
2829TOKEN:
2830{
Yingyi Bu144453b2017-05-24 14:34:46 -07002831 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("-")? <DIGITS>)?
2832 | <DIGITS> (("e"|"E") ("-")? <DIGITS>)
2833 | "." <DIGITS> (("e"|"E") ("-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002834 >
2835 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2836 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2837 | "." <DIGITS> ( "f" | "F" )
2838 >
2839 | <DIGITS : (<DIGIT>)+ >
2840}
2841
2842<DEFAULT,IN_DBL_BRACE>
2843TOKEN :
2844{
2845 <#LETTER : ["A" - "Z", "a" - "z"]>
2846 | <SPECIALCHARS : ["$", "_", "-"]>
2847}
2848
2849<DEFAULT,IN_DBL_BRACE>
2850TOKEN :
2851{
2852 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2853 <STRING_LITERAL : ("\"" (
2854 <EscapeQuot>
2855 | <EscapeBslash>
2856 | <EscapeSlash>
2857 | <EscapeBspace>
2858 | <EscapeFormf>
2859 | <EscapeNl>
2860 | <EscapeCr>
2861 | <EscapeTab>
2862 | ~["\"","\\"])* "\"")
2863 | ("\'"(
2864 <EscapeApos>
2865 | <EscapeBslash>
2866 | <EscapeSlash>
2867 | <EscapeBspace>
2868 | <EscapeFormf>
2869 | <EscapeNl>
2870 | <EscapeCr>
2871 | <EscapeTab>
2872 | ~["\'","\\"])* "\'")>
2873 | < #EscapeQuot: "\\\"" >
2874 | < #EscapeApos: "\\\'" >
2875 | < #EscapeBslash: "\\\\" >
2876 | < #EscapeSlash: "\\/" >
2877 | < #EscapeBspace: "\\b" >
2878 | < #EscapeFormf: "\\f" >
2879 | < #EscapeNl: "\\n" >
2880 | < #EscapeCr: "\\r" >
2881 | < #EscapeTab: "\\t" >
2882}
2883
2884<DEFAULT,IN_DBL_BRACE>
2885TOKEN :
2886{
2887 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2888}
2889
2890<DEFAULT,IN_DBL_BRACE>
2891TOKEN :
2892{
2893 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
2894}
2895
2896<DEFAULT,IN_DBL_BRACE>
2897SKIP:
2898{
2899 " "
2900 | "\t"
2901 | "\r"
2902 | "\n"
2903}
2904
2905<DEFAULT,IN_DBL_BRACE>
2906SKIP:
2907{
2908 <"//" (~["\n"])* "\n">
2909}
2910
2911<DEFAULT,IN_DBL_BRACE>
2912SKIP:
2913{
2914 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2915}
2916
2917<DEFAULT,IN_DBL_BRACE>
2918SKIP:
2919{
2920 <"/*"> { pushState(); } : INSIDE_COMMENT
2921}
2922
2923<INSIDE_COMMENT>
2924SPECIAL_TOKEN:
2925{
2926 <"+"(" ")*(~["*"])*>
2927}
2928
2929<INSIDE_COMMENT>
2930SKIP:
2931{
2932 <"/*"> { pushState(); }
2933}
2934
2935<INSIDE_COMMENT>
2936SKIP:
2937{
2938 <"*/"> { popState("*/"); }
2939 | <~[]>
2940}