blob: 4c8820f666cc8f076b14b2147fcda86dedf163be [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;
Yingyi Bucb5bf332017-01-02 22:19:50 -080070import org.apache.asterix.lang.aql.util.AQLFormatPrintUtil;
Yingyi Bu391f09e2015-10-29 13:49:39 -070071import org.apache.asterix.lang.common.base.Clause;
72import org.apache.asterix.lang.common.base.Expression;
Yingyi Bucb5bf332017-01-02 22:19:50 -080073import org.apache.asterix.lang.common.base.ILangExpression;
Yingyi Bu391f09e2015-10-29 13:49:39 -070074import org.apache.asterix.lang.common.base.IParser;
Ali Alsuliman80225e22018-10-15 14:17:07 -070075import org.apache.asterix.lang.common.base.IParserFactory;
Yingyi Bu391f09e2015-10-29 13:49:39 -070076import 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;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700143import org.apache.asterix.lang.common.statement.SetStatement;
144import org.apache.asterix.lang.common.statement.TypeDecl;
145import org.apache.asterix.lang.common.statement.TypeDropStatement;
146import org.apache.asterix.lang.common.statement.UpdateStatement;
Abdullah Alamoudi5dc958c2016-01-30 11:15:23 +0300147import org.apache.asterix.lang.common.statement.UpsertStatement;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700148import org.apache.asterix.lang.common.statement.WriteStatement;
149import org.apache.asterix.lang.common.struct.Identifier;
Dmitry Lychaginbf48c492018-05-01 18:30:27 -0700150import org.apache.asterix.lang.common.struct.OperatorType;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700151import org.apache.asterix.lang.common.struct.QuantifiedPair;
152import org.apache.asterix.lang.common.struct.VarIdentifier;
Ali Alsuliman80225e22018-10-15 14:17:07 -0700153import org.apache.asterix.lang.common.util.RangeMapBuilder;
Yingyi Buab817482016-08-19 21:29:31 -0700154import org.apache.asterix.metadata.utils.MetadataConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700155import org.apache.hyracks.algebricks.common.utils.Pair;
156import org.apache.hyracks.algebricks.common.utils.Triple;
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800157import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
Shiva2ea73232019-10-09 18:04:05 -0700158import org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700159import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
160import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
161import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
162
163
Yingyi Bucaea8f02015-11-16 15:12:15 -0800164class AQLParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700165
166 // optimizer hints
167 private static final String AUTO_HINT = "auto";
Shiva2ea73232019-10-09 18:04:05 -0700168 private static final String HASH_BROADCAST_JOIN_HINT = "hash-bcast";
Yingyi Bu391f09e2015-10-29 13:49:39 -0700169 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
170 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
171 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
172 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
173 private static final String HASH_GROUP_BY_HINT = "hash";
174 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
175 private static final String INMEMORY_HINT = "inmem";
176 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
177 private static final String INTERVAL_HINT = "interval";
178 private static final String LIST_HINT = "list";
179 private static final String LIST_VAL_FILE_HINT = "list-val-file";
180 private static final String RANGE_HINT = "range";
181 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
182 private static final String VAL_FILE_HINT = "val-files";
183 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
Yingyi Bu391f09e2015-10-29 13:49:39 -0700184 private static final String GEN_FIELDS_HINT = "gen-fields";
Yingyi Bu391f09e2015-10-29 13:49:39 -0700185 // data generator hints
186 private static final String DGEN_HINT = "dgen";
187
188 private static class IndexParams {
189 public IndexType type;
190 public int gramLength;
191
192 public IndexParams(IndexType type, int gramLength) {
193 this.type = type;
194 this.gramLength = gramLength;
195 }
196 };
197
198 private static class FunctionName {
199 public String dataverse = null;
200 public String library = null;
201 public String function = null;
202 public String hint = null;
203 }
204
205 private static String getHint(Token t) {
206 if (t.specialToken == null) {
207 return null;
208 }
209 String s = t.specialToken.image;
210 int n = s.length();
211 if (n < 2) {
212 return null;
213 }
214 return s.substring(1).trim();
215 }
216
Yingyi Bucb5bf332017-01-02 22:19:50 -0800217 private static void checkBindingVariable(Expression returnExpression, VariableExpr var,
218 ILangExpression bodyExpression) throws ParseException {
219 if (returnExpression != null && var == null) {
220 try {
221 throw new ParseException("Need a binding variable for the enclosed expression: " +
222 AQLFormatPrintUtil.toString(bodyExpression));
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800223 } catch (CompilationException e){
Yingyi Bucb5bf332017-01-02 22:19:50 -0800224 throw new ParseException(e.getLocalizedMessage());
225 }
226 }
227 }
228
Yingyi Bu391f09e2015-10-29 13:49:39 -0700229 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
230 IRecordFieldDataGen rfdg = null;
231 String splits[] = hint.split(" +");
232 if (splits[0].equals(VAL_FILE_HINT)) {
233 File[] valFiles = new File[splits.length - 1];
234 for (int k=1; k<splits.length; k++) {
235 valFiles[k-1] = new File(splits[k]);
236 }
237 rfdg = new FieldValFileDataGen(valFiles);
238 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
239 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
240 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
241 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
242 } else if (splits[0].equals(LIST_HINT)) {
243 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
244 } else if (splits[0].equals(INTERVAL_HINT)) {
245 FieldIntervalDataGen.ValueType vt;
246 if (splits[1].equals("int")) {
247 vt = FieldIntervalDataGen.ValueType.INT;
248 } else if (splits[1].equals("long")) {
249 vt = FieldIntervalDataGen.ValueType.LONG;
250 } else if (splits[1].equals("float")) {
251 vt = FieldIntervalDataGen.ValueType.FLOAT;
252 } else if (splits[1].equals("double")) {
253 vt = FieldIntervalDataGen.ValueType.DOUBLE;
254 } else {
255 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
256 }
257 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
258 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
259 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
260 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
261 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
262 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
263 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
264 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
265 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
266 } else if (splits[0].equals(AUTO_HINT)) {
267 rfdg = new AutoDataGen(splits[1]);
268 }
269 return rfdg;
270 }
271
272 public AQLParser(String s){
273 this(new StringReader(s));
274 super.setInput(s);
275 }
276
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800277 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700278 File file = new File(args[0]);
279 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
280 AQLParser parser = new AQLParser(fis);
281 List<Statement> st = parser.parse();
282 //st.accept(new AQLPrintVisitor(), 0);
283 }
284
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800285 public List<Statement> parse() throws CompilationException {
Dmitry Lychagin1227f022019-08-01 13:14:30 -0700286 return parseImpl(new ParseFunction<List<Statement>>() {
287 @Override
288 public List<Statement> parse() throws ParseException {
289 return AQLParser.this.Statement();
290 }
291 });
292 }
293
294 private Expression parseExpression() throws CompilationException {
295 return parseImpl(new ParseFunction<Expression>() {
296 @Override
297 public Expression parse() throws ParseException {
298 return AQLParser.this.Expression();
299 }
300 });
301 }
302
303 private static Expression parseExpression(String text) throws CompilationException {
304 return new AQLParser(text).parseExpression();
305 }
306
307 private <T> T parseImpl(ParseFunction<T> parseFunction) throws CompilationException {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700308 try {
Dmitry Lychagin1227f022019-08-01 13:14:30 -0700309 return parseFunction.parse();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700310 } catch (Error e) {
311 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
312 // 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 -0800313 throw new CompilationException(new ParseException(e.getMessage()));
Yingyi Bu391f09e2015-10-29 13:49:39 -0700314 } catch (ParseException e){
Taewoo Kime65e6ca2017-01-14 17:53:28 -0800315 throw new CompilationException(e.getMessage());
Yingyi Bu391f09e2015-10-29 13:49:39 -0700316 }
317 }
Dmitry Lychagin1227f022019-08-01 13:14:30 -0700318
319 @FunctionalInterface
320 private interface ParseFunction<T> {
321 T parse() throws ParseException;
322 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700323}
324
325PARSER_END(AQLParser)
326
327
328List<Statement> Statement() throws ParseException:
329{
330 scopeStack.push(RootScopeFactory.createRootScope(this));
331 List<Statement> decls = new ArrayList<Statement>();
332 Statement stmt = null;
333}
334{
335 ( stmt = SingleStatement() (";") ?
336 {
337 decls.add(stmt);
338 }
339 )*
Till Westmann81870d72017-03-16 18:11:23 -0700340 (";") *
Yingyi Bu391f09e2015-10-29 13:49:39 -0700341 <EOF>
342 {
343 return decls;
344 }
345}
346
347Statement SingleStatement() throws ParseException:
348{
349 Statement stmt = null;
350}
351{
352 (
353 stmt = DataverseDeclaration()
354 | stmt = FunctionDeclaration()
355 | stmt = CreateStatement()
356 | stmt = LoadStatement()
357 | stmt = DropStatement()
358 | stmt = WriteStatement()
359 | stmt = SetStatement()
360 | stmt = InsertStatement()
Yingyi Bucb5bf332017-01-02 22:19:50 -0800361 | stmt = UpsertStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700362 | stmt = DeleteStatement()
363 | stmt = UpdateStatement()
364 | stmt = FeedStatement()
365 | stmt = CompactStatement()
366 | stmt = Query()
367 | stmt = RefreshExternalDatasetStatement()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700368 )
369 {
370 return stmt;
371 }
372}
373
374DataverseDecl DataverseDeclaration() throws ParseException:
375{
376 String dvName = null;
377}
378{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400379 <USE> <DATAVERSE> dvName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700380 {
381 defaultDataverse = dvName;
382 return new DataverseDecl(new Identifier(dvName));
383 }
384}
385
386Statement CreateStatement() throws ParseException:
387{
388 String hint = null;
389 boolean dgen = false;
390 Statement stmt = null;
391}
392{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400393 <CREATE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700394 (
395 {
396 hint = getHint(token);
397 if (hint != null && hint.startsWith(DGEN_HINT)) {
398 dgen = true;
399 }
400 }
401 stmt = TypeSpecification(hint, dgen)
402 | stmt = NodegroupSpecification()
403 | stmt = DatasetSpecification()
404 | stmt = IndexSpecification()
405 | stmt = DataverseSpecification()
406 | stmt = FunctionSpecification()
407 | stmt = FeedSpecification()
408 | stmt = FeedPolicySpecification()
409 )
410 {
411 return stmt;
412 }
413}
414
415TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
416{
417 Pair<Identifier,Identifier> nameComponents = null;
418 boolean ifNotExists = false;
419 TypeExpression typeExpr = null;
420}
421{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400422 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
423 <AS> typeExpr = TypeExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700424 {
425 long numValues = -1;
426 String filename = null;
427 if (dgen) {
428 String splits[] = hint.split(" +");
429 if (splits.length != 3) {
430 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
431 }
432 filename = splits[1];
433 numValues = Long.parseLong(splits[2]);
434 }
435 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
436 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
437 }
438}
439
440
441NodegroupDecl NodegroupSpecification() throws ParseException:
442{
443 String name = null;
444 String tmp = null;
445 boolean ifNotExists = false;
446 List<Identifier>ncNames = null;
447}
448{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400449 <NODEGROUP> name = Identifier()
450 ifNotExists = IfNotExists() <ON> tmp = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700451 {
452 ncNames = new ArrayList<Identifier>();
453 ncNames.add(new Identifier(tmp));
454 }
455 ( <COMMA> tmp = Identifier()
456 {
457 ncNames.add(new Identifier(tmp));
458 }
459 )*
460 {
461 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
462 }
463}
464
465DatasetDecl DatasetSpecification() throws ParseException:
466{
467 Pair<Identifier,Identifier> nameComponents = null;
468 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800469 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700470 String adapterName = null;
471 Map<String,String> properties = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700472 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800473 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700474 String nodeGroupName = null;
475 Map<String,String> hints = new HashMap<String,String>();
476 DatasetDecl dsetDecl = null;
477 boolean autogenerated = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800478 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800479 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800480 RecordConstructor withRecord = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700481}
482{
483 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400484 <EXTERNAL> <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800485 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700486 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400487 <USING> adapterName = AdapterName() properties = Configuration()
488 ( <ON> nodeGroupName = Identifier() )?
489 ( <HINTS> hints = Properties() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800490 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700491 {
492 ExternalDetailsDecl edd = new ExternalDetailsDecl();
493 edd.setAdapter(adapterName);
494 edd.setProperties(properties);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800495 try{
496 dsetDecl = new DatasetDecl(nameComponents.first,
497 nameComponents.second,
498 typeComponents.first,
499 typeComponents.second,
500 metaTypeComponents.first,
501 metaTypeComponents.second,
502 nodeGroupName != null? new Identifier(nodeGroupName): null,
503 hints,
504 DatasetType.EXTERNAL,
505 edd,
506 withRecord,
507 ifNotExists);
508 } catch (CompilationException e){
509 throw new ParseException(e.getMessage());
510 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700511 }
512
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300513 | ( <INTERNAL> )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700514 <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800515 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800516 (
517 { String name; }
518 <WITH>
519 name = Identifier()
520 {
521 if(!name.equals("meta")){
522 throw new ParseException("We can only support one additional associated field called \"meta\".");
523 }
524 }
525 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
526 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700527 ifNotExists = IfNotExists()
528 primaryKeyFields = PrimaryKey()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400529 ( <AUTOGENERATED> { autogenerated = true; } )?
530 ( <ON> nodeGroupName = Identifier() )?
531 ( <HINTS> hints = Properties() )?
Till Westmannf3aa19f2017-12-01 17:42:35 -0800532 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
533 ( <WITH> withRecord = RecordConstructor() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700534 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800535 if(filterField!=null && filterField.first!=0){
536 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
537 }
538 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
539 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700540 autogenerated,
Murtadha Hubail2c04ae02017-11-21 15:58:01 +0300541 filterField == null? null : filterField.second);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800542 try{
543 dsetDecl = new DatasetDecl(nameComponents.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700544 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800545 typeComponents.first,
546 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800547 metaTypeComponents.first,
548 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700549 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700550 hints,
551 DatasetType.INTERNAL,
552 idd,
Till Westmannf3aa19f2017-12-01 17:42:35 -0800553 withRecord,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700554 ifNotExists);
Till Westmannf3aa19f2017-12-01 17:42:35 -0800555 } catch (CompilationException e){
556 throw new ParseException(e.getMessage());
557 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700558 }
559 )
560 {
561 return dsetDecl;
562 }
563}
564
565RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
566{
567 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
568 Pair<Identifier,Identifier> nameComponents = null;
569 String datasetName = null;
570}
571{
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +0300572 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400573 <REFRESH> <EXTERNAL> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700574 {
575 redss.setDataverseName(nameComponents.first);
576 redss.setDatasetName(nameComponents.second);
577 return redss;
578 }
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +0300579 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700580}
581
Yingyi Bu391f09e2015-10-29 13:49:39 -0700582CreateIndexStatement IndexSpecification() throws ParseException:
583{
584 CreateIndexStatement cis = new CreateIndexStatement();
585 String indexName = null;
586 boolean ifNotExists = false;
587 Pair<Identifier,Identifier> nameComponents = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -0700588 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700589 IndexParams indexType = null;
590 boolean enforced = false;
Ali Alsuliman8351d252017-09-24 00:43:15 -0700591 boolean isPrimaryIdx = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700592}
593{
Ali Alsuliman8351d252017-09-24 00:43:15 -0700594 (
595 (<INDEX> indexName = Identifier()
596 ifNotExists = IfNotExists()
597 <ON> nameComponents = QualifiedName()
598 <LEFTPAREN> ( fieldPair = OpenField()
599 {
600 cis.addFieldExprPair(fieldPair.second);
601 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700602 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700603 ) (<COMMA> fieldPair = OpenField()
604 {
605 cis.addFieldExprPair(fieldPair.second);
606 cis.addFieldIndexIndicator(fieldPair.first);
607 }
608 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
609 |
610 (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
611 (
612 (indexName = Identifier())? ifNotExists = IfNotExists()
613 )
614 <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
615 )
616 )
617 {
618 if (isPrimaryIdx && indexName == null) {
619 indexName = "primary_idx_" + nameComponents.second;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700620 }
Ali Alsuliman8351d252017-09-24 00:43:15 -0700621 cis.setIndexName(new Identifier(indexName));
622 cis.setIfNotExists(ifNotExists);
623 cis.setDataverseName(nameComponents.first);
624 cis.setDatasetName(nameComponents.second);
625 if (indexType != null) {
626 cis.setIndexType(indexType.type);
627 cis.setGramLength(indexType.gramLength);
628 }
629 cis.setEnforced(enforced);
630 return cis;
631 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700632}
633
634String CompactionPolicy() throws ParseException :
635{
636 String compactionPolicy = null;
637}
638{
639 compactionPolicy = Identifier()
640 {
641 return compactionPolicy;
642 }
643}
644
645String FilterField() throws ParseException :
646{
647 String filterField = null;
648}
649{
650 filterField = Identifier()
651 {
652 return filterField;
653 }
654}
655
656IndexParams IndexType() throws ParseException:
657{
658 IndexType type = null;
659 int gramLength = 0;
660}
661{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400662 (
663 <BTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700664 {
665 type = IndexType.BTREE;
666 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400667 |<RTREE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700668 {
669 type = IndexType.RTREE;
670 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400671 |<KEYWORD>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700672 {
673 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
674 }
Taewoo Kimc49405a2017-01-04 00:30:43 -0800675 |<FULLTEXT>
676 {
677 type = IndexType.SINGLE_PARTITION_WORD_INVIX;
678 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400679 |<NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700680 {
681 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
682 gramLength = Integer.valueOf(token.image);
683 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400684 <RIGHTPAREN>
685 )
686 {
687 return new IndexParams(type, gramLength);
688 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700689}
690
691CreateDataverseStatement DataverseSpecification() throws ParseException :
692{
693 String dvName = null;
694 boolean ifNotExists = false;
695 String format = null;
696}
697{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400698 <DATAVERSE> dvName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700699 ifNotExists = IfNotExists()
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400700 ( <WITH> <FORMAT> format = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700701 {
702 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
703 }
704}
705
706CreateFunctionStatement FunctionSpecification() throws ParseException:
707{
708 FunctionSignature signature;
709 boolean ifNotExists = false;
710 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
711 String functionBody;
712 VarIdentifier var = null;
713 Expression functionBodyExpr;
714 Token beginPos;
715 Token endPos;
716 FunctionName fctName = null;
717
718 createNewScope();
719}
720{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400721 <FUNCTION> fctName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700722 ifNotExists = IfNotExists()
723 paramList = ParameterList()
724 <LEFTBRACE>
725 {
726 beginPos = token;
727 }
728 functionBodyExpr = Expression() <RIGHTBRACE>
729 {
730 endPos = token;
731 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
732 // TODO use fctName.library
733 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
734 getCurrentScope().addFunctionDescriptor(signature, false);
735 removeCurrentScope();
Steven Glenn Jacobs665e9fe2017-12-27 10:30:39 -0800736 return new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700737 }
738}
739
740CreateFeedStatement FeedSpecification() throws ParseException:
741{
742 Pair<Identifier,Identifier> nameComponents = null;
743 boolean ifNotExists = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700744 CreateFeedStatement cfs = null;
745 Pair<Identifier,Identifier> sourceNameComponents = null;
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800746 RecordConstructor withRecord = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700747}
748{
Abdullah Alamoudifff200c2017-02-18 20:32:14 -0800749 <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
Xikui Wang5a61b2a2018-01-02 14:14:03 -0800750 <WITH> withRecord = RecordConstructor()
751 {
752 try {
753 cfs = new CreateFeedStatement(nameComponents, withRecord, ifNotExists);
754 return cfs;
755 } catch (AlgebricksException e) {
756 throw new ParseException(e.getMessage());
757 }
758 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700759}
760
761CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
762{
Michael Blowd6cf6412016-06-30 02:44:35 -0400763 String policyName = null;
764 String basePolicyName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700765 String sourcePolicyFile = null;
766 String definition = null;
767 boolean ifNotExists = false;
768 Map<String,String> properties = null;
769 CreateFeedPolicyStatement cfps = null;
770}
771{
772 (
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400773 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
774 <FROM>
775 (
776 <POLICY> basePolicyName = Identifier() properties = Configuration() ( <DEFINITION> definition = StringLiteral())?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700777 {
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400778 cfps = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700779 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300780 |<PATH> sourcePolicyFile = StringLiteral() (<DEFINITION> definition = StringLiteral())?
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400781 {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700782 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400783 }
784 )
Yingyi Bu391f09e2015-10-29 13:49:39 -0700785 )
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400786 {
787 return cfps;
788 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700789}
790
791
792
793List<VarIdentifier> ParameterList() throws ParseException:
794{
795 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
796 VarIdentifier var = null;
797}
798{
799 <LEFTPAREN> (<VARIABLE>
800 {
801 var = new VarIdentifier();
802 var.setValue(token.image);
803 paramList.add(var);
804 getCurrentScope().addNewVarSymbolToScope(var);
805 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400806 ( <COMMA> <VARIABLE>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700807 {
808 var = new VarIdentifier();
809 var.setValue(token.image);
810 paramList.add(var);
811 getCurrentScope().addNewVarSymbolToScope(var);
812 }
813 )*)? <RIGHTPAREN>
814 {
815 return paramList;
816 }
817}
818
819boolean IfNotExists() throws ParseException:
820{
821}
822{
Yingyi Budcd91122016-08-10 12:13:36 -0700823 (
824 LOOKAHEAD(1)
825 <IF>
826 <IDENTIFIER>
827 (
828 {
829 if(!token.image.equals("not")){
830 throw new ParseException("Expect word \"not\" at line " + token.beginLine + ", column "
831 + token.beginColumn +"!");
832 }
833 }
834 )
835 <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700836 {
837 return true;
838 }
839 )?
840 {
841 return false;
842 }
843}
844
Xikui Wang9d63f622017-05-18 17:50:44 -0700845void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700846{
847 FunctionName functioName = null;
Xikui Wang261dc6d2017-03-29 21:23:15 -0700848 String fqFunctionName = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700849}
850{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400851 <APPLY> <FUNCTION> functioName = FunctionName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700852 {
Xikui Wang261dc6d2017-03-29 21:23:15 -0700853 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
854 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
855 }
856 (
857 <COMMA> functioName = FunctionName()
858 {
859 fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
860 funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
861 }
862 )*
Yingyi Bu391f09e2015-10-29 13:49:39 -0700863}
864
865String GetPolicy() throws ParseException:
866{
867 String policy = null;
868}
869{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400870 <USING> <POLICY> policy = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700871 {
872 return policy;
873 }
874
875}
876
877FunctionSignature FunctionSignature() throws ParseException:
878{
879 FunctionName fctName = null;
880 int arity = 0;
881}
882{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400883 fctName = FunctionName() <SYMBOLAT> <INTEGER_LITERAL>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700884 {
885 arity = new Integer(token.image);
886 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
887 throw new ParseException(" invalid arity:" + arity);
888 }
889
890 // TODO use fctName.library
891 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
892 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
893 }
894}
895
Yingyi Buc9bfe252016-03-01 00:02:40 -0800896Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700897{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800898 Pair<Integer, List<String>> tmp = null;
899 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
900 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700901}
902{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400903 <PRIMARY> <KEY> tmp = NestedField()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700904 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800905 keyFieldSourceIndicators.add(tmp.first);
906 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700907 }
908 ( <COMMA> tmp = NestedField()
909 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800910 keyFieldSourceIndicators.add(tmp.first);
911 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700912 }
913 )*
914 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800915 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700916 }
917}
918
919Statement DropStatement() throws ParseException:
920{
921 String id = null;
922 Pair<Identifier,Identifier> pairId = null;
923 Triple<Identifier,Identifier,Identifier> tripleId = null;
924 FunctionSignature funcSig = null;
925 boolean ifExists = false;
926 Statement stmt = null;
927}
928{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400929 <DROP>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700930 (
931 <DATASET> pairId = QualifiedName() ifExists = IfExists()
932 {
Yingyi Buab817482016-08-19 21:29:31 -0700933 stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700934 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400935 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700936 {
937 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
938 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400939 | <NODEGROUP> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700940 {
941 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
942 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400943 | <TYPE> pairId = TypeName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700944 {
945 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
946 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400947 | <DATAVERSE> id = Identifier() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700948 {
949 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
950 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400951 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700952 {
953 stmt = new FunctionDropStatement(funcSig, ifExists);
954 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +0400955 | <FEED> pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700956 {
957 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
958 }
Abdullah Alamoudi5dc73ed2016-07-28 05:03:13 +0300959 | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
960 {
961 stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
962 }
Yingyi Bu391f09e2015-10-29 13:49:39 -0700963 )
964 {
965 return stmt;
966 }
967}
968
969boolean IfExists() throws ParseException :
970{
971}
972{
Yingyi Budcd91122016-08-10 12:13:36 -0700973 (
974 LOOKAHEAD(1)
975 <IF> <EXISTS>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700976 {
977 return true;
978 }
979 )?
980 {
981 return false;
982 }
983}
984
985InsertStatement InsertStatement() throws ParseException:
986{
987 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800988 VariableExpr var = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700989 Query query;
Yingyi Bucb5bf332017-01-02 22:19:50 -0800990 Expression returnExpression = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700991}
992{
Yingyi Bucb5bf332017-01-02 22:19:50 -0800993 <INSERT> <INTO> <DATASET> nameComponents = QualifiedName()
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -0700994 (<AS> var = Variable())?
995 {
996 if(var != null){
997 getCurrentScope().addNewVarSymbolToScope(var.getVar());
998 }
999 }
Yingyi Bucb5bf332017-01-02 22:19:50 -08001000 query = Query() ( <RETURNING> returnExpression = Expression())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001001 {
Yingyi Bucb5bf332017-01-02 22:19:50 -08001002 checkBindingVariable(returnExpression, var, query);
Yingyi Bucaea8f02015-11-16 15:12:15 -08001003 query.setTopLevel(true);
Yingyi Bucb5bf332017-01-02 22:19:50 -08001004 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1005 returnExpression);
1006 }
1007}
1008
1009UpsertStatement UpsertStatement() throws ParseException:
1010{
1011 Pair<Identifier,Identifier> nameComponents = null;
1012 VariableExpr var = null;
1013 Query query;
1014 Expression returnExpression = null;
1015}
1016{
1017 <UPSERT> <INTO> <DATASET> nameComponents = QualifiedName()
1018 (<AS> var = Variable())?
1019 {
1020 if(var != null){
1021 getCurrentScope().addNewVarSymbolToScope(var.getVar());
1022 }
1023 }
1024 query = Query() ( <RETURNING> returnExpression = Expression())?
1025 {
1026 checkBindingVariable(returnExpression, var, query);
1027 query.setTopLevel(true);
1028 return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
1029 returnExpression);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001030 }
1031}
1032
1033DeleteStatement DeleteStatement() throws ParseException:
1034{
1035 VariableExpr var = null;
1036 Expression condition = null;
1037 Pair<Identifier, Identifier> nameComponents;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001038}
1039{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001040 <DELETE> var = Variable()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001041 {
1042 getCurrentScope().addNewVarSymbolToScope(var.getVar());
1043 }
1044 <FROM> <DATASET> nameComponents = QualifiedName()
1045 (<WHERE> condition = Expression())?
1046 {
1047 // First we get the dataverses and datasets that we want to lock
Yingyi Bu391f09e2015-10-29 13:49:39 -07001048 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
Abdullah Alamoudi6eb01752017-04-01 21:51:19 -07001049 condition, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001050 }
1051}
1052
1053UpdateStatement UpdateStatement() throws ParseException:
1054{
1055 VariableExpr vars;
1056 Expression target;
1057 Expression condition;
1058 UpdateClause uc;
1059 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
1060}
1061{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001062 <UPDATE> vars = Variable() <IN> target = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001063 <WHERE> condition = Expression()
1064 <LEFTPAREN> (uc = UpdateClause()
1065 {
1066 ucs.add(uc);
1067 }
1068 (<COMMA> uc = UpdateClause()
1069 {
1070 ucs.add(uc);
1071 }
1072 )*) <RIGHTPAREN>
1073 {
1074 return new UpdateStatement(vars, target, condition, ucs);
1075 }
1076}
1077
1078UpdateClause UpdateClause() throws ParseException:
1079{
1080 Expression target = null;
1081 Expression value = null ;
1082 InsertStatement is = null;
1083 DeleteStatement ds = null;
1084 UpdateStatement us = null;
1085 Expression condition = null;
1086 UpdateClause ifbranch = null;
1087 UpdateClause elsebranch = null;
1088}
1089{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001090 (<SET> target = Expression() <ASSIGN> value = Expression()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001091 | is = InsertStatement()
1092 | ds = DeleteStatement()
1093 | us = UpdateStatement()
1094 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
1095 <THEN> ifbranch = UpdateClause()
1096 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1097 {
1098 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1099 }
1100 )
1101}
1102
1103Statement SetStatement() throws ParseException:
1104{
1105 String pn = null;
1106 String pv = null;
1107}
1108{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001109 <SET> pn = Identifier() pv = StringLiteral()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001110 {
1111 return new SetStatement(pn, pv);
1112 }
1113}
1114
1115Statement WriteStatement() throws ParseException:
1116{
1117 String nodeName = null;
1118 String fileName = null;
1119 Query query;
1120 String writerClass = null;
1121 Pair<Identifier,Identifier> nameComponents = null;
1122}
1123{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001124 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = StringLiteral()
1125 ( <USING> writerClass = StringLiteral() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001126 {
1127 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1128 }
1129}
1130
1131LoadStatement LoadStatement() throws ParseException:
1132{
1133 Identifier dataverseName = null;
1134 Identifier datasetName = null;
1135 boolean alreadySorted = false;
1136 String adapterName;
1137 Map<String,String> properties;
1138 Pair<Identifier,Identifier> nameComponents = null;
1139}
1140{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001141 <LOAD> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001142 {
1143 dataverseName = nameComponents.first;
1144 datasetName = nameComponents.second;
1145 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001146 <USING> adapterName = AdapterName() properties = Configuration()
1147 (<PRESORTED>
Yingyi Bu391f09e2015-10-29 13:49:39 -07001148 {
1149 alreadySorted = true;
1150 }
1151 )?
1152 {
1153 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1154 }
1155}
1156
1157
1158String AdapterName() throws ParseException :
1159{
1160 String adapterName = null;
1161}
1162{
1163 adapterName = Identifier()
1164 {
1165 return adapterName;
1166 }
1167}
1168
1169Statement CompactStatement() throws ParseException:
1170{
1171 Pair<Identifier,Identifier> nameComponents = null;
1172 Statement stmt = null;
1173}
1174{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001175 <COMPACT> <DATASET> nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001176 {
1177 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1178 }
1179 {
1180 return stmt;
1181 }
1182}
1183
1184Statement FeedStatement() throws ParseException:
1185{
1186 Pair<Identifier,Identifier> feedNameComponents = null;
1187 Pair<Identifier,Identifier> datasetNameComponents = null;
1188
1189 Map<String,String> configuration = null;
Xikui Wang9d63f622017-05-18 17:50:44 -07001190 List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07001191 Statement stmt = null;
1192 String policy = null;
1193}
1194{
1195 (
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001196 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName()
Xikui Wang9d63f622017-05-18 17:50:44 -07001197 (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001198 {
Xikui Wangf6741682018-02-22 19:17:17 -08001199 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions, policy, null, getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001200 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001201 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001202 {
1203 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1204 }
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08001205 | <START> <FEED> feedNameComponents = QualifiedName()
1206 {
1207 stmt = new StartFeedStatement (feedNameComponents);
1208 }
1209 | <STOP> <FEED> feedNameComponents = QualifiedName()
1210 {
1211 stmt = new StopFeedStatement (feedNameComponents);
1212 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001213 )
1214 {
1215 return stmt;
1216 }
1217}
1218
1219Map<String,String> Configuration() throws ParseException :
1220{
1221 Map<String,String> configuration = new LinkedHashMap<String,String>();
1222 Pair<String, String> keyValuePair = null;
1223}
1224{
1225 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1226 {
1227 configuration.put(keyValuePair.first, keyValuePair.second);
1228 }
1229 ( <COMMA> keyValuePair = KeyValuePair()
1230 {
1231 configuration.put(keyValuePair.first, keyValuePair.second);
1232 }
1233 )* )? <RIGHTPAREN>
1234 {
1235 return configuration;
1236 }
1237}
1238
1239Pair<String, String> KeyValuePair() throws ParseException:
1240{
1241 String key;
1242 String value;
1243}
1244{
1245 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
1246 {
1247 return new Pair<String, String>(key, value);
1248 }
1249}
1250
1251Map<String,String> Properties() throws ParseException:
1252{
1253 Map<String,String> properties = new HashMap<String,String>();
1254 Pair<String, String> property;
1255}
1256{
1257 ( <LEFTPAREN> property = Property()
1258 {
1259 properties.put(property.first, property.second);
1260 }
1261 ( <COMMA> property = Property()
1262 {
1263 properties.put(property.first, property.second);
1264 }
1265 )* <RIGHTPAREN> )?
1266 {
1267 return properties;
1268 }
1269}
1270
1271Pair<String, String> Property() throws ParseException:
1272{
1273 String key;
1274 String value;
1275}
1276{
1277 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
1278 {
1279 try {
1280 value = "" + Long.valueOf(token.image);
1281 } catch (NumberFormatException nfe) {
1282 throw new ParseException("inapproriate value: " + token.image);
1283 }
1284 }
1285 )
1286 {
1287 return new Pair<String, String>(key.toUpperCase(), value);
1288 }
1289}
1290
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001291IndexedTypeExpression IndexedTypeExpr() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001292{
1293 TypeExpression typeExpr = null;
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001294 boolean isUnknownable = false;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001295}
1296{
1297 (
1298 typeExpr = TypeReference()
1299 | typeExpr = OrderedListTypeDef()
1300 | typeExpr = UnorderedListTypeDef()
1301 )
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001302 ( <QUES> { isUnknownable = true; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001303 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001304 return new IndexedTypeExpression(typeExpr, isUnknownable);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001305 }
1306}
1307
1308TypeExpression TypeExpr() throws ParseException:
1309{
1310 TypeExpression typeExpr = null;
1311}
1312{
1313 (
1314 typeExpr = RecordTypeDef()
1315 | typeExpr = TypeReference()
1316 | typeExpr = OrderedListTypeDef()
1317 | typeExpr = UnorderedListTypeDef()
1318 )
1319 {
1320 return typeExpr;
1321 }
1322}
1323
1324RecordTypeDefinition RecordTypeDef() throws ParseException:
1325{
1326 RecordTypeDefinition recType = new RecordTypeDefinition();
1327 RecordTypeDefinition.RecordKind recordKind = null;
1328}
1329{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001330 ( <CLOSED>{ recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1331 | <OPEN>{ recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001332 <LEFTBRACE>
1333 {
1334 String hint = getHint(token);
1335 if (hint != null) {
1336 String splits[] = hint.split(" +");
1337 if (splits[0].equals(GEN_FIELDS_HINT)) {
1338 if (splits.length != 5) {
1339 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1340 }
1341 if (!splits[1].equals("int")) {
1342 throw new ParseException("The only supported type for gen-fields is int.");
1343 }
1344 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1345 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1346 recType.setUndeclaredFieldsDataGen(ufdg);
1347 }
1348 }
1349
1350 }
1351 (
1352 RecordField(recType)
1353 ( <COMMA> RecordField(recType) )*
1354 )?
1355 <RIGHTBRACE>
1356 {
1357 if (recordKind == null) {
1358 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1359 }
1360 recType.setRecordKind(recordKind);
1361 return recType;
1362 }
1363}
1364
1365void RecordField(RecordTypeDefinition recType) throws ParseException:
1366{
1367 String fieldName;
1368 TypeExpression type = null;
1369 boolean nullable = false;
1370}
1371{
1372 fieldName = Identifier()
1373 {
1374 String hint = getHint(token);
1375 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1376 }
1377 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1378 {
1379 recType.addField(fieldName, type, nullable, rfdg);
1380 }
1381}
1382
1383TypeReferenceExpression TypeReference() throws ParseException:
1384{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001385 Pair<Identifier,Identifier> id = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001386}
1387{
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001388 id = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001389 {
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001390 if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
1391 id.second.setValue("int64");
Yingyi Bu391f09e2015-10-29 13:49:39 -07001392 }
1393
Abdullah Alamoudie4b318f2016-09-19 13:31:25 +03001394 return new TypeReferenceExpression(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001395 }
1396}
1397
1398OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1399{
1400 TypeExpression type = null;
1401}
1402{
1403 <LEFTBRACKET>
1404 ( type = TypeExpr() )
1405 <RIGHTBRACKET>
1406 {
1407 return new OrderedListTypeDefinition(type);
1408 }
1409}
1410
1411
1412UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1413{
1414 TypeExpression type = null;
1415}
1416{
1417 <LEFTDBLBRACE>
1418 ( type = TypeExpr() )
1419 <RIGHTDBLBRACE>
1420 {
1421 return new UnorderedListTypeDefinition(type);
1422 }
1423}
1424
1425FunctionName FunctionName() throws ParseException:
1426{
1427 String first = null;
1428 String second = null;
1429 String third = null;
1430 boolean secondAfterDot = false;
1431}
1432{
Michael Blowd6cf6412016-06-30 02:44:35 -04001433 first = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001434 {
1435 FunctionName result = new FunctionName();
1436 result.hint = getHint(token);
Michael Blowd6cf6412016-06-30 02:44:35 -04001437 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001438 ( <DOT> second = Identifier()
1439 {
1440 secondAfterDot = true;
1441 }
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001442 ( <SYMBOLHASH> third = Identifier())? | <SYMBOLHASH> second = Identifier() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001443 {
1444 if (second == null) {
1445 result.dataverse = defaultDataverse;
1446 result.library = null;
1447 result.function = first;
1448 } else if (third == null) {
1449 if (secondAfterDot) {
1450 result.dataverse = first;
1451 result.library = null;
1452 result.function = second;
1453 } else {
1454 result.dataverse = defaultDataverse;
1455 result.library = first;
1456 result.function = second;
1457 }
1458 } else {
1459 result.dataverse = first;
1460 result.library = second;
1461 result.function = third;
1462 }
1463
1464 if (result.function.equalsIgnoreCase("int")) {
1465 result.function = "int64";
1466 }
1467 return result;
1468 }
1469}
1470
1471
1472Pair<Identifier,Identifier> TypeName() throws ParseException:
1473{
1474 Pair<Identifier,Identifier> name = null;
1475}
1476{
1477 name = QualifiedName()
1478 {
1479 if (name.first == null) {
1480 name.first = new Identifier(defaultDataverse);
1481 }
1482 return name;
1483 }
1484}
1485
1486String Identifier() throws ParseException:
1487{
1488 String lit = null;
1489}
1490{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001491 ((<IDENTIFIER>)
Yingyi Bu391f09e2015-10-29 13:49:39 -07001492 {
1493 return token.image;
1494 }
1495 | lit = StringLiteral()
1496 {
1497 return lit;
1498 }
1499 )
1500}
1501
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001502Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001503{
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001504 IndexedTypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001505 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001506}
1507{
1508 fieldList = NestedField()
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001509 ( <COLON> fieldType = IndexedTypeExpr() )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001510 {
Dmitry Lychagin8ba59442017-06-16 14:19:45 -07001511 return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
1512 (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001513 }
1514}
1515
Yingyi Buc9bfe252016-03-01 00:02:40 -08001516Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001517{
1518 List<String> exprList = new ArrayList<String>();
1519 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001520 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001521}
1522{
1523 lit = Identifier()
1524 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001525 boolean meetParens = false;
1526 }
1527 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001528 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001529 <LEFTPAREN><RIGHTPAREN>
1530 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001531 if(!lit.equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001532 throw new ParseException("The string before () has to be \"meta\".");
1533 }
1534 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001535 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001536 }
1537 )?
1538 {
1539 if(!meetParens){
1540 exprList.add(lit);
1541 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001542 }
1543 (<DOT>
1544 lit = Identifier()
1545 {
1546 exprList.add(lit);
1547 }
1548 )*
1549 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001550 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001551 }
1552}
1553
1554
1555
1556String StringLiteral() throws ParseException:
1557{
1558}
1559{
1560 <STRING_LITERAL>
1561 {
1562 return removeQuotesAndEscapes(token.image);
1563 }
1564}
1565
1566Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1567{
1568 String first = null;
1569 String second = null;
1570}
1571{
1572 first = Identifier() (<DOT> second = Identifier())?
1573 {
1574 Identifier id1 = null;
1575 Identifier id2 = null;
1576 if (second == null) {
1577 id2 = new Identifier(first);
1578 } else
1579 {
1580 id1 = new Identifier(first);
1581 id2 = new Identifier(second);
1582 }
1583 return new Pair<Identifier,Identifier>(id1, id2);
1584 }
1585}
1586
1587Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1588{
1589 String first = null;
1590 String second = null;
1591 String third = null;
1592}
1593{
1594 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1595 {
1596 Identifier id1 = null;
1597 Identifier id2 = null;
1598 Identifier id3 = null;
1599 if (third == null) {
1600 id2 = new Identifier(first);
1601 id3 = new Identifier(second);
1602 } else {
1603 id1 = new Identifier(first);
1604 id2 = new Identifier(second);
1605 id3 = new Identifier(third);
1606 }
1607 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1608 }
1609}
1610
1611FunctionDecl FunctionDeclaration() throws ParseException:
1612{
1613 FunctionDecl funcDecl;
1614 FunctionSignature signature;
1615 String functionName;
1616 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1617 Expression funcBody;
1618 createNewScope();
1619}
1620{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04001621 <DECLARE> <FUNCTION> functionName = Identifier()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001622 paramList = ParameterList()
1623 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1624 {
1625 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1626 getCurrentScope().addFunctionDescriptor(signature, false);
1627 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1628 removeCurrentScope();
1629 return funcDecl;
1630 }
1631}
1632
1633
1634Query Query() throws ParseException:
1635{
Till Westmannef3f0272016-07-27 18:34:01 -07001636 Query query = new Query(false);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001637 Expression expr;
1638}
1639{
1640 expr = Expression()
1641 {
1642 query.setBody(expr);
1643 query.setVarCounter(getVarCounter());
Yingyi Bu391f09e2015-10-29 13:49:39 -07001644 return query;
1645 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001646}
1647
1648
1649
1650Expression Expression():
1651{
1652 Expression expr = null;
1653 Expression exprP = null;
1654}
1655{
1656(
1657
1658//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1659 expr = OperatorExpr()
1660 | expr = IfThenElse()
1661 | expr = FLWOGR()
1662 | expr = QuantifiedExpression()
1663
1664
1665)
1666 {
1667 return (exprP==null) ? expr : exprP;
1668 }
1669}
1670
1671
1672
1673Expression OperatorExpr()throws ParseException:
1674{
1675 OperatorExpr op = null;
1676 Expression operand = null;
1677}
1678{
1679 operand = AndExpr()
1680 (
1681
1682 <OR>
1683 {
1684 if (op == null) {
1685 op = new OperatorExpr();
1686 op.addOperand(operand);
1687 op.setCurrentop(true);
1688 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001689 try{
1690 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001691 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001692 throw new ParseException(e.getMessage());
1693 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001694 }
1695
1696 operand = AndExpr()
1697 {
1698 op.addOperand(operand);
1699 }
1700
1701 )*
1702
1703 {
1704 return op==null? operand: op;
1705 }
1706}
1707
1708Expression AndExpr()throws ParseException:
1709{
1710 OperatorExpr op = null;
1711 Expression operand = null;
1712}
1713{
1714 operand = RelExpr()
1715 (
1716
1717 <AND>
1718 {
1719 if (op == null) {
1720 op = new OperatorExpr();
1721 op.addOperand(operand);
1722 op.setCurrentop(true);
1723 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001724 try{
1725 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001726 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001727 throw new ParseException(e.getMessage());
1728 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001729 }
1730
1731 operand = RelExpr()
1732 {
1733 op.addOperand(operand);
1734 }
1735
1736 )*
1737
1738 {
1739 return op==null? operand: op;
1740 }
1741}
1742
1743
1744
1745Expression RelExpr()throws ParseException:
1746{
1747 OperatorExpr op = null;
1748 Expression operand = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001749 IExpressionAnnotation annotation = null;
1750}
1751{
1752 operand = AddExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001753
1754 (
1755 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1756 {
1757 String mhint = getHint(token);
1758 if (mhint != null) {
1759 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1760 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1761 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1762 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1763 }
1764 }
1765 if (op == null) {
1766 op = new OperatorExpr();
Shiva2ea73232019-10-09 18:04:05 -07001767 op.addOperand(operand);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001768 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001769 }
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 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001779 if (operand instanceof VariableExpr) {
1780 String hint = getHint(token);
Shiva2ea73232019-10-09 18:04:05 -07001781 if (hint != null && hint.equals(HASH_BROADCAST_JOIN_HINT)) {
1782 annotation = new BroadcastExpressionAnnotation();
1783 annotation.setObject(BroadcastExpressionAnnotation.BroadcastSide.RIGHT);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001784 }
1785 }
Shiva2ea73232019-10-09 18:04:05 -07001786 op.addOperand(operand);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001787 }
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;
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07001834 OperatorType opType = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001835 Expression operand = null;
1836}
1837{
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001838 operand = ExponentExpr()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001839
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07001840 ( (
1841 <MUL> { opType = OperatorType.MUL; } |
1842 <DIVIDE> { opType = OperatorType.DIVIDE; } |
1843 <DIV> { opType = OperatorType.DIV; } |
1844 ( <MOD> | <PERCENT> ) { opType = OperatorType.MOD; }
1845 )
Yingyi Bu391f09e2015-10-29 13:49:39 -07001846 {
1847 if (op == null) {
1848 op = new OperatorExpr();
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001849 op.addOperand(operand);
1850 op.setCurrentop(true);
1851 }
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07001852 op.addOperator(opType);
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001853 }
1854 operand = ExponentExpr()
1855 {
1856 op.addOperand(operand);
1857 }
1858 )*
1859
1860 {
1861 return op==null?operand:op;
1862 }
1863}
1864
1865Expression ExponentExpr()throws ParseException:
1866{
1867 OperatorExpr op = null;
1868 Expression operand = null;
1869}
1870{
1871 operand = UnionExpr()
1872
1873 ( <CARET>
1874 {
1875 if (op == null) {
1876 op = new OperatorExpr();
1877 op.addOperand(operand);
1878 op.setCurrentop(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001879 }
Yingyi Bu196db5d2016-07-15 19:07:20 -07001880 try{
1881 op.addOperator(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001882 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001883 throw new ParseException(e.getMessage());
1884 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001885 }
1886 operand = UnionExpr()
1887 {
1888 op.addOperand(operand);
1889 }
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001890 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001891
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001892 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07001893 return op==null?operand:op;
Yingyi Bu79ccdac2016-07-26 23:49:24 -07001894 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001895}
1896
1897Expression UnionExpr() throws ParseException:
1898{
1899 UnionExpr union = null;
1900 Expression operand1 = null;
1901 Expression operand2 = null;
1902}
1903{
1904 operand1 = UnaryExpr()
1905 (<UNION>
1906 (operand2 = UnaryExpr()) {
1907 if (union == null) {
1908 union = new UnionExpr();
1909 union.addExpr(operand1);
1910 }
1911 union.addExpr(operand2);
1912 } )*
1913 {
1914 return (union == null)? operand1: union;
1915 }
1916}
1917
1918Expression UnaryExpr() throws ParseException:
1919{
Yingyi Bu196db5d2016-07-15 19:07:20 -07001920 UnaryExpr uexpr = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001921 Expression expr = null;
1922}
1923{
1924 ( (<PLUS> | <MINUS>)
1925 {
1926 uexpr = new UnaryExpr();
Yingyi Bu196db5d2016-07-15 19:07:20 -07001927 try{
1928 uexpr.setExprType(token.image);
Taewoo Kime65e6ca2017-01-14 17:53:28 -08001929 } catch (CompilationException e){
Yingyi Bu196db5d2016-07-15 19:07:20 -07001930 throw new ParseException(e.getMessage());
1931 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001932 }
1933 )?
1934
1935 expr = ValueExpr()
1936 {
1937 if(uexpr!=null){
1938 ((UnaryExpr)uexpr).setExpr(expr);
1939 return uexpr;
1940 }
1941 else{
1942 return expr;
1943 }
1944 }
1945}
1946
1947Expression ValueExpr()throws ParseException:
1948{
1949 Expression expr = null;
1950 Identifier ident = null;
1951 AbstractAccessor fa = null;
1952 Expression indexExpr = null;
1953}
1954{
1955 expr = PrimaryExpr() ( ident = Field()
1956 {
1957 fa = (fa == null ? new FieldAccessor(expr, ident)
1958 : new FieldAccessor(fa, ident));
1959 }
1960 | indexExpr = Index()
1961 {
1962 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1963 : new IndexAccessor(fa, indexExpr));
1964 }
1965 )*
1966 {
1967 return fa == null ? expr : fa;
1968 }
1969}
1970
1971Identifier Field() throws ParseException:
1972{
1973 String ident = null;
1974}
1975{
1976 <DOT> ident = Identifier()
1977 {
1978 return new Identifier(ident);
1979 }
1980}
1981
1982Expression Index() throws ParseException:
1983{
1984 Expression expr = null;
1985}
1986{
1987 <LEFTBRACKET> ( expr = Expression()
1988 {
1989 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1990 {
1991 Literal lit = ((LiteralExpr)expr).getValue();
1992 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1993 lit.getLiteralType() != Literal.Type.LONG) {
1994 throw new ParseException("Index should be an INTEGER");
1995 }
1996 }
1997 }
1998
1999 | <QUES> // ANY
2000
2001 )
2002
2003 <RIGHTBRACKET>
2004 {
2005 return expr;
2006 }
2007}
2008
2009
2010Expression PrimaryExpr()throws ParseException:
2011{
2012 Expression expr = null;
2013}
2014{
2015 ( LOOKAHEAD(2)
2016 expr = FunctionCallExpr()
2017 | expr = Literal()
2018 | expr = DatasetAccessExpression()
2019 | expr = VariableRef()
2020 {
2021 if(((VariableExpr)expr).getIsNewVar() == true)
2022 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
2023 }
2024 | expr = ListConstructor()
2025 | expr = RecordConstructor()
2026 | expr = ParenthesizedExpression()
2027 )
2028 {
2029 return expr;
2030 }
2031}
2032
2033Expression Literal() throws ParseException:
2034{
2035 LiteralExpr lit = new LiteralExpr();
2036 String str = null;
2037}
2038{
2039 ( str = StringLiteral()
2040 {
2041 lit.setValue(new StringLiteral(str));
2042 }
2043 | <INTEGER_LITERAL>
2044 {
2045 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
2046 }
2047 | <FLOAT_LITERAL>
2048 {
2049 lit.setValue(new FloatLiteral(new Float(token.image)));
2050 }
2051 | <DOUBLE_LITERAL>
2052 {
2053 lit.setValue(new DoubleLiteral(new Double(token.image)));
2054 }
Yingyi Bu535d86b2016-05-23 16:44:25 -07002055 | <MISSING>
2056 {
2057 lit.setValue(MissingLiteral.INSTANCE);
2058 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07002059 | <NULL>
2060 {
2061 lit.setValue(NullLiteral.INSTANCE);
2062 }
2063 | <TRUE>
2064 {
2065 lit.setValue(TrueLiteral.INSTANCE);
2066 }
2067 | <FALSE>
2068 {
2069 lit.setValue(FalseLiteral.INSTANCE);
2070 }
2071 )
2072 {
2073 return lit;
2074 }
2075}
2076
2077
2078VariableExpr VariableRef() throws ParseException:
2079{
2080 VariableExpr varExp = new VariableExpr();
2081 VarIdentifier var = new VarIdentifier();
2082}
2083{
2084 <VARIABLE>
2085 {
2086 String varName = token.image;
2087 Identifier ident = lookupSymbol(varName);
2088 if (isInForbiddenScopes(varName)) {
2089 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.");
2090 }
2091 if(ident != null) { // exist such ident
2092 varExp.setIsNewVar(false);
2093 varExp.setVar((VarIdentifier)ident);
2094 } else {
2095 varExp.setVar(var);
2096 }
2097 var.setValue(varName);
2098 return varExp;
2099 }
2100}
2101
2102
2103VariableExpr Variable() throws ParseException:
2104{
2105 VariableExpr varExp = new VariableExpr();
2106 VarIdentifier var = new VarIdentifier();
2107}
2108{
2109 <VARIABLE>
2110 {
2111 Identifier ident = lookupSymbol(token.image);
2112 if(ident != null) { // exist such ident
2113 varExp.setIsNewVar(false);
2114 }
2115 varExp.setVar(var);
2116 var.setValue(token.image);
2117 return varExp;
2118 }
2119}
2120
2121Expression ListConstructor() throws ParseException:
2122{
2123 Expression expr = null;
2124}
2125{
2126 (
2127 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
2128 )
2129
2130 {
2131 return expr;
2132 }
2133}
2134
2135
2136ListConstructor OrderedListConstructor() throws ParseException:
2137{
2138 ListConstructor expr = new ListConstructor();
2139 List<Expression> exprList = null;
2140 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
2141}
2142{
2143 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
2144 {
2145 expr.setExprList(exprList);
2146 return expr;
2147 }
2148}
2149
2150ListConstructor UnorderedListConstructor() throws ParseException:
2151{
2152 ListConstructor expr = new ListConstructor();
2153 List<Expression> exprList = null;
2154 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
2155}
2156{
2157 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2158 {
2159 expr.setExprList(exprList);
2160 return expr;
2161 }
2162}
2163
2164List<Expression> ExpressionList() throws ParseException:
2165{
2166 Expression expr = null;
2167 List<Expression> list = null;
2168 List<Expression> exprList = new ArrayList<Expression>();
2169}
2170{
2171 (
2172 expr = Expression() { exprList.add(expr); }
2173 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2174 )?
2175 (LOOKAHEAD(1) Comma())?
2176 {
2177 return exprList;
2178 }
2179}
2180
2181void Comma():
2182{}
2183{
2184 <COMMA>
2185}
2186
2187RecordConstructor RecordConstructor() throws ParseException:
2188{
2189 RecordConstructor expr = new RecordConstructor();
2190 FieldBinding tmp = null;
2191 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2192}
2193{
2194 <LEFTBRACE> (tmp = FieldBinding()
2195 {
2196 fbList.add(tmp);
2197 }
2198 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2199 {
2200 expr.setFbList(fbList);
2201 return expr;
2202 }
2203}
2204
2205FieldBinding FieldBinding() throws ParseException:
2206{
Yingyi Bu391f09e2015-10-29 13:49:39 -07002207 Expression left, right;
2208}
2209{
2210 left = Expression() <COLON> right = Expression()
2211 {
Dmitry Lychagin5cdaa5d2018-02-21 11:11:26 -08002212 return new FieldBinding(left, right);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002213 }
2214}
2215
2216
2217Expression FunctionCallExpr() throws ParseException:
2218{
2219 CallExpr callExpr;
2220 List<Expression> argList = new ArrayList<Expression>();
2221 Expression tmp;
2222 int arity = 0;
2223 FunctionName funcName = null;
2224 String hint = null;
2225}
2226{
2227 funcName = FunctionName()
2228 {
2229 hint = funcName.hint;
2230 }
2231 <LEFTPAREN> (tmp = Expression()
2232 {
2233 argList.add(tmp);
2234 arity ++;
2235 }
2236 (<COMMA> tmp = Expression()
2237 {
2238 argList.add(tmp);
2239 arity++;
2240 }
2241 )*)? <RIGHTPAREN>
2242 {
2243 // TODO use funcName.library
2244 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2245 FunctionSignature signature
2246 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2247 if (signature == null) {
2248 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2249 }
2250 callExpr = new CallExpr(signature,argList);
2251 if (hint != null) {
2252 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2253 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2254 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2255 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2256 }
2257 }
2258 return callExpr;
2259 }
2260}
2261
2262
2263Expression DatasetAccessExpression() throws ParseException:
2264{
2265 String funcName;
2266 String arg1 = null;
2267 String arg2 = null;
2268 Expression nameArg;
2269}
2270{
2271 <DATASET>
2272 {
2273 funcName = token.image;
2274 }
2275 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
2276 {
2277 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
2278 LiteralExpr ds = new LiteralExpr();
2279 ds.setValue( new StringLiteral(name) );
2280 nameArg = ds;
Yingyi Bu391f09e2015-10-29 13:49:39 -07002281 }
2282 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
2283 {
2284 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2285 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2286 if (signature == null) {
2287 signature = new FunctionSignature(dataverse, funcName, 1);
2288 }
2289 List<Expression> argList = new ArrayList<Expression>();
2290 argList.add(nameArg);
2291 return new CallExpr(signature, argList);
2292 }
2293}
2294
2295Expression ParenthesizedExpression() throws ParseException:
2296{
2297 Expression expr;
2298}
2299{
2300 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2301 {
2302 return expr;
2303 }
2304}
2305
2306Expression IfThenElse() throws ParseException:
2307{
2308 Expression condExpr;
2309 Expression thenExpr;
2310 Expression elseExpr;
2311 IfExpr ifExpr = new IfExpr();
2312}
2313{
2314 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2315
2316 {
2317 ifExpr.setCondExpr(condExpr);
2318 ifExpr.setThenExpr(thenExpr);
2319 ifExpr.setElseExpr(elseExpr);
2320 return ifExpr;
2321 }
2322}
2323
Taewoo Kim92c0bac2017-02-11 16:38:44 -08002324// Note: if you modify this part: "tmp = LetClause() {clauseList.add(tmp);}", please also apply the necessary
2325// change to the AQLPlusExtension.jj file since it refers to this string part and may behave incorrectly if this
2326// part is modified. For more details, please refer to AQLPlusExtension.jj file.
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002327Expression FLWOGR() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07002328{
2329 FLWOGRExpression flworg = new FLWOGRExpression();
2330 List<Clause> clauseList = new ArrayList<Clause>();
2331 Expression returnExpr;
2332 Clause tmp;
2333 createNewScope();
2334}
2335{
2336 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
2337 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
2338
2339 {
2340 flworg.setClauseList(clauseList);
2341 flworg.setReturnExpr(returnExpr);
2342 removeCurrentScope();
2343 return flworg;
2344 }
2345}
2346
2347Clause Clause()throws ParseException :
2348{
2349 Clause clause;
2350}
2351{
2352 (
2353 clause = ForClause()
2354 | clause = LetClause()
2355 | clause = WhereClause()
2356 | clause = OrderbyClause()
2357 | clause = GroupClause()
2358 | clause = LimitClause()
2359 | clause = DistinctClause()
2360 )
2361 {
2362 return clause;
2363 }
2364}
2365
2366Clause ForClause()throws ParseException :
2367{
2368 ForClause fc = new ForClause();
2369 VariableExpr varExp;
2370 VariableExpr varPos = null;
2371 Expression inExp;
2372 extendCurrentScope();
2373}
2374{
2375 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
2376 {
2377 fc.setVarExpr(varExp);
2378 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2379 fc.setInExpr(inExp);
2380 if (varPos != null) {
2381 fc.setPosExpr(varPos);
2382 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
2383 }
2384 return fc;
2385 }
2386}
2387
2388Clause LetClause() throws ParseException:
2389{
2390 LetClause lc = new LetClause();
2391 VariableExpr varExp;
2392 Expression beExp;
2393 extendCurrentScope();
2394}
2395{
2396 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
2397 {
2398 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
2399 lc.setVarExpr(varExp);
2400 lc.setBindingExpr(beExp);
2401 return lc;
2402 }
2403}
2404
2405Clause WhereClause()throws ParseException :
2406{
2407 WhereClause wc = new WhereClause();
2408 Expression whereExpr;
2409}
2410{
2411 <WHERE> whereExpr = Expression()
2412 {
2413 wc.setWhereExpr(whereExpr);
2414 return wc;
2415 }
2416}
2417
2418Clause OrderbyClause()throws ParseException :
2419{
2420 OrderbyClause oc = new OrderbyClause();
2421 Expression orderbyExpr;
2422 List<Expression> orderbyList = new ArrayList<Expression>();
2423 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2424 int numOfOrderby = 0;
2425}
2426{
2427 (
2428 <ORDER>
2429 {
2430 String hint = getHint(token);
2431 if (hint != null) {
2432 if (hint.startsWith(INMEMORY_HINT)) {
2433 String splits[] = hint.split(" +");
2434 int numFrames = Integer.parseInt(splits[1]);
2435 int numTuples = Integer.parseInt(splits[2]);
2436 oc.setNumFrames(numFrames);
2437 oc.setNumTuples(numTuples);
Dmitry Lychagin1227f022019-08-01 13:14:30 -07002438 } else if (hint.startsWith(RANGE_HINT)) {
2439 try {
2440 oc.setRangeMap(RangeMapBuilder.parseHint(parseExpression(hint.substring(RANGE_HINT.length()))));
Taewoo Kime65e6ca2017-01-14 17:53:28 -08002441 } catch (CompilationException e) {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002442 throw new ParseException(e.getMessage());
2443 }
2444 }
2445 }
2446 }
2447 <BY> orderbyExpr = Expression()
2448 {
2449 orderbyList.add(orderbyExpr);
2450 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2451 }
2452 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2453 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2454 {
2455 modifierList.add(modif);
2456 }
2457
2458 (<COMMA> orderbyExpr = Expression()
2459 {
2460 orderbyList.add(orderbyExpr);
2461 modif = OrderbyClause.OrderModifier.ASC;
2462 }
2463 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2464 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2465 {
2466 modifierList.add(modif);
2467 }
2468 )*
2469)
2470 {
2471 oc.setModifierList(modifierList);
2472 oc.setOrderbyList(orderbyList);
2473 return oc;
2474 }
2475}
2476Clause GroupClause()throws ParseException :
2477{
Abdullah Alamoudi806f7d22016-07-23 18:02:55 +03002478 GroupbyClause gbc = new GroupbyClause();
2479 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2480 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002481 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002482 Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002483 VariableExpr var = null;
2484 VariableExpr withVar = null;
2485 Expression expr = null;
2486 VariableExpr decorVar = null;
2487 Expression decorExpr = null;
2488}
2489{
2490 {
2491 Scope newScope = extendCurrentScopeNoPush(true);
2492 // extendCurrentScope(true);
2493 }
2494 <GROUP>
2495 {
2496 String hint = getHint(token);
2497 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2498 gbc.setHashGroupByHint(true);
2499 }
2500 }
2501 <BY> (LOOKAHEAD(2) var = Variable()
2502 {
2503 newScope.addNewVarSymbolToScope(var.getVar());
2504 } <ASSIGN>)?
2505 expr = Expression()
2506 {
2507 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2508 vePairList.add(pair1);
2509 }
2510 (<COMMA> ( LOOKAHEAD(2) var = Variable()
2511 {
2512 newScope.addNewVarSymbolToScope(var.getVar());
2513 } <ASSIGN>)?
2514 expr = Expression()
2515 {
2516 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2517 vePairList.add(pair2);
2518 }
2519 )*
2520 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2521 {
2522 newScope.addNewVarSymbolToScope(decorVar.getVar());
2523 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2524 decorPairList.add(pair3);
2525 }
2526 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
2527 {
2528 newScope.addNewVarSymbolToScope(decorVar.getVar());
2529 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2530 decorPairList.add(pair4);
2531 }
2532 )*
2533 )?
2534 (<WITH>|<KEEPING>) withVar = VariableRef()
2535 {
2536 if(withVar.getIsNewVar()==true)
2537 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002538 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002539 newScope.addNewVarSymbolToScope(withVar.getVar());
2540 }
2541 (<COMMA> withVar = VariableRef()
2542 {
2543 if(withVar.getIsNewVar()==true)
2544 throw new ParseException("can't find variable " + withVar.getVar());
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002545 withVarMap.put(withVar, withVar);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002546 newScope.addNewVarSymbolToScope(withVar.getVar());
2547 })*
2548 {
2549 gbc.setGbyPairList(vePairList);
2550 gbc.setDecorPairList(decorPairList);
Yingyi Bu8671ddf2016-08-14 23:58:43 -07002551 gbc.setWithVarMap(withVarMap);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002552 replaceCurrentScope(newScope);
2553 return gbc;
2554 }
2555}
2556
2557
2558LimitClause LimitClause() throws ParseException:
2559{
2560 LimitClause lc = new LimitClause();
2561 Expression expr;
2562 pushForbiddenScope(getCurrentScope());
2563}
2564{
2565 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2566 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2567
2568 {
2569 popForbiddenScope();
2570 return lc;
2571 }
2572}
2573
2574DistinctClause DistinctClause() throws ParseException:
2575{
2576 List<Expression> exprs = new ArrayList<Expression>();
2577 Expression expr;
2578}
2579{
2580 <DISTINCT> <BY> expr = Expression()
2581 {
2582 exprs.add(expr);
2583 }
2584 (<COMMA> expr = Expression()
2585 {
2586 exprs.add(expr);
2587 }
2588 )*
2589 {
2590 return new DistinctClause(exprs);
2591 }
2592}
2593
2594QuantifiedExpression QuantifiedExpression()throws ParseException:
2595{
2596 QuantifiedExpression qc = new QuantifiedExpression();
2597 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2598 Expression satisfiesExpr;
2599 VariableExpr var;
2600 Expression inExpr;
2601 QuantifiedPair pair;
2602}
2603{
2604 {
2605 createNewScope();
2606 }
2607
Michael Blowd6cf6412016-06-30 02:44:35 -04002608 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2609 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
Yingyi Bu391f09e2015-10-29 13:49:39 -07002610 var = Variable() <IN> inExpr = Expression()
2611 {
2612 pair = new QuantifiedPair(var, inExpr);
2613 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2614 quantifiedList.add(pair);
2615 }
2616 (
2617 <COMMA> var = Variable() <IN> inExpr = Expression()
2618 {
2619 pair = new QuantifiedPair(var, inExpr);
2620 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2621 quantifiedList.add(pair);
2622 }
2623 )*
2624 <SATISFIES> satisfiesExpr = Expression()
2625 {
2626 qc.setSatisfiesExpr(satisfiesExpr);
2627 qc.setQuantifiedList(quantifiedList);
2628 removeCurrentScope();
2629 return qc;
2630 }
2631}
2632
2633TOKEN_MGR_DECLS:
2634{
2635 public int commentDepth = 0;
Till Westmanne9b2adf2016-10-15 12:39:01 -07002636 public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -07002637
2638 public void pushState() {
2639 lexerStateStack.push( curLexState );
2640 }
2641
2642 public void popState(String token) {
2643 if (lexerStateStack.size() > 0) {
2644 SwitchTo( lexerStateStack.pop() );
2645 } else {
2646 int errorLine = input_stream.getEndLine();
2647 int errorColumn = input_stream.getEndColumn();
2648 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2649 + "\" but state stack is empty.";
2650 throw new TokenMgrError(msg, -1);
2651 }
2652 }
2653}
2654
2655<DEFAULT,IN_DBL_BRACE>
2656TOKEN :
2657{
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002658 <APPLY : "apply">
2659 | <AS : "as">
2660 | <ASC : "asc">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002661 | <AT : "at">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002662 | <AUTOGENERATED : "autogenerated">
2663 | <BTREE : "btree">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002664 | <BY : "by">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002665 | <CLOSED : "closed">
2666 | <COMPACT : "compact">
2667 | <COMPACTION : "compaction">
2668 | <CONNECT : "connect">
2669 | <CREATE : "create">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002670 | <DATASET : "dataset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002671 | <DATAVERSE : "dataverse">
2672 | <DECLARE : "declare">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002673 | <DECOR : "decor">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002674 | <DEFINITION : "definition">
2675 | <DELETE : "delete">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002676 | <DESC : "desc">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002677 | <DISCONNECT : "disconnect">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002678 | <DISTINCT : "distinct">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002679 | <DROP : "drop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002680 | <ELSE : "else">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002681 | <ENFORCED : "enforced">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002682 | <EVERY : "every">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002683 | <EXISTS : "exists">
2684 | <EXTERNAL : "external">
2685 | <FEED : "feed">
2686 | <FILTER : "filter">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002687 | <FOR : "for">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002688 | <FORMAT : "format">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002689 | <FROM : "from">
Taewoo Kimc49405a2017-01-04 00:30:43 -08002690 | <FULLTEXT : "fulltext">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002691 | <FUNCTION : "function">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002692 | <GROUP : "group">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002693 | <HINTS : "hints">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002694 | <IF : "if">
2695 | <IN : "in">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002696 | <INDEX : "index">
2697 | <INGESTION : "ingestion">
2698 | <INSERT : "insert">
2699 | <INTERNAL : "internal">
2700 | <INTO : "into">
2701 | <KEY : "key">
2702 | <KEYWORD : "keyword">
2703 | <KEEPING : "keeping">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002704 | <LET : "let">
2705 | <LIMIT : "limit">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002706 | <LOAD : "load">
2707 | <NGRAM : "ngram">
2708 | <NODEGROUP : "nodegroup">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002709 | <OFFSET : "offset">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002710 | <ON : "on">
2711 | <OPEN : "open">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002712 | <ORDER : "order">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002713 | <OUTPUT : "output">
2714 | <PATH : "path">
2715 | <POLICY : "policy">
2716 | <PRESORTED : "pre-sorted">
2717 | <PRIMARY : "primary">
2718 | <REFRESH : "refresh">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002719 | <RETURN : "return">
Steven Glenn Jacobsafa909a2016-10-16 10:35:30 -07002720 | <RETURNING : "returning">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002721 | <RTREE : "rtree">
2722 | <RUN : "run">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002723 | <SATISFIES : "satisfies">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002724 | <SECONDARY : "secondary">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002725 | <SELECT : "select">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002726 | <SET : "set">
Abdullah Alamoudifff200c2017-02-18 20:32:14 -08002727 | <START: "start">
2728 | <STOP: "stop">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002729 | <SOME : "some">
Murtadha Hubail2c04ae02017-11-21 15:58:01 +03002730 | <TEMPORARY : "temporary"> // intentionally not used but reserved for future usage
Yingyi Bu391f09e2015-10-29 13:49:39 -07002731 | <THEN : "then">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002732 | <TO : "to">
2733 | <TYPE : "type">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002734 | <UNION : "union">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002735 | <UPDATE : "update">
2736 | <UPSERT : "upsert">
2737 | <USE : "use">
2738 | <USING : "using">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002739 | <WHERE : "where">
2740 | <WITH : "with">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002741 | <WRITE : "write">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002742}
2743
2744<DEFAULT,IN_DBL_BRACE>
2745TOKEN :
2746{
2747 <CARET : "^">
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07002748 | <DIVIDE : "/">
2749 | <DIV : "div">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002750 | <MINUS : "-">
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07002751 | <MOD : "mod">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002752 | <MUL : "*">
2753 | <PLUS : "+">
2754
2755 | <LEFTPAREN : "(">
2756 | <RIGHTPAREN : ")">
2757 | <LEFTBRACKET : "[">
2758 | <RIGHTBRACKET : "]">
2759
2760 | <COLON : ":">
2761 | <COMMA : ",">
2762 | <DOT : ".">
Dmitry Lychaginbf48c492018-05-01 18:30:27 -07002763 | <PERCENT: "%">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002764 | <QUES : "?">
2765
2766 | <LT : "<">
2767 | <GT : ">">
2768 | <LE : "<=">
2769 | <GE : ">=">
2770 | <EQ : "=">
2771 | <NE : "!=">
2772 | <SIMILAR : "~=">
2773 | <ASSIGN : ":=">
2774
2775 | <AND : "and">
2776 | <OR : "or">
Abdullah Alamoudie6e54f32016-07-12 20:40:15 +04002777
2778 | <SYMBOLAT : "@">
2779 | <SYMBOLHASH : "#">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002780}
2781
2782<DEFAULT,IN_DBL_BRACE>
2783TOKEN :
2784{
2785 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2786}
2787
2788<DEFAULT>
2789TOKEN :
2790{
2791 <RIGHTBRACE : "}"> { popState("}"); }
2792}
2793
2794<DEFAULT,IN_DBL_BRACE>
2795TOKEN :
2796{
2797 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2798}
2799
2800<IN_DBL_BRACE>
2801TOKEN :
2802{
2803 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2804}
2805
2806<DEFAULT,IN_DBL_BRACE>
2807TOKEN :
2808{
2809 <INTEGER_LITERAL : (<DIGIT>)+ >
2810}
2811
2812<DEFAULT,IN_DBL_BRACE>
2813TOKEN :
2814{
Yingyi Bu535d86b2016-05-23 16:44:25 -07002815 < MISSING : "missing">
2816 | <NULL : "null">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002817 | <TRUE : "true">
2818 | <FALSE : "false">
2819}
2820
2821<DEFAULT,IN_DBL_BRACE>
2822TOKEN :
2823{
2824 <#DIGIT : ["0" - "9"]>
2825}
2826
2827<DEFAULT,IN_DBL_BRACE>
2828TOKEN:
2829{
Dmitry Lychaginee8526b2018-03-30 14:21:01 -07002830 < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("+"|"-")? <DIGITS>)?
2831 | <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)
2832 | "." <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002833 >
2834 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2835 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2836 | "." <DIGITS> ( "f" | "F" )
2837 >
2838 | <DIGITS : (<DIGIT>)+ >
2839}
2840
2841<DEFAULT,IN_DBL_BRACE>
2842TOKEN :
2843{
2844 <#LETTER : ["A" - "Z", "a" - "z"]>
2845 | <SPECIALCHARS : ["$", "_", "-"]>
2846}
2847
2848<DEFAULT,IN_DBL_BRACE>
2849TOKEN :
2850{
2851 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2852 <STRING_LITERAL : ("\"" (
2853 <EscapeQuot>
2854 | <EscapeBslash>
2855 | <EscapeSlash>
2856 | <EscapeBspace>
2857 | <EscapeFormf>
2858 | <EscapeNl>
2859 | <EscapeCr>
2860 | <EscapeTab>
2861 | ~["\"","\\"])* "\"")
2862 | ("\'"(
2863 <EscapeApos>
2864 | <EscapeBslash>
2865 | <EscapeSlash>
2866 | <EscapeBspace>
2867 | <EscapeFormf>
2868 | <EscapeNl>
2869 | <EscapeCr>
2870 | <EscapeTab>
2871 | ~["\'","\\"])* "\'")>
2872 | < #EscapeQuot: "\\\"" >
2873 | < #EscapeApos: "\\\'" >
2874 | < #EscapeBslash: "\\\\" >
2875 | < #EscapeSlash: "\\/" >
2876 | < #EscapeBspace: "\\b" >
2877 | < #EscapeFormf: "\\f" >
2878 | < #EscapeNl: "\\n" >
2879 | < #EscapeCr: "\\r" >
2880 | < #EscapeTab: "\\t" >
2881}
2882
2883<DEFAULT,IN_DBL_BRACE>
2884TOKEN :
2885{
2886 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2887}
2888
2889<DEFAULT,IN_DBL_BRACE>
2890TOKEN :
2891{
2892 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
2893}
2894
2895<DEFAULT,IN_DBL_BRACE>
2896SKIP:
2897{
2898 " "
2899 | "\t"
2900 | "\r"
2901 | "\n"
2902}
2903
2904<DEFAULT,IN_DBL_BRACE>
2905SKIP:
2906{
2907 <"//" (~["\n"])* "\n">
2908}
2909
2910<DEFAULT,IN_DBL_BRACE>
2911SKIP:
2912{
2913 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2914}
2915
2916<DEFAULT,IN_DBL_BRACE>
2917SKIP:
2918{
2919 <"/*"> { pushState(); } : INSIDE_COMMENT
2920}
2921
2922<INSIDE_COMMENT>
2923SPECIAL_TOKEN:
2924{
2925 <"+"(" ")*(~["*"])*>
2926}
2927
2928<INSIDE_COMMENT>
2929SKIP:
2930{
2931 <"/*"> { pushState(); }
2932}
2933
2934<INSIDE_COMMENT>
2935SKIP:
2936{
2937 <"*/"> { popState("*/"); }
2938 | <~[]>
2939}