blob: ec915e97ff1d2bf8d4117aa76cb6064fe24d58da [file] [log] [blame]
Yingyi Bu391f09e2015-10-29 13:49:39 -07001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(SQLPPParser)
10
11package org.apache.asterix.lang.sqlpp.parser;
12
13// For SQL++ ParserTokenManager
14import org.apache.xerces.util.IntStack;
15
16import java.io.BufferedReader;
17import java.io.File;
18import java.io.FileInputStream;
19import java.io.FileNotFoundException;
20import java.io.IOException;
21import java.io.InputStreamReader;
22import java.io.Reader;
23import java.io.StringReader;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.Iterator;
27import java.util.LinkedHashMap;
28import java.util.List;
29import java.util.Map;
30
31import org.apache.asterix.common.annotations.AutoDataGen;
32import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
33import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
34import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
35import org.apache.asterix.common.annotations.FieldIntervalDataGen;
36import org.apache.asterix.common.annotations.FieldValFileDataGen;
37import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
38import org.apache.asterix.common.annotations.IRecordFieldDataGen;
39import org.apache.asterix.common.annotations.InsertRandIntDataGen;
40import org.apache.asterix.common.annotations.ListDataGen;
41import org.apache.asterix.common.annotations.ListValFileDataGen;
42import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
43import org.apache.asterix.common.annotations.TypeDataGen;
44import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
45import org.apache.asterix.common.config.DatasetConfig.DatasetType;
46import org.apache.asterix.common.config.DatasetConfig.IndexType;
Abdullah Alamoudie800e6d2016-01-14 11:20:55 +030047import org.apache.asterix.common.config.MetadataConstants;
Yingyi Bu391f09e2015-10-29 13:49:39 -070048import org.apache.asterix.common.exceptions.AsterixException;
49import org.apache.asterix.common.functions.FunctionSignature;
50import org.apache.asterix.lang.common.base.Expression;
51import org.apache.asterix.lang.common.base.Literal;
52import org.apache.asterix.lang.common.base.IParser;
53import org.apache.asterix.lang.common.base.Statement;
54import org.apache.asterix.lang.common.clause.GroupbyClause;
55import org.apache.asterix.lang.common.clause.LetClause;
56import org.apache.asterix.lang.common.clause.LimitClause;
57import org.apache.asterix.lang.common.clause.OrderbyClause;
58import org.apache.asterix.lang.common.clause.UpdateClause;
59import org.apache.asterix.lang.common.clause.WhereClause;
60import org.apache.asterix.lang.common.context.RootScopeFactory;
61import org.apache.asterix.lang.common.context.Scope;
62import org.apache.asterix.lang.common.expression.AbstractAccessor;
63import org.apache.asterix.lang.common.expression.CallExpr;
64import org.apache.asterix.lang.common.expression.FieldAccessor;
65import org.apache.asterix.lang.common.expression.FieldBinding;
66import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
67import org.apache.asterix.lang.common.expression.IfExpr;
68import org.apache.asterix.lang.common.expression.IndexAccessor;
69import org.apache.asterix.lang.common.expression.ListConstructor;
70import org.apache.asterix.lang.common.expression.LiteralExpr;
71import org.apache.asterix.lang.common.expression.OperatorExpr;
72import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
73import org.apache.asterix.lang.common.expression.QuantifiedExpression;
74import org.apache.asterix.lang.common.expression.RecordConstructor;
75import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
76import org.apache.asterix.lang.common.expression.TypeExpression;
77import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
78import org.apache.asterix.lang.common.expression.UnaryExpr;
79import org.apache.asterix.lang.common.expression.UnaryExpr.Sign;
80import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
81import org.apache.asterix.lang.common.expression.VariableExpr;
82import org.apache.asterix.lang.common.literal.DoubleLiteral;
83import org.apache.asterix.lang.common.literal.FalseLiteral;
84import org.apache.asterix.lang.common.literal.FloatLiteral;
85import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
86import org.apache.asterix.lang.common.literal.NullLiteral;
87import org.apache.asterix.lang.common.literal.StringLiteral;
88import org.apache.asterix.lang.common.literal.TrueLiteral;
89import org.apache.asterix.lang.common.parser.ScopeChecker;
90import org.apache.asterix.lang.common.statement.CompactStatement;
91import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
92import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
93import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
94import org.apache.asterix.lang.common.statement.CreateFeedStatement;
95import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
96import org.apache.asterix.lang.common.statement.CreateIndexStatement;
97import org.apache.asterix.lang.common.statement.CreatePrimaryFeedStatement;
98import org.apache.asterix.lang.common.statement.CreateSecondaryFeedStatement;
99import org.apache.asterix.lang.common.statement.DatasetDecl;
100import org.apache.asterix.lang.common.statement.DataverseDecl;
101import org.apache.asterix.lang.common.statement.DataverseDropStatement;
102import org.apache.asterix.lang.common.statement.DeleteStatement;
103import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
104import org.apache.asterix.lang.common.statement.DropStatement;
105import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
106import org.apache.asterix.lang.common.statement.FeedDropStatement;
107import org.apache.asterix.lang.common.statement.FunctionDecl;
108import org.apache.asterix.lang.common.statement.FunctionDropStatement;
109import org.apache.asterix.lang.common.statement.IndexDropStatement;
110import org.apache.asterix.lang.common.statement.InsertStatement;
111import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
112import org.apache.asterix.lang.common.statement.LoadStatement;
113import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
114import org.apache.asterix.lang.common.statement.NodegroupDecl;
115import org.apache.asterix.lang.common.statement.Query;
116import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
117import org.apache.asterix.lang.common.statement.RunStatement;
118import org.apache.asterix.lang.common.statement.SetStatement;
119import org.apache.asterix.lang.common.statement.TypeDecl;
120import org.apache.asterix.lang.common.statement.TypeDropStatement;
121import org.apache.asterix.lang.common.statement.UpdateStatement;
122import org.apache.asterix.lang.common.statement.WriteStatement;
123import org.apache.asterix.lang.common.struct.Identifier;
124import org.apache.asterix.lang.common.struct.QuantifiedPair;
125import org.apache.asterix.lang.common.struct.VarIdentifier;
126import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
127import org.apache.asterix.lang.sqlpp.clause.FromClause;
128import org.apache.asterix.lang.sqlpp.clause.FromTerm;
129import org.apache.asterix.lang.sqlpp.clause.HavingClause;
130import org.apache.asterix.lang.sqlpp.clause.JoinClause;
131import org.apache.asterix.lang.sqlpp.clause.NestClause;
132import org.apache.asterix.lang.sqlpp.clause.Projection;
133import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
134import org.apache.asterix.lang.sqlpp.clause.SelectClause;
135import org.apache.asterix.lang.sqlpp.clause.SelectElement;
136import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
137import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
138import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
139import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
140import org.apache.asterix.lang.sqlpp.optype.JoinType;
141import org.apache.asterix.lang.sqlpp.optype.SetOpType;
142import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
143import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700144import org.apache.hyracks.algebricks.common.utils.Pair;
145import org.apache.hyracks.algebricks.common.utils.Triple;
146import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
147import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
148import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
149
150
151
Yingyi Bucaea8f02015-11-16 15:12:15 -0800152class SQLPPParser extends ScopeChecker implements IParser {
Yingyi Bu391f09e2015-10-29 13:49:39 -0700153
154 // optimizer hints
155 private static final String AUTO_HINT = "auto";
156 private static final String BROADCAST_JOIN_HINT = "bcast";
157 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
158 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
159 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
160 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
161 private static final String HASH_GROUP_BY_HINT = "hash";
162 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
163 private static final String INMEMORY_HINT = "inmem";
164 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
165 private static final String INTERVAL_HINT = "interval";
166 private static final String LIST_HINT = "list";
167 private static final String LIST_VAL_FILE_HINT = "list-val-file";
168 private static final String RANGE_HINT = "range";
169 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
170 private static final String VAL_FILE_HINT = "val-files";
171 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
172
173 private static final String GEN_FIELDS_HINT = "gen-fields";
174
175 // data generator hints
176 private static final String DGEN_HINT = "dgen";
177
178 private static class IndexParams {
179 public IndexType type;
180 public int gramLength;
181
182 public IndexParams(IndexType type, int gramLength) {
183 this.type = type;
184 this.gramLength = gramLength;
185 }
186 };
187
188 private static class FunctionName {
189 public String dataverse = null;
190 public String library = null;
191 public String function = null;
192 public String hint = null;
193 }
194
195 private static String getHint(Token t) {
196 if (t.specialToken == null) {
197 return null;
198 }
199 String s = t.specialToken.image;
200 int n = s.length();
201 if (n < 2) {
202 return null;
203 }
204 return s.substring(1).trim();
205 }
206
207 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
208 IRecordFieldDataGen rfdg = null;
209 String splits[] = hint.split(" +");
210 if (splits[0].equals(VAL_FILE_HINT)) {
211 File[] valFiles = new File[splits.length - 1];
212 for (int k=1; k<splits.length; k++) {
213 valFiles[k-1] = new File(splits[k]);
214 }
215 rfdg = new FieldValFileDataGen(valFiles);
216 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
217 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
218 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
219 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
220 } else if (splits[0].equals(LIST_HINT)) {
221 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
222 } else if (splits[0].equals(INTERVAL_HINT)) {
223 FieldIntervalDataGen.ValueType vt;
224 if (splits[1].equals("int")) {
225 vt = FieldIntervalDataGen.ValueType.INT;
226 } else if (splits[1].equals("long")) {
227 vt = FieldIntervalDataGen.ValueType.LONG;
228 } else if (splits[1].equals("float")) {
229 vt = FieldIntervalDataGen.ValueType.FLOAT;
230 } else if (splits[1].equals("double")) {
231 vt = FieldIntervalDataGen.ValueType.DOUBLE;
232 } else {
233 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
234 }
235 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
236 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
237 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
238 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
239 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
240 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
241 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
242 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
243 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
244 } else if (splits[0].equals(AUTO_HINT)) {
245 rfdg = new AutoDataGen(splits[1]);
246 }
247 return rfdg;
248 }
249
250 public SQLPPParser(String s){
251 this(new StringReader(s));
252 super.setInput(s);
253 }
254
255 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
256 File file = new File(args[0]);
257 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
258 SQLPPParser parser = new SQLPPParser(fis);
259 List<Statement> st = parser.parse();
260 //st.accept(new SQLPPPrintVisitor(), 0);
261 }
262
263 public List<Statement> parse() throws AsterixException {
264 try {
265 return Statement();
266 } catch (Error e) {
267 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
268 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
269 throw new AsterixException(new ParseException(e.getMessage()));
270 } catch (ParseException e) {
271 throw new AsterixException(e.getMessage());
272 }
273 }
274}
275
276PARSER_END(SQLPPParser)
277
278
279List<Statement> Statement() throws ParseException:
280{
281 scopeStack.push(RootScopeFactory.createRootScope(this));
282 List<Statement> decls = new ArrayList<Statement>();
283 Statement stmt = null;
284}
285{
286 ( stmt = SingleStatement() (<SEMICOLON>)*
287 {
288 decls.add(stmt);
289 }
290 )*
291 <EOF>
292 {
293 return decls;
294 }
295}
296
297Statement SingleStatement() throws ParseException:
298{
299 Statement stmt = null;
300}
301{
302 (
303 stmt = DataverseDeclaration()
304 | stmt = FunctionDeclaration()
305 | stmt = CreateStatement()
306 | stmt = LoadStatement()
307 | stmt = DropStatement()
308 | stmt = WriteStatement()
309 | stmt = SetStatement()
310 | stmt = InsertStatement()
311 | stmt = DeleteStatement()
312 | stmt = UpdateStatement()
313 | stmt = FeedStatement()
314 | stmt = CompactStatement()
315 | stmt = Query() <SEMICOLON>
316 | stmt = RefreshExternalDatasetStatement()
317 | stmt = RunStatement()
318 )
319 {
320 return stmt;
321 }
322}
323
324DataverseDecl DataverseDeclaration() throws ParseException:
325{
326 String dvName = null;
327}
328{
329 <USE> dvName = Identifier()
330 {
331 defaultDataverse = dvName;
332 return new DataverseDecl(new Identifier(dvName));
333 }
334}
335
336Statement CreateStatement() throws ParseException:
337{
338 String hint = null;
339 boolean dgen = false;
340 Statement stmt = null;
341}
342{
343 <CREATE>
344 (
345 {
346 hint = getHint(token);
347 if (hint != null && hint.startsWith(DGEN_HINT)) {
348 dgen = true;
349 }
350 }
351 stmt = TypeSpecification(hint, dgen)
352 | stmt = NodegroupSpecification()
353 | stmt = DatasetSpecification()
354 | stmt = IndexSpecification()
355 | stmt = DataverseSpecification()
356 | stmt = FunctionSpecification()
357 | stmt = FeedSpecification()
358 | stmt = FeedPolicySpecification()
359 )
360 {
361 return stmt;
362 }
363}
364
365TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
366{
367 Pair<Identifier,Identifier> nameComponents = null;
368 boolean ifNotExists = false;
369 TypeExpression typeExpr = null;
370}
371{
372 <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
373 <AS> typeExpr = TypeExpr()
374 {
375 long numValues = -1;
376 String filename = null;
377 if (dgen) {
378 String splits[] = hint.split(" +");
379 if (splits.length != 3) {
380 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
381 }
382 filename = splits[1];
383 numValues = Long.parseLong(splits[2]);
384 }
385 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
386 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
387 }
388}
389
390
391NodegroupDecl NodegroupSpecification() throws ParseException:
392{
393 String name = null;
394 String tmp = null;
395 boolean ifNotExists = false;
396 List<Identifier>ncNames = null;
397}
398{
399 <NODEGROUP> name = Identifier()
400 ifNotExists = IfNotExists() <ON> tmp = Identifier()
401 {
402 ncNames = new ArrayList<Identifier>();
403 ncNames.add(new Identifier(tmp));
404 }
405 ( <COMMA> tmp = Identifier()
406 {
407 ncNames.add(new Identifier(tmp));
408 }
409 )*
410 {
411 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
412 }
413}
414
415DatasetDecl DatasetSpecification() throws ParseException:
416{
417 Pair<Identifier,Identifier> nameComponents = null;
418 boolean ifNotExists = false;
Your Namedace5f22016-01-12 14:02:48 -0800419 Pair<Identifier,Identifier> typeComponents = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700420 String adapterName = null;
421 Map<String,String> properties = null;
422 Map<String,String> compactionPolicyProperties = null;
423 FunctionSignature appliedFunction = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800424 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700425 String nodeGroupName = null;
426 Map<String,String> hints = new HashMap<String,String>();
427 DatasetDecl dsetDecl = null;
428 boolean autogenerated = false;
429 String compactionPolicy = null;
430 boolean temp = false;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800431 Pair<Integer, List<String>> filterField = null;
Yingyi Bub9169b62016-02-26 21:21:49 -0800432 Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700433}
434{
435 (
436 <EXTERNAL> <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800437 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bu391f09e2015-10-29 13:49:39 -0700438 ifNotExists = IfNotExists()
439 <USING> adapterName = AdapterName() properties = Configuration()
440 (<ON> nodeGroupName = Identifier() )?
441 ( <HINTS> hints = Properties() )?
442 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
443 {
444 ExternalDetailsDecl edd = new ExternalDetailsDecl();
445 edd.setAdapter(adapterName);
446 edd.setProperties(properties);
447 dsetDecl = new DatasetDecl(nameComponents.first,
448 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800449 typeComponents.first,
450 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800451 metaTypeComponents.first,
452 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700453 nodeGroupName != null? new Identifier(nodeGroupName): null,
454 compactionPolicy,
455 compactionPolicyProperties,
456 hints,
457 DatasetType.EXTERNAL,
458 edd,
459 ifNotExists);
460 }
461
Yingyi Bub9169b62016-02-26 21:21:49 -0800462 | (<INTERNAL> | <TEMPORARY> { temp = true; })?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700463 <DATASET> nameComponents = QualifiedName()
Your Namedace5f22016-01-12 14:02:48 -0800464 <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
Yingyi Bub9169b62016-02-26 21:21:49 -0800465 (
466 { String name; }
467 <WITH>
468 name = Identifier()
469 {
470 if(!name.toLowerCase().equals("meta")){
471 throw new ParseException("We can only support one additional associated field called \"meta\".");
472 }
473 }
474 <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
475 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -0700476 ifNotExists = IfNotExists()
477 primaryKeyFields = PrimaryKey()
478 (<AUTOGENERATED> { autogenerated = true; } )?
479 (<ON> nodeGroupName = Identifier() )?
480 ( <HINTS> hints = Properties() )?
481 ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )?
482 ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
483 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800484 if(filterField!=null && filterField.first!=0){
485 throw new ParseException("A filter field can only be a field in the main record of the dataset.");
486 }
487 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
488 primaryKeyFields.first,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700489 autogenerated,
Yingyi Buc9bfe252016-03-01 00:02:40 -0800490 filterField == null? null : filterField.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700491 temp);
492 dsetDecl = new DatasetDecl(nameComponents.first,
493 nameComponents.second,
Your Namedace5f22016-01-12 14:02:48 -0800494 typeComponents.first,
495 typeComponents.second,
Yingyi Bub9169b62016-02-26 21:21:49 -0800496 metaTypeComponents.first,
497 metaTypeComponents.second,
Yingyi Bu391f09e2015-10-29 13:49:39 -0700498 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
499 compactionPolicy,
500 compactionPolicyProperties,
501 hints,
502 DatasetType.INTERNAL,
503 idd,
504 ifNotExists);
505 }
506 )
507 {
508 return dsetDecl;
509 }
510}
511
512RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
513{
514 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
515 Pair<Identifier,Identifier> nameComponents = null;
516 String datasetName = null;
517}
518{
519 <REFRESH> <EXTERNAL> <DATASET> nameComponents = QualifiedName()
520 {
521 redss.setDataverseName(nameComponents.first);
522 redss.setDatasetName(nameComponents.second);
523 return redss;
524 }
525}
526
527RunStatement RunStatement() throws ParseException:
528{
529 String system = null;
530 String tmp;
531 ArrayList<String> parameters = new ArrayList<String>();
532 Pair<Identifier,Identifier> nameComponentsFrom = null;
533 Pair<Identifier,Identifier> nameComponentsTo = null;
534}
535{
536 <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
537 {
538 parameters.add(tmp);
539 }
540 )*<RIGHTPAREN>
541 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
542 <TO> <DATASET> nameComponentsTo = QualifiedName()
543 {
544 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
545 }
546}
547
548CreateIndexStatement IndexSpecification() throws ParseException:
549{
550 CreateIndexStatement cis = new CreateIndexStatement();
551 String indexName = null;
552 boolean ifNotExists = false;
553 Pair<Identifier,Identifier> nameComponents = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -0800554 Pair<Integer, Pair<List<String>, TypeExpression>> fieldPair = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -0700555 IndexParams indexType = null;
556 boolean enforced = false;
557}
558{
559 <INDEX> indexName = Identifier()
560 ifNotExists = IfNotExists()
561 <ON> nameComponents = QualifiedName()
562 <LEFTPAREN> ( fieldPair = OpenField()
563 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800564 cis.addFieldExprPair(fieldPair.second);
565 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700566 }
567 ) (<COMMA> fieldPair = OpenField()
568 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800569 cis.addFieldExprPair(fieldPair.second);
570 cis.addFieldIndexIndicator(fieldPair.first);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700571 }
572 )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?
573 {
574 cis.setIndexName(new Identifier(indexName));
575 cis.setIfNotExists(ifNotExists);
576 cis.setDataverseName(nameComponents.first);
577 cis.setDatasetName(nameComponents.second);
578 if (indexType != null) {
579 cis.setIndexType(indexType.type);
580 cis.setGramLength(indexType.gramLength);
581 }
582 cis.setEnforced(enforced);
583 return cis;
584 }
585}
586
587String CompactionPolicy() throws ParseException :
588{
589 String compactionPolicy = null;
590}
591{
592 compactionPolicy = Identifier()
593 {
594 return compactionPolicy;
595 }
596}
597
598String FilterField() throws ParseException :
599{
600 String filterField = null;
601}
602{
603 filterField = Identifier()
604 {
605 return filterField;
606 }
607}
608
609IndexParams IndexType() throws ParseException:
610{
611 IndexType type = null;
612 int gramLength = 0;
613}
614{
615 (<BTREE>
616 {
617 type = IndexType.BTREE;
618 }
619 | <RTREE>
620 {
621 type = IndexType.RTREE;
622 }
623 | <KEYWORD>
624 {
625 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
626 }
627 | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
628 {
629 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
630 gramLength = Integer.valueOf(token.image);
631 }
632 <RIGHTPAREN>)
633 {
634 return new IndexParams(type, gramLength);
635 }
636}
637
638CreateDataverseStatement DataverseSpecification() throws ParseException :
639{
640 String dvName = null;
641 boolean ifNotExists = false;
642 String format = null;
643}
644{
645 <DATAVERSE> dvName = Identifier()
646 ifNotExists = IfNotExists()
647 ( LOOKAHEAD(1) <WITH> <FORMAT> format = QuotedString() )?
648 {
649 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
650 }
651}
652
653CreateFunctionStatement FunctionSpecification() throws ParseException:
654{
655 FunctionSignature signature;
656 boolean ifNotExists = false;
657 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
658 String functionBody;
659 VarIdentifier var = null;
660 Expression functionBodyExpr;
661 Token beginPos;
662 Token endPos;
663 FunctionName fctName = null;
664
665 createNewScope();
666}
667{
668 <FUNCTION> fctName = FunctionName()
669 ifNotExists = IfNotExists()
670 paramList = ParameterList()
671 <LEFTBRACE>
672 {
673 beginPos = token;
674 }
675 functionBodyExpr = Expression() <RIGHTBRACE>
676 {
677 endPos = token;
678 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
679 // TODO use fctName.library
680 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
681 getCurrentScope().addFunctionDescriptor(signature, false);
682 removeCurrentScope();
683 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
684 }
685}
686
687CreateFeedStatement FeedSpecification() throws ParseException:
688{
689 Pair<Identifier,Identifier> nameComponents = null;
690 boolean ifNotExists = false;
691 String adapterName = null;
692 Map<String,String> properties = null;
693 FunctionSignature appliedFunction = null;
694 CreateFeedStatement cfs = null;
695 Pair<Identifier,Identifier> sourceNameComponents = null;
696
697}
698{
699 (
700 <SECONDARY> <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
701 <FROM> <FEED> sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())?
702 {
703 cfs = new CreateSecondaryFeedStatement(nameComponents,
704 sourceNameComponents, appliedFunction, ifNotExists);
705 }
706 |
707 (<PRIMARY>)? <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
708 <USING> adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())?
709 {
710 cfs = new CreatePrimaryFeedStatement(nameComponents,
711 adapterName, properties, appliedFunction, ifNotExists);
712 }
713 )
714 {
715 return cfs;
716 }
717}
718
719CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
720{
721 String policyName = null;
722 String basePolicyName = null;
723 String sourcePolicyFile = null;
724 String definition = null;
725 boolean ifNotExists = false;
726 Map<String,String> properties = null;
727 CreateFeedPolicyStatement cfps = null;
728}
729{
730 (
731 <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists()
732 <FROM>
733 (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = QuotedString())?
734 {
735 cfps = new CreateFeedPolicyStatement(policyName,
736 basePolicyName, properties, definition, ifNotExists);
737 }
738 | <PATH> sourcePolicyFile = Identifier() (<DEFINITION> definition = QuotedString())?
739 {
740 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
741 }
742 )
743
744 )
745 {
746 return cfps;
747 }
748}
749
750
751
752List<VarIdentifier> ParameterList() throws ParseException:
753{
754 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
755 VarIdentifier var = null;
756}
757{
758 <LEFTPAREN> (<IDENTIFIER>
759 {
760 var = new VarIdentifier();
761 var.setValue(token.image);
762 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700763 }
764 (<COMMA> <IDENTIFIER>
765 {
766 var = new VarIdentifier();
767 var.setValue(token.image);
768 paramList.add(var);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700769 }
770 )*)? <RIGHTPAREN>
771 {
772 return paramList;
773 }
774}
775
776boolean IfNotExists() throws ParseException:
777{
778}
779{
780 ( LOOKAHEAD(1) <IF> ("not exists"|"NOT EXISTS")
781 {
782 return true;
783 }
784 )?
785 {
786 return false;
787 }
788}
789
790FunctionSignature ApplyFunction() throws ParseException:
791{
792 FunctionName functioName = null;
793 FunctionSignature funcSig = null;
794}
795{
796 <APPLY> <FUNCTION> functioName = FunctionName()
797 {
798 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
799 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
800 }
801}
802
803String GetPolicy() throws ParseException:
804{
805 String policy = null;
806}
807{
808 <USING> <POLICY> policy = Identifier()
809 {
810 return policy;
811 }
812
813}
814
815FunctionSignature FunctionSignature() throws ParseException:
816{
817 FunctionName fctName = null;
818 int arity = 0;
819}
820{
821 fctName = FunctionName() <ATT> <INTEGER_LITERAL>
822 {
823 arity = new Integer(token.image);
824 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
825 throw new ParseException(" invalid arity:" + arity);
826 }
827
828 // TODO use fctName.library
829 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
830 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
831 }
832}
833
Yingyi Buc9bfe252016-03-01 00:02:40 -0800834Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -0700835{
Yingyi Buc9bfe252016-03-01 00:02:40 -0800836 Pair<Integer, List<String>> tmp = null;
837 List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
Yingyi Bu391f09e2015-10-29 13:49:39 -0700838 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
839}
840{
841 <PRIMARY> <KEY> tmp = NestedField()
842 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800843 keyFieldSourceIndicators.add(tmp.first);
844 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700845 }
846 ( <COMMA> tmp = NestedField()
847 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800848 keyFieldSourceIndicators.add(tmp.first);
849 primaryKeyFields.add(tmp.second);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700850 }
851 )*
852 {
Yingyi Buc9bfe252016-03-01 00:02:40 -0800853 return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700854 }
855}
856
857Statement DropStatement() throws ParseException:
858{
859 String id = null;
860 Pair<Identifier,Identifier> pairId = null;
861 Triple<Identifier,Identifier,Identifier> tripleId = null;
862 FunctionSignature funcSig = null;
863 boolean ifExists = false;
864 Statement stmt = null;
865}
866{
867 <DROP>
868 (
869 <DATASET> pairId = QualifiedName() ifExists = IfExists()
870 {
871 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
872 }
873 | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
874 {
875 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
876 }
877 | <NODEGROUP> id = Identifier() ifExists = IfExists()
878 {
879 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
880 }
881 | <TYPE> pairId = TypeName() ifExists = IfExists()
882 {
883 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
884 }
885 | <DATAVERSE> id = Identifier() ifExists = IfExists()
886 {
887 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
888 }
889 | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
890 {
891 stmt = new FunctionDropStatement(funcSig, ifExists);
892 }
893 | <FEED> pairId = QualifiedName() ifExists = IfExists()
894 {
895 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
896 }
897 )
898 {
899 return stmt;
900 }
901}
902
903boolean IfExists() throws ParseException :
904{
905}
906{
907 ( LOOKAHEAD(1) <IF> <EXISTS>
908 {
909 return true;
910 }
911 )?
912 {
913 return false;
914 }
915}
916
917InsertStatement InsertStatement() throws ParseException:
918{
919 Pair<Identifier,Identifier> nameComponents = null;
920 Query query;
921}
922{
923 <INSERT> <INTO> nameComponents = QualifiedName() query = Query()
924 {
Yingyi Bucaea8f02015-11-16 15:12:15 -0800925 query.setTopLevel(true);
Yingyi Bu391f09e2015-10-29 13:49:39 -0700926 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
927 }
928}
929
930DeleteStatement DeleteStatement() throws ParseException:
931{
932 VariableExpr var = null;
933 Expression condition = null;
934 Pair<Identifier, Identifier> nameComponents;
935 // This is related to the new metadata lock management
936 setDataverses(new ArrayList<String>());
937 setDatasets(new ArrayList<String>());
938
939}
940{
941 <DELETE> var = Variable()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700942 <FROM> nameComponents = QualifiedName()
943 (<WHERE> condition = Expression())?
944 {
945 // First we get the dataverses and datasets that we want to lock
946 List<String> dataverses = getDataverses();
947 List<String> datasets = getDatasets();
948 // we remove the pointer to the dataverses and datasets
949 setDataverses(null);
950 setDatasets(null);
951 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
952 condition, getVarCounter(), dataverses, datasets);
953 }
954}
955
956UpdateStatement UpdateStatement() throws ParseException:
957{
958 VariableExpr vars;
959 Expression target;
960 Expression condition;
961 UpdateClause uc;
962 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
963}
964{
965 <UPDATE> vars = Variable() <IN> target = Expression()
966 <WHERE> condition = Expression()
967 <LEFTPAREN> (uc = UpdateClause()
968 {
969 ucs.add(uc);
970 }
971 (<COMMA> uc = UpdateClause()
972 {
973 ucs.add(uc);
974 }
975 )*) <RIGHTPAREN>
976 {
977 return new UpdateStatement(vars, target, condition, ucs);
978 }
979}
980
981UpdateClause UpdateClause() throws ParseException:
982{
983 Expression target = null;
984 Expression value = null ;
985 InsertStatement is = null;
986 DeleteStatement ds = null;
987 UpdateStatement us = null;
988 Expression condition = null;
989 UpdateClause ifbranch = null;
990 UpdateClause elsebranch = null;
991}
992{
993 (<SET> target = Expression() <EQ> value = Expression()
994 | is = InsertStatement()
995 | ds = DeleteStatement()
996 | us = UpdateStatement()
997 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
998 <THEN> ifbranch = UpdateClause()
999 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
1000 {
1001 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
1002 }
1003 )
1004}
1005
1006Statement SetStatement() throws ParseException:
1007{
1008 String pn = null;
1009 String pv = null;
1010}
1011{
1012 <SET> pn = Identifier() pv = QuotedString()
1013 {
1014 return new SetStatement(pn, pv);
1015 }
1016}
1017
1018Statement WriteStatement() throws ParseException:
1019{
1020 String nodeName = null;
1021 String fileName = null;
1022 Query query;
1023 String writerClass = null;
1024 Pair<Identifier,Identifier> nameComponents = null;
1025}
1026{
1027 <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = QuotedString()
1028 ( <USING> writerClass = QuotedString() )?
1029 {
1030 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
1031 }
1032}
1033
1034LoadStatement LoadStatement() throws ParseException:
1035{
1036 Identifier dataverseName = null;
1037 Identifier datasetName = null;
1038 boolean alreadySorted = false;
1039 String adapterName;
1040 Map<String,String> properties;
1041 Pair<Identifier,Identifier> nameComponents = null;
1042}
1043{
1044 <LOAD> <DATASET> nameComponents = QualifiedName()
1045 {
1046 dataverseName = nameComponents.first;
1047 datasetName = nameComponents.second;
1048 }
1049 <USING> adapterName = AdapterName() properties = Configuration()
1050 (<PRESORTED>
1051 {
1052 alreadySorted = true;
1053 }
1054 )?
1055 {
1056 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
1057 }
1058}
1059
1060
1061String AdapterName() throws ParseException :
1062{
1063 String adapterName = null;
1064}
1065{
1066 adapterName = Identifier()
1067 {
1068 return adapterName;
1069 }
1070}
1071
1072Statement CompactStatement() throws ParseException:
1073{
1074 Pair<Identifier,Identifier> nameComponents = null;
1075 Statement stmt = null;
1076}
1077{
1078 <COMPACT> <DATASET> nameComponents = QualifiedName()
1079 {
1080 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
1081 }
1082 {
1083 return stmt;
1084 }
1085}
1086
1087Statement FeedStatement() throws ParseException:
1088{
1089 Pair<Identifier,Identifier> feedNameComponents = null;
1090 Pair<Identifier,Identifier> datasetNameComponents = null;
1091
1092 Map<String,String> configuration = null;
1093 Statement stmt = null;
1094 String policy = null;
1095}
1096{
1097 (
1098 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
1099 {
1100 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
1101 }
1102 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
1103 {
1104 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
1105 }
1106 )
1107 {
1108 return stmt;
1109 }
1110}
1111
1112Map<String,String> Configuration() throws ParseException :
1113{
1114 Map<String,String> configuration = new LinkedHashMap<String,String>();
1115 Pair<String, String> keyValuePair = null;
1116}
1117{
1118 <LEFTPAREN> ( keyValuePair = KeyValuePair()
1119 {
1120 configuration.put(keyValuePair.first, keyValuePair.second);
1121 }
1122 ( <COMMA> keyValuePair = KeyValuePair()
1123 {
1124 configuration.put(keyValuePair.first, keyValuePair.second);
1125 }
1126 )* )? <RIGHTPAREN>
1127 {
1128 return configuration;
1129 }
1130}
1131
1132Pair<String, String> KeyValuePair() throws ParseException:
1133{
1134 String key;
1135 String value;
1136}
1137{
1138 <LEFTPAREN> key = QuotedString() <EQ> value = QuotedString() <RIGHTPAREN>
1139 {
1140 return new Pair<String, String>(key, value);
1141 }
1142}
1143
1144Map<String,String> Properties() throws ParseException:
1145{
1146 Map<String,String> properties = new HashMap<String,String>();
1147 Pair<String, String> property;
1148}
1149{
1150 (LOOKAHEAD(1) <LEFTPAREN> property = Property()
1151 {
1152 properties.put(property.first, property.second);
1153 }
1154 ( <COMMA> property = Property()
1155 {
1156 properties.put(property.first, property.second);
1157 }
1158 )* <RIGHTPAREN> )?
1159 {
1160 return properties;
1161 }
1162}
1163
1164Pair<String, String> Property() throws ParseException:
1165{
1166 String key;
1167 String value;
1168}
1169{
1170 key = Identifier() <EQ> ( value = QuotedString() | <INTEGER_LITERAL>
1171 {
1172 try {
1173 value = "" + Long.valueOf(token.image);
1174 } catch (NumberFormatException nfe) {
1175 throw new ParseException("inapproriate value: " + token.image);
1176 }
1177 }
1178 )
1179 {
1180 return new Pair<String, String>(key.toUpperCase(), value);
1181 }
1182}
1183
1184TypeExpression IndexedTypeExpr() throws ParseException:
1185{
1186 TypeExpression typeExpr = null;
1187}
1188{
1189 (
1190 typeExpr = TypeReference()
1191 | typeExpr = OrderedListTypeDef()
1192 | typeExpr = UnorderedListTypeDef()
1193 )
1194 {
1195 return typeExpr;
1196 }
1197}
1198
1199TypeExpression TypeExpr() throws ParseException:
1200{
1201 TypeExpression typeExpr = null;
1202}
1203{
1204 (
1205 typeExpr = RecordTypeDef()
1206 | typeExpr = TypeReference()
1207 | typeExpr = OrderedListTypeDef()
1208 | typeExpr = UnorderedListTypeDef()
1209 )
1210 {
1211 return typeExpr;
1212 }
1213}
1214
1215RecordTypeDefinition RecordTypeDef() throws ParseException:
1216{
1217 RecordTypeDefinition recType = new RecordTypeDefinition();
1218 RecordTypeDefinition.RecordKind recordKind = null;
1219}
1220{
1221 ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
1222 | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
1223 <LEFTBRACE>
1224 {
1225 String hint = getHint(token);
1226 if (hint != null) {
1227 String splits[] = hint.split(" +");
1228 if (splits[0].equals(GEN_FIELDS_HINT)) {
1229 if (splits.length != 5) {
1230 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1231 }
1232 if (!splits[1].equals("int")) {
1233 throw new ParseException("The only supported type for gen-fields is int.");
1234 }
1235 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
1236 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
1237 recType.setUndeclaredFieldsDataGen(ufdg);
1238 }
1239 }
1240
1241 }
1242 (
1243 RecordField(recType)
1244 ( <COMMA> RecordField(recType) )*
1245 )?
1246 <RIGHTBRACE>
1247 {
1248 if (recordKind == null) {
1249 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1250 }
1251 recType.setRecordKind(recordKind);
1252 return recType;
1253 }
1254}
1255
1256void RecordField(RecordTypeDefinition recType) throws ParseException:
1257{
1258 String fieldName;
1259 TypeExpression type = null;
1260 boolean nullable = false;
1261}
1262{
1263 fieldName = Identifier()
1264 {
1265 String hint = getHint(token);
1266 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1267 }
1268 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
1269 {
1270 recType.addField(fieldName, type, nullable, rfdg);
1271 }
1272}
1273
1274TypeReferenceExpression TypeReference() throws ParseException:
1275{
1276 String id = null;
1277}
1278{
1279 id = Identifier()
1280 {
1281 if (id.equalsIgnoreCase("int")) {
1282 id = "int64";
1283 }
1284
1285 return new TypeReferenceExpression(new Identifier(id));
1286 }
1287}
1288
1289OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
1290{
1291 TypeExpression type = null;
1292}
1293{
1294 <LEFTBRACKET>
1295 ( type = TypeExpr() )
1296 <RIGHTBRACKET>
1297 {
1298 return new OrderedListTypeDefinition(type);
1299 }
1300}
1301
1302
1303UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1304{
1305 TypeExpression type = null;
1306}
1307{
1308 <LEFTDBLBRACE>
1309 ( type = TypeExpr() )
1310 <RIGHTDBLBRACE>
1311 {
1312 return new UnorderedListTypeDefinition(type);
1313 }
1314}
1315
1316FunctionName FunctionName() throws ParseException:
1317{
1318 String first = null;
1319 String second = null;
1320 String third = null;
1321 boolean secondAfterDot = false;
1322}
1323{
1324 first = Identifier()
1325 {
1326 FunctionName result = new FunctionName();
1327 result.hint = getHint(token);
1328 }
1329 ( <DOT> second = Identifier()
1330 {
1331 secondAfterDot = true;
1332 }
1333 (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )?
1334 {
1335 if (second == null) {
1336 result.dataverse = defaultDataverse;
1337 result.library = null;
1338 result.function = first;
1339 } else if (third == null) {
1340 if (secondAfterDot) {
1341 result.dataverse = first;
1342 result.library = null;
1343 result.function = second;
1344 } else {
1345 result.dataverse = defaultDataverse;
1346 result.library = first;
1347 result.function = second;
1348 }
1349 } else {
1350 result.dataverse = first;
1351 result.library = second;
1352 result.function = third;
1353 }
1354
1355 if (result.function.equalsIgnoreCase("int")) {
1356 result.function = "int64";
1357 }
1358 return result;
1359 }
1360}
1361
1362Pair<Identifier,Identifier> TypeName() throws ParseException:
1363{
1364 Pair<Identifier,Identifier> name = null;
1365}
1366{
1367 name = QualifiedName()
1368 {
1369 if (name.first == null) {
1370 name.first = new Identifier(defaultDataverse);
1371 }
1372 return name;
1373 }
1374}
1375
1376String Identifier() throws ParseException:
1377{
1378 String lit = null;
1379}
1380{
1381 (<IDENTIFIER>
1382 {
1383 return token.image;
1384 }
1385 | lit = QuotedString()
1386 {
1387 return lit;
1388 }
1389 )
1390}
1391
Yingyi Buc9bfe252016-03-01 00:02:40 -08001392Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001393{
1394 TypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001395 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001396}
1397{
1398 fieldList = NestedField()
1399 ( <COLON> fieldType = IndexedTypeExpr() )?
1400 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001401 return new Pair<Integer, Pair<List<String>, TypeExpression>>
1402 (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001403 }
1404}
1405
Yingyi Buc9bfe252016-03-01 00:02:40 -08001406Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001407{
1408 List<String> exprList = new ArrayList<String>();
1409 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001410 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001411}
1412{
1413 lit = Identifier()
1414 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001415 boolean meetParens = false;
1416 }
1417 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001418 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001419 <LEFTPAREN><RIGHTPAREN>
1420 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001421 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001422 throw new ParseException("The string before () has to be \"meta\".");
1423 }
1424 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001425 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001426 }
1427 )?
1428 {
1429 if(!meetParens){
1430 exprList.add(lit);
1431 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001432 }
1433 (<DOT>
1434 lit = Identifier()
1435 {
1436 exprList.add(lit);
1437 }
1438 )*
1439 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001440 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001441 }
1442}
1443
1444
1445String QuotedString() throws ParseException:
1446{
1447}
1448{
1449 <QUOTED_STRING>
1450 {
1451 return removeQuotesAndEscapes(token.image);
1452 }
1453}
1454
1455
1456String StringLiteral() throws ParseException:
1457{
1458}
1459{
1460 <STRING_LITERAL>
1461 {
1462 return removeQuotesAndEscapes(token.image);
1463 }
1464}
1465
1466Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1467{
1468 String first = null;
1469 String second = null;
1470}
1471{
1472 first = Identifier() (<DOT> second = Identifier())?
1473 {
1474 Identifier id1 = null;
1475 Identifier id2 = null;
1476 if (second == null) {
1477 id2 = new Identifier(first);
1478 } else
1479 {
1480 id1 = new Identifier(first);
1481 id2 = new Identifier(second);
1482 }
1483 return new Pair<Identifier,Identifier>(id1, id2);
1484 }
1485}
1486
1487Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1488{
1489 String first = null;
1490 String second = null;
1491 String third = null;
1492}
1493{
1494 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1495 {
1496 Identifier id1 = null;
1497 Identifier id2 = null;
1498 Identifier id3 = null;
1499 if (third == null) {
1500 id2 = new Identifier(first);
1501 id3 = new Identifier(second);
1502 } else {
1503 id1 = new Identifier(first);
1504 id2 = new Identifier(second);
1505 id3 = new Identifier(third);
1506 }
1507 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1508 }
1509}
1510
1511FunctionDecl FunctionDeclaration() throws ParseException:
1512{
1513 FunctionDecl funcDecl;
1514 FunctionSignature signature;
1515 String functionName;
1516 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1517 Expression funcBody;
1518 createNewScope();
1519}
1520{
1521 <DECLARE> <FUNCTION> functionName = Identifier()
1522 paramList = ParameterList()
1523 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1524 {
1525 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1526 getCurrentScope().addFunctionDescriptor(signature, false);
1527 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1528 removeCurrentScope();
1529 return funcDecl;
1530 }
1531}
1532
1533
1534Query Query() throws ParseException:
1535{
1536 Query query = new Query();
1537 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1538 setDataverses(query.getDataverses());
1539 setDatasets(query.getDatasets());
1540 Expression expr;
1541}
1542{
1543 (
1544 expr = Expression()
1545 |
1546 expr = SelectExpression(false)
1547 )
1548 {
1549 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001550 // we remove the pointers to the locked entities before we return the query object
1551 setDataverses(null);
1552 setDatasets(null);
1553 return query;
1554 }
1555}
1556
1557
1558
1559Expression Expression():
1560{
1561 Expression expr = null;
1562 Expression exprP = null;
1563}
1564{
1565(
1566 LOOKAHEAD(2)
1567 expr = OperatorExpr()
1568 | expr = IfThenElse()
1569 | expr = QuantifiedExpression()
1570)
1571 {
1572 return (exprP==null) ? expr : exprP;
1573 }
1574}
1575
1576
1577
1578Expression OperatorExpr()throws ParseException:
1579{
1580 OperatorExpr op = null;
1581 Expression operand = null;
1582}
1583{
1584 operand = AndExpr()
1585 (
1586
1587 <OR>
1588 {
1589 if (op == null) {
1590 op = new OperatorExpr();
1591 op.addOperand(operand);
1592 op.setCurrentop(true);
1593 }
1594 op.addOperator(token.image);
1595 }
1596
1597 operand = AndExpr()
1598 {
1599 op.addOperand(operand);
1600 }
1601
1602 )*
1603
1604 {
1605 return op==null? operand: op;
1606 }
1607}
1608
1609Expression AndExpr()throws ParseException:
1610{
1611 OperatorExpr op = null;
1612 Expression operand = null;
1613}
1614{
1615 operand = RelExpr()
1616 (
1617
1618 <AND>
1619 {
1620 if (op == null) {
1621 op = new OperatorExpr();
1622 op.addOperand(operand);
1623 op.setCurrentop(true);
1624 }
1625 op.addOperator(token.image);
1626 }
1627
1628 operand = RelExpr()
1629 {
1630 op.addOperand(operand);
1631 }
1632
1633 )*
1634
1635 {
1636 return op==null? operand: op;
1637 }
1638}
1639
1640
1641
1642Expression RelExpr()throws ParseException:
1643{
1644 OperatorExpr op = null;
1645 Expression operand = null;
1646 boolean broadcast = false;
1647 IExpressionAnnotation annotation = null;
1648}
1649{
1650 operand = AddExpr()
1651 {
1652 if (operand instanceof VariableExpr) {
1653 String hint = getHint(token);
1654 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1655 broadcast = true;
1656 }
1657 }
1658 }
1659
1660 (
1661 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1662 {
1663 String mhint = getHint(token);
1664 if (mhint != null) {
1665 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1666 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1667 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1668 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1669 }
1670 }
1671 if (op == null) {
1672 op = new OperatorExpr();
1673 op.addOperand(operand, broadcast);
1674 op.setCurrentop(true);
1675 broadcast = false;
1676 }
1677 op.addOperator(token.image);
1678 }
1679
1680 operand = AddExpr()
1681 {
1682 broadcast = false;
1683 if (operand instanceof VariableExpr) {
1684 String hint = getHint(token);
1685 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1686 broadcast = true;
1687 }
1688 }
1689 op.addOperand(operand, broadcast);
1690 }
1691 )?
1692
1693 {
1694 if (annotation != null) {
1695 op.addHint(annotation);
1696 }
1697 return op==null? operand: op;
1698 }
1699}
1700
1701Expression AddExpr()throws ParseException:
1702{
1703 OperatorExpr op = null;
1704 Expression operand = null;
1705}
1706{
1707 operand = MultExpr()
1708 (
1709 LOOKAHEAD(1)
1710 (<PLUS> | <MINUS>)
1711 {
1712 if (op == null) {
1713 op = new OperatorExpr();
1714 op.addOperand(operand);
1715 op.setCurrentop(true);
1716 }
1717 ((OperatorExpr)op).addOperator(token.image);
1718 }
1719
1720 operand = MultExpr()
1721 {
1722 op.addOperand(operand);
1723 }
1724 )*
1725
1726 {
1727 return op==null? operand: op;
1728 }
1729}
1730
1731Expression MultExpr()throws ParseException:
1732{
1733 OperatorExpr op = null;
1734 Expression operand = null;
1735}
1736{
1737 operand = UnaryExpr()
1738
1739 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1740 {
1741 if (op == null) {
1742 op = new OperatorExpr();
1743 op.addOperand(operand);
1744 op.setCurrentop(true);
1745 }
1746 op.addOperator(token.image);
1747 }
1748 operand = UnaryExpr()
1749 {
1750 op.addOperand(operand);
1751 }
1752 )*
1753
1754 {
1755 return op==null?operand:op;
1756 }
1757}
1758
1759Expression UnaryExpr() throws ParseException:
1760{
1761 Expression uexpr = null;
1762 Expression expr = null;
1763}
1764{
1765 ( (<PLUS> | <MINUS>)
1766 {
1767 uexpr = new UnaryExpr();
1768 if("+".equals(token.image))
1769 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1770 else if("-".equals(token.image))
1771 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1772 else
1773 throw new ParseException();
1774 }
1775 )?
1776
1777 expr = ValueExpr()
1778 {
1779 if(uexpr!=null){
1780 ((UnaryExpr)uexpr).setExpr(expr);
1781 return uexpr;
1782 }
1783 else{
1784 return expr;
1785 }
1786 }
1787}
1788
1789Expression ValueExpr()throws ParseException:
1790{
1791 Expression expr = null;
1792 Identifier ident = null;
1793 AbstractAccessor fa = null;
1794 Expression indexExpr = null;
1795}
1796{
1797 expr = PrimaryExpr() (
1798 ident = Field()
1799 {
1800 fa = (fa == null ? new FieldAccessor(expr, ident)
1801 : new FieldAccessor(fa, ident));
1802 }
1803 | indexExpr = Index()
1804 {
1805 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1806 : new IndexAccessor(fa, indexExpr));
1807 }
1808 )*
1809 {
1810 return fa == null ? expr : fa;
1811 }
1812}
1813
1814Identifier Field() throws ParseException:
1815{
1816 String ident = null;
1817}
1818{
1819 <DOT> ident = Identifier()
1820 {
1821 return new Identifier(ident);
1822 }
1823}
1824
1825Expression Index() throws ParseException:
1826{
1827 Expression expr = null;
1828}
1829{
1830 <LEFTBRACKET> ( expr = Expression()
1831 {
1832 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1833 {
1834 Literal lit = ((LiteralExpr)expr).getValue();
1835 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1836 lit.getLiteralType() != Literal.Type.LONG) {
1837 throw new ParseException("Index should be an INTEGER");
1838 }
1839 }
1840 }
1841
1842 | <QUES> // ANY
1843
1844 )
1845
1846 <RIGHTBRACKET>
1847 {
1848 return expr;
1849 }
1850}
1851
1852
1853Expression PrimaryExpr()throws ParseException:
1854{
1855 Expression expr = null;
1856}
1857{
1858 ( LOOKAHEAD(4)
1859 expr = FunctionCallExpr()
1860 | expr = Literal()
1861 | expr = VariableRef()
1862 | expr = ListConstructor()
1863 | expr = RecordConstructor()
1864 | expr = ParenthesizedExpression()
1865 )
1866 {
1867 return expr;
1868 }
1869}
1870
1871Expression Literal() throws ParseException:
1872{
1873 LiteralExpr lit = new LiteralExpr();
1874 String str = null;
1875}
1876{
1877 ( str = StringLiteral()
1878 {
1879 lit.setValue(new StringLiteral(str));
1880 }
1881 | <INTEGER_LITERAL>
1882 {
1883 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1884 }
1885 | <FLOAT_LITERAL>
1886 {
1887 lit.setValue(new FloatLiteral(new Float(token.image)));
1888 }
1889 | <DOUBLE_LITERAL>
1890 {
1891 lit.setValue(new DoubleLiteral(new Double(token.image)));
1892 }
1893 | <NULL>
1894 {
1895 lit.setValue(NullLiteral.INSTANCE);
1896 }
1897 | <TRUE>
1898 {
1899 lit.setValue(TrueLiteral.INSTANCE);
1900 }
1901 | <FALSE>
1902 {
1903 lit.setValue(FalseLiteral.INSTANCE);
1904 }
1905 )
1906 {
1907 return lit;
1908 }
1909}
1910
1911
1912VariableExpr VariableRef() throws ParseException:
1913{
1914 VariableExpr varExp = new VariableExpr();
1915 VarIdentifier var = new VarIdentifier();
1916}
1917{
1918 { String id = null; }
1919 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1920 {
1921 Identifier ident = lookupSymbol(id);
1922 if (isInForbiddenScopes(id)) {
1923 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.");
1924 }
1925 if(ident != null) { // exist such ident
1926 varExp.setIsNewVar(false);
1927 varExp.setVar((VarIdentifier)ident);
1928 } else {
1929 varExp.setVar(var);
1930 }
1931 var.setValue(id);
1932 return varExp;
1933 }
1934}
1935
1936
1937VariableExpr Variable() throws ParseException:
1938{
1939 VariableExpr varExp = new VariableExpr();
1940 VarIdentifier var = new VarIdentifier();
1941}
1942{
1943 { String id = null; }
1944 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1945 {
1946 Identifier ident = lookupSymbol(id);
1947 if(ident != null) { // exist such ident
1948 varExp.setIsNewVar(false);
1949 }
1950 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08001951 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001952 return varExp;
1953 }
1954}
1955
1956Expression ListConstructor() throws ParseException:
1957{
1958 Expression expr = null;
1959}
1960{
1961 (
1962 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1963 )
1964
1965 {
1966 return expr;
1967 }
1968}
1969
1970
1971ListConstructor OrderedListConstructor() throws ParseException:
1972{
1973 ListConstructor expr = new ListConstructor();
1974 List<Expression> exprList = null;
1975 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1976}
1977{
1978 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
1979 {
1980 expr.setExprList(exprList);
1981 return expr;
1982 }
1983}
1984
1985ListConstructor UnorderedListConstructor() throws ParseException:
1986{
1987 ListConstructor expr = new ListConstructor();
1988 List<Expression> exprList = null;
1989 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1990}
1991{
1992 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
1993 {
1994 expr.setExprList(exprList);
1995 return expr;
1996 }
1997}
1998
1999List<Expression> ExpressionList() throws ParseException:
2000{
2001 Expression expr = null;
2002 List<Expression> list = null;
2003 List<Expression> exprList = new ArrayList<Expression>();
2004}
2005{
2006 (
2007 expr = Expression() { exprList.add(expr); }
2008 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2009 )?
2010 (LOOKAHEAD(1) Comma())?
2011 {
2012 return exprList;
2013 }
2014}
2015
2016void Comma():
2017{}
2018{
2019 <COMMA>
2020}
2021
2022RecordConstructor RecordConstructor() throws ParseException:
2023{
2024 RecordConstructor expr = new RecordConstructor();
2025 FieldBinding tmp = null;
2026 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2027}
2028{
2029 <LEFTBRACE> (tmp = FieldBinding()
2030 {
2031 fbList.add(tmp);
2032 }
2033 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2034 {
2035 expr.setFbList(fbList);
2036 return expr;
2037 }
2038}
2039
2040FieldBinding FieldBinding() throws ParseException:
2041{
2042 FieldBinding fb = new FieldBinding();
2043 Expression left, right;
2044}
2045{
2046 left = Expression() <COLON> right = Expression()
2047 {
2048 fb.setLeftExpr(left);
2049 fb.setRightExpr(right);
2050 return fb;
2051 }
2052}
2053
2054
2055Expression FunctionCallExpr() throws ParseException:
2056{
2057 CallExpr callExpr;
2058 List<Expression> argList = new ArrayList<Expression>();
2059 Expression tmp;
2060 int arity = 0;
2061 FunctionName funcName = null;
2062 String hint = null;
2063}
2064{
2065 funcName = FunctionName()
2066 {
2067 hint = funcName.hint;
2068 }
2069 <LEFTPAREN> (tmp = Expression()
2070 {
2071 argList.add(tmp);
2072 arity ++;
2073 }
2074 (<COMMA> tmp = Expression()
2075 {
2076 argList.add(tmp);
2077 arity++;
2078 }
2079 )*)? <RIGHTPAREN>
2080 {
2081 // TODO use funcName.library
2082 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2083 FunctionSignature signature
2084 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2085 if (signature == null) {
2086 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2087 }
2088 callExpr = new CallExpr(signature,argList);
2089 if (hint != null) {
2090 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2091 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2092 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2093 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2094 }
2095 }
2096 return callExpr;
2097 }
2098}
2099
2100Expression ParenthesizedExpression() throws ParseException:
2101{
2102 Expression expr;
2103}
2104{
2105 (
2106 LOOKAHEAD(2)
2107 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2108 |
2109 expr = Subquery()
2110 )
2111 {
2112 return expr;
2113 }
2114}
2115
2116Expression IfThenElse() throws ParseException:
2117{
2118 Expression condExpr;
2119 Expression thenExpr;
2120 Expression elseExpr;
2121 IfExpr ifExpr = new IfExpr();
2122}
2123{
2124 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2125
2126 {
2127 ifExpr.setCondExpr(condExpr);
2128 ifExpr.setThenExpr(thenExpr);
2129 ifExpr.setElseExpr(elseExpr);
2130 return ifExpr;
2131 }
2132}
2133
2134SelectExpression SelectExpression(boolean subquery) throws ParseException: {
2135 List<LetClause> letClauses = new ArrayList<LetClause>();
2136 SelectSetOperation selectSetOperation;
2137 OrderbyClause orderbyClause = null;
2138 LimitClause limitClause = null;
2139 createNewScope();
2140} {
2141 ( letClauses = LetClause() )?
2142 selectSetOperation = SelectSetOperation()
2143 (orderbyClause = OrderbyClause() {})?
2144 (limitClause = LimitClause() {})?
2145 {
2146 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2147 }
2148}
2149
2150SelectSetOperation SelectSetOperation() throws ParseException: {
2151 SetOperationInput setOperationInputLeft;
2152 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2153}
2154{
2155 {
2156 SelectBlock selectBlockLeft = null;
2157 SelectExpression subqueryLeft = null;
2158 Expression expr = null;
2159 }
2160 selectBlockLeft = SelectBlock()
2161 {
2162 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2163 }
2164 (
2165 {
2166 SetOpType opType = SetOpType.UNION;
2167 boolean setSemantics = true;
2168 SelectBlock selectBlockRight = null;
2169 SelectExpression subqueryRight = null;
2170 }
2171 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2172 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2173 {
2174 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2175 }
2176 )*
2177 {
2178 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2179 }
2180}
2181
2182SelectExpression Subquery() throws ParseException: {
2183 SelectExpression selectExpr = null;
2184}
2185{
2186 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2187 {
2188 return selectExpr;
2189 }
2190}
2191
2192SelectBlock SelectBlock() throws ParseException: {
2193 SelectClause selectClause = null;
2194 FromClause fromClause = null;
2195 List<LetClause> fromLetClauses = null;
2196 WhereClause whereClause = null;
2197 GroupbyClause groupbyClause = null;
2198 List<LetClause> gbyLetClauses = null;
2199 HavingClause havingClause = null;
2200}
2201{
2202 (
2203 selectClause = SelectClause()
2204 (
2205 LOOKAHEAD(1)
2206 fromClause = FromClause()
2207 (
2208 LOOKAHEAD(1)
2209 fromLetClauses = LetClause()
2210 )?
2211 )?
2212 (whereClause = WhereClause())?
2213 (
2214 groupbyClause = GroupbyClause()
2215 (
2216 LOOKAHEAD(1)
2217 gbyLetClauses = LetClause()
2218 )?
2219 (havingClause = HavingClause())?
2220 )?
2221 |
2222 fromClause = FromClause()
2223 (
2224 LOOKAHEAD(1)
2225 fromLetClauses = LetClause()
2226 )?
2227 (whereClause = WhereClause())?
2228 (
2229 groupbyClause = GroupbyClause()
2230 (
2231 gbyLetClauses = LetClause()
2232 )?
2233 (havingClause = HavingClause())?
2234 )?
2235 selectClause = SelectClause()
2236 )
2237 {
2238 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2239 }
2240}
2241
2242SelectClause SelectClause() throws ParseException: {
2243 SelectRegular selectRegular = null;
2244 SelectElement selectElement = null;
2245 boolean distinct = false;
2246}
2247{
2248 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
2249 (
2250 selectRegular = SelectRegular()
2251 |
2252 selectElement = SelectElement()
2253 )
2254 {
2255 return new SelectClause(selectElement, selectRegular, distinct);
2256 }
2257}
2258
2259SelectRegular SelectRegular() throws ParseException: {
2260 List<Projection> projections = new ArrayList<Projection>();
2261}
2262{
2263 {
2264 Projection projection = null;
2265 }
2266 projection = Projection() { projections.add(projection); }
2267 ( LOOKAHEAD(2) <COMMA>
2268 projection = Projection() {projections.add(projection);}
2269 )*
2270 {
2271 return new SelectRegular(projections);
2272 }
2273}
2274
2275SelectElement SelectElement() throws ParseException: {
2276 Expression expr = null;
2277 String name = null;
2278}
2279{
2280 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2281 {
2282 return new SelectElement(expr);
2283 }
2284}
2285
2286Projection Projection() throws ParseException: {
2287 Expression expr = null;
2288 Identifier identifier = null;
2289 String name = null;
2290 boolean star = false;
2291 boolean exprStar = false;
2292}
2293{
2294 (
2295 LOOKAHEAD(2)
2296 expr= Expression() (<AS>)? name = Identifier()
2297 | expr = Expression() <DOT> <MUL> {exprStar = true; }
2298 | <MUL> {star = true; }
2299 )
2300 {
2301 return new Projection(expr, name, star, exprStar);
2302 }
2303}
2304
2305FromClause FromClause() throws ParseException :
2306{
2307 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2308 extendCurrentScope();
2309}
2310{
2311 {
2312 FromTerm fromTerm = null;
2313 }
2314 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
2315 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2316 {
2317 return new FromClause(fromTerms);
2318 }
2319}
2320
2321FromTerm FromTerm() throws ParseException :
2322{
2323 Expression leftExpr = null;
2324 VariableExpr leftVar = null;
2325 VariableExpr posVar = null;
2326 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2327}
2328{
2329 leftExpr = Expression() (<AS>)? leftVar = Variable() (<AT> posVar = Variable())?
2330 (
2331 {JoinType joinType = JoinType.INNER; }
2332 (joinType = JoinType())?
2333 {
2334 AbstractBinaryCorrelateClause correlateClause = null;
2335 }
2336 (correlateClause = JoinClause(joinType)
2337 |
2338 correlateClause = NestClause(joinType)
2339 |
2340 correlateClause = UnnestClause(joinType)
2341 )
2342 {
2343 correlateClauses.add(correlateClause);
2344 }
2345 )*
2346 {
2347 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2348 }
2349}
2350
2351JoinClause JoinClause(JoinType joinType) throws ParseException :
2352{
2353 Expression rightExpr = null;
2354 VariableExpr rightVar = null;
2355 VariableExpr posVar = null;
2356 Expression conditionExpr = null;
2357}
2358{
2359 <JOIN> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2360 {
2361 return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2362 }
2363}
2364
2365NestClause NestClause(JoinType joinType) throws ParseException :
2366{
2367 Expression rightExpr = null;
2368 VariableExpr rightVar = null;
2369 VariableExpr posVar = null;
2370 Expression conditionExpr = null;
2371}
2372{
2373 <NEST> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2374 {
2375 return new NestClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2376 }
2377}
2378
2379UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2380{
2381 Expression rightExpr;
2382 VariableExpr rightVar;
2383 VariableExpr posVar = null;
2384}
2385{
2386 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())?
2387 {
2388 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2389 }
2390}
2391
2392
2393JoinType JoinType() throws ParseException :
2394{
2395 JoinType joinType = JoinType.INNER;
2396}
2397{
2398 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2399 {
2400 return joinType;
2401 }
2402}
2403
2404List<LetClause> LetClause() throws ParseException:
2405{
2406 List<LetClause> letList = new ArrayList<LetClause>();
2407 LetClause letClause;
2408}
2409{
2410 (
2411 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2412 |
2413 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2414 )
2415 {
2416 return letList;
2417 }
2418}
2419
2420WhereClause WhereClause()throws ParseException :
2421{
2422 WhereClause wc = new WhereClause();
2423 Expression whereExpr;
2424}
2425{
2426 <WHERE> whereExpr = Expression()
2427 {
2428 wc.setWhereExpr(whereExpr);
2429 return wc;
2430 }
2431}
2432
2433OrderbyClause OrderbyClause()throws ParseException :
2434{
2435 OrderbyClause oc = new OrderbyClause();
2436 Expression orderbyExpr;
2437 List<Expression> orderbyList = new ArrayList<Expression>();
2438 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2439 int numOfOrderby = 0;
2440}
2441{
2442 <ORDER>
2443 {
2444 String hint = getHint(token);
2445 if (hint != null) {
2446 if (hint.startsWith(INMEMORY_HINT)) {
2447 String splits[] = hint.split(" +");
2448 int numFrames = Integer.parseInt(splits[1]);
2449 int numTuples = Integer.parseInt(splits[2]);
2450 oc.setNumFrames(numFrames);
2451 oc.setNumTuples(numTuples);
2452 }
2453 }
2454 }
2455 <BY> orderbyExpr = Expression()
2456 {
2457 orderbyList.add(orderbyExpr);
2458 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2459 }
2460 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2461 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2462 {
2463 modifierList.add(modif);
2464 }
2465
2466 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2467 {
2468 orderbyList.add(orderbyExpr);
2469 modif = OrderbyClause.OrderModifier.ASC;
2470 }
2471 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2472 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2473 {
2474 modifierList.add(modif);
2475 }
2476 )*
2477
2478 {
2479 oc.setModifierList(modifierList);
2480 oc.setOrderbyList(orderbyList);
2481 return oc;
2482 }
2483}
2484
2485GroupbyClause GroupbyClause()throws ParseException :
2486{
2487 GroupbyClause gbc = new GroupbyClause();
2488 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2489 VariableExpr var = null;
2490 VariableExpr withVar = null;
2491 Expression expr = null;
2492 VariableExpr decorVar = null;
2493 Expression decorExpr = null;
2494}
2495{
2496 {
2497 Scope newScope = extendCurrentScopeNoPush(true);
2498 // extendCurrentScope(true);
2499 }
2500 <GROUP>
2501 {
2502 String hint = getHint(token);
2503 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2504 gbc.setHashGroupByHint(true);
2505 }
2506 }
2507 <BY> (
2508 expr = Expression()
2509 (LOOKAHEAD(1) (<AS>)?
2510 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002511 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002512 {
2513 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2514 vePairList.add(pair1);
2515 }
2516 ( LOOKAHEAD(1) <COMMA>
2517 expr = Expression()
2518 (LOOKAHEAD(1) (<AS>)?
2519 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002520 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002521 {
2522 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2523 vePairList.add(pair2);
2524 }
2525 )*
2526 )
2527 {
2528 gbc.setGbyPairList(vePairList);
2529 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
2530 gbc.setWithVarList(new ArrayList<VariableExpr>());
2531 replaceCurrentScope(newScope);
2532 return gbc;
2533 }
2534}
2535
2536HavingClause HavingClause() throws ParseException:
2537{
2538 Expression filterExpr = null;
2539}
2540{
2541 <HAVING> filterExpr = Expression()
2542 {
2543 return new HavingClause(filterExpr);
2544 }
2545}
2546
2547LimitClause LimitClause() throws ParseException:
2548{
2549 LimitClause lc = new LimitClause();
2550 Expression expr;
2551 pushForbiddenScope(getCurrentScope());
2552}
2553{
2554 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2555 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2556
2557 {
2558 popForbiddenScope();
2559 return lc;
2560 }
2561}
2562
2563QuantifiedExpression QuantifiedExpression()throws ParseException:
2564{
2565 QuantifiedExpression qc = new QuantifiedExpression();
2566 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2567 Expression satisfiesExpr;
2568 VariableExpr var;
2569 Expression inExpr;
2570 QuantifiedPair pair;
2571}
2572{
2573 {
2574 createNewScope();
2575 }
2576
2577 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2578 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2579 var = Variable() <IN> inExpr = Expression()
2580 {
2581 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002582 quantifiedList.add(pair);
2583 }
2584 (
2585 <COMMA> var = Variable() <IN> inExpr = Expression()
2586 {
2587 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002588 quantifiedList.add(pair);
2589 }
2590 )*
2591 <SATISFIES> satisfiesExpr = Expression()
2592 {
2593 qc.setSatisfiesExpr(satisfiesExpr);
2594 qc.setQuantifiedList(quantifiedList);
2595 removeCurrentScope();
2596 return qc;
2597 }
2598}
2599
2600LetClause LetElement() throws ParseException:
2601{
2602 LetClause lc = new LetClause();
2603 VariableExpr varExp;
2604 Expression beExp;
2605 extendCurrentScope();
2606}
2607{
2608 varExp = Variable() <EQ> beExp = Expression()
2609 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002610 lc.setVarExpr(varExp);
2611 lc.setBindingExpr(beExp);
2612 return lc;
2613 }
2614}
2615
2616LetClause WithElement() throws ParseException:
2617{
2618 LetClause lc = new LetClause();
2619 VariableExpr varExp;
2620 Expression beExp;
2621 extendCurrentScope();
2622}
2623{
2624 varExp = Variable() <AS> beExp = Expression()
2625 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002626 lc.setVarExpr(varExp);
2627 lc.setBindingExpr(beExp);
2628 return lc;
2629 }
2630}
2631
2632TOKEN_MGR_DECLS:
2633{
2634 public int commentDepth = 0;
2635 public IntStack lexerStateStack = new IntStack();
2636
2637 public void pushState() {
2638 lexerStateStack.push( curLexState );
2639 }
2640
2641 public void popState(String token) {
2642 if (lexerStateStack.size() > 0) {
2643 SwitchTo( lexerStateStack.pop() );
2644 } else {
2645 int errorLine = input_stream.getEndLine();
2646 int errorColumn = input_stream.getEndColumn();
2647 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2648 + "\" but state stack is empty.";
2649 throw new TokenMgrError(msg, -1);
2650 }
2651 }
2652}
2653
2654<DEFAULT,IN_DBL_BRACE>
2655TOKEN [IGNORE_CASE]:
2656{
2657 <ALL : "all">
2658 | <AND : "and">
2659 | <APPLY : "apply">
2660 | <AS : "as">
2661 | <ASC : "asc">
2662 | <AT : "at">
2663 | <AUTOGENERATED : "autogenerated">
2664 | <BTREE : "btree">
2665 | <BY : "by">
2666 | <CASE : "case">
2667 | <CLOSED : "closed">
2668 | <CREATE : "create">
2669 | <COMPACTION : "compaction">
2670 | <COMPACT : "compact">
2671 | <CONNECT : "connect">
2672 | <CORRELATE : "correlate">
2673 | <DATASET : "table">
2674 | <DATAVERSE : "database">
2675 | <DECLARE : "declare">
2676 | <DEFINITION : "definition">
2677 | <DELETE : "delete">
2678 | <DESC : "desc">
2679 | <DISCONNECT : "disconnect">
2680 | <DISTINCT : "distinct">
2681 | <DROP : "drop">
2682 | <ELEMENT : "element">
2683 | <ELSE : "else">
2684 | <ENFORCED : "enforced">
2685 | <EVERY : "every">
2686 | <EXCEPT : "except">
2687 | <EXISTS : "exists">
2688 | <EXTERNAL : "external">
2689 | <FEED : "feed">
2690 | <FILTER : "filter">
2691 | <FLATTEN : "flatten">
2692 | <FOR : "for">
2693 | <FORMAT : "format">
2694 | <FROM : "from">
2695 | <FULL : "full">
2696 | <FUNCTION : "function">
2697 | <GROUP : "group">
2698 | <HAVING : "having">
2699 | <HINTS : "hints">
2700 | <IF : "if">
2701 | <INTO : "into">
2702 | <IN : "in">
2703 | <INDEX : "index">
2704 | <INGESTION : "ingestion">
2705 | <INNER : "inner">
2706 | <INSERT : "insert">
2707 | <INTERNAL : "internal">
2708 | <INTERSECT : "intersect">
2709 | <JOIN : "join">
2710 | <KEYWORD : "keyword">
2711 | <KEY : "key">
2712 | <LEFT : "left">
2713 | <LETTING : "letting">
2714 | <LET : "let">
2715 | <LIMIT : "limit">
2716 | <LOAD : "load">
2717 | <NEST : "nest">
2718 | <NODEGROUP : "nodegroup">
2719 | <NGRAM : "ngram">
2720 | <OFFSET : "offset">
2721 | <ON : "on">
2722 | <OPEN : "open">
2723 | <OR : "or">
2724 | <ORDER : "order">
2725 | <OUTER : "outer">
2726 | <OUTPUT : "output">
2727 | <PATH : "path">
2728 | <POLICY : "policy">
2729 | <PRESORTED : "pre-sorted">
2730 | <PRIMARY : "primary">
2731 | <RAW : "raw">
2732 | <REFRESH : "refresh">
2733 | <RETURN : "return">
2734 | <RTREE : "rtree">
2735 | <RUN : "run">
2736 | <SATISFIES : "satisfies">
2737 | <SECONDARY : "secondary">
2738 | <SELECT : "select">
2739 | <SET : "set">
2740 | <SOME : "some">
2741 | <TEMPORARY : "temporary">
2742 | <THEN : "then">
2743 | <TYPE : "type">
2744 | <TO : "to">
2745 | <UNION : "union">
2746 | <UNNEST : "unnest">
2747 | <VALUE : "value">
2748 | <WHEN : "when">
2749 | <WHERE : "where">
2750 | <WITH : "with">
2751 | <WRITE : "write">
2752 | <UPDATE : "update">
2753 | <USE : "use">
2754 | <USING : "using">
2755}
2756
2757<DEFAULT,IN_DBL_BRACE>
2758TOKEN :
2759{
2760 <CARET : "^">
2761 | <DIV : "/">
2762 | <IDIV : "idiv">
2763 | <MINUS : "-">
2764 | <MOD : "%">
2765 | <MUL : "*">
2766 | <PLUS : "+">
2767
2768 | <LEFTPAREN : "(">
2769 | <RIGHTPAREN : ")">
2770 | <LEFTBRACKET : "[">
2771 | <RIGHTBRACKET : "]">
2772
2773 | <ATT : "@">
2774 | <COLON : ":">
2775 | <COMMA : ",">
2776 | <DOT : ".">
2777 | <QUES : "?">
2778 | <SEMICOLON : ";">
2779 | <SHARP : "#">
2780
2781 | <LT : "<">
2782 | <GT : ">">
2783 | <LE : "<=">
2784 | <GE : ">=">
2785 | <EQ : "=">
2786 | <NE : "!=">
2787 | <SIMILAR : "~=">
2788}
2789
2790<DEFAULT,IN_DBL_BRACE>
2791TOKEN :
2792{
2793 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2794}
2795
2796<DEFAULT>
2797TOKEN :
2798{
2799 <RIGHTBRACE : "}"> { popState("}"); }
2800}
2801
2802<DEFAULT,IN_DBL_BRACE>
2803TOKEN :
2804{
2805 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2806}
2807
2808<IN_DBL_BRACE>
2809TOKEN :
2810{
2811 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2812}
2813
2814<DEFAULT,IN_DBL_BRACE>
2815TOKEN :
2816{
2817 <INTEGER_LITERAL : (<DIGIT>)+ >
2818}
2819
2820<DEFAULT,IN_DBL_BRACE>
2821TOKEN :
2822{
2823 <NULL : "null">
2824 | <TRUE : "true">
2825 | <FALSE : "false">
2826}
2827
2828<DEFAULT,IN_DBL_BRACE>
2829TOKEN :
2830{
2831 <#DIGIT : ["0" - "9"]>
2832}
2833
2834<DEFAULT,IN_DBL_BRACE>
2835TOKEN:
2836{
2837 < DOUBLE_LITERAL: <DIGITS>
2838 | <DIGITS> ( "." <DIGITS> )?
2839 | "." <DIGITS>
2840 >
2841 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2842 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2843 | "." <DIGITS> ( "f" | "F" )
2844 >
2845 | <DIGITS : (<DIGIT>)+ >
2846}
2847
2848<DEFAULT,IN_DBL_BRACE>
2849TOKEN :
2850{
2851 <#LETTER : ["A" - "Z", "a" - "z"]>
2852 | <SPECIALCHARS : ["$", "_"]>
2853}
2854
2855<DEFAULT,IN_DBL_BRACE>
2856TOKEN :
2857{
2858 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2859 <QUOTED_STRING : "\"" (
2860 <EscapeQuot>
2861 | <EscapeBslash>
2862 | <EscapeSlash>
2863 | <EscapeBspace>
2864 | <EscapeFormf>
2865 | <EscapeNl>
2866 | <EscapeCr>
2867 | <EscapeTab>
2868 | ~["\"","\\"])* "\"">
2869 | <STRING_LITERAL : "\'" (
2870 <EscapeQuot>
2871 | <EscapeApos>
2872 | <EscapeBslash>
2873 | <EscapeSlash>
2874 | <EscapeBspace>
2875 | <EscapeFormf>
2876 | <EscapeNl>
2877 | <EscapeCr>
2878 | <EscapeTab>
2879 | ~["\'","\\"])* "\'">
2880 | < #EscapeQuot: "\\\"" >
2881 | < #EscapeApos: "\\\'" >
2882 | < #EscapeBslash: "\\\\" >
2883 | < #EscapeSlash: "\\/" >
2884 | < #EscapeBspace: "\\b" >
2885 | < #EscapeFormf: "\\f" >
2886 | < #EscapeNl: "\\n" >
2887 | < #EscapeCr: "\\r" >
2888 | < #EscapeTab: "\\t" >
2889}
2890
2891<DEFAULT,IN_DBL_BRACE>
2892TOKEN :
2893{
2894 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2895}
2896
2897<DEFAULT,IN_DBL_BRACE>
2898SKIP:
2899{
2900 " "
2901 | "\t"
2902 | "\r"
2903 | "\n"
2904}
2905
2906<DEFAULT,IN_DBL_BRACE>
2907SKIP:
2908{
2909 <"//" (~["\n"])* "\n">
2910}
2911
2912<DEFAULT,IN_DBL_BRACE>
2913SKIP:
2914{
2915 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2916}
2917
2918<DEFAULT,IN_DBL_BRACE>
2919SKIP:
2920{
2921 <"/*"> { pushState(); } : INSIDE_COMMENT
2922}
2923
2924<INSIDE_COMMENT>
2925SPECIAL_TOKEN:
2926{
2927 <"+"(" ")*(~["*"])*>
2928}
2929
2930<INSIDE_COMMENT>
2931SKIP:
2932{
2933 <"/*"> { pushState(); }
2934}
2935
2936<INSIDE_COMMENT>
2937SKIP:
2938{
2939 <"*/"> { popState("*/"); }
2940 | <~[]>
2941}