blob: 38b4429bfaadad9479ac7ad95b4a3af8e3cb8e4b [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 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700436 <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 Bu1c0fff52016-03-25 20:23:30 -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{
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700519 <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700520 {
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>
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700541 <FROM> Dataset() nameComponentsFrom = QualifiedName()
542 <TO> Dataset() nameComponentsTo = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700543 {
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 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -0700869 Dataset() pairId = QualifiedName() ifExists = IfExists()
Yingyi Bu391f09e2015-10-29 13:49:39 -0700870 {
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{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001044 <LOAD> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001045 {
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{
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001078 <COMPACT> Dataset() nameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001079 {
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 (
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001098 <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Yingyi Bu391f09e2015-10-29 13:49:39 -07001099 {
1100 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
1101 }
Yingyi Bu1c0fff52016-03-25 20:23:30 -07001102 | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName()
Yingyi Bu391f09e2015-10-29 13:49:39 -07001103 {
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 Bu1c0fff52016-03-25 20:23:30 -07001392void Dataset() throws ParseException:
1393{
1394}
1395{
1396 (<DATASET>|<COLLECTION>)
1397}
1398
Yingyi Buc9bfe252016-03-01 00:02:40 -08001399Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001400{
1401 TypeExpression fieldType = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001402 Pair<Integer, List<String>> fieldList = null;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001403}
1404{
1405 fieldList = NestedField()
1406 ( <COLON> fieldType = IndexedTypeExpr() )?
1407 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001408 return new Pair<Integer, Pair<List<String>, TypeExpression>>
1409 (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType));
Yingyi Bu391f09e2015-10-29 13:49:39 -07001410 }
1411}
1412
Yingyi Buc9bfe252016-03-01 00:02:40 -08001413Pair<Integer, List<String>> NestedField() throws ParseException:
Yingyi Bu391f09e2015-10-29 13:49:39 -07001414{
1415 List<String> exprList = new ArrayList<String>();
1416 String lit = null;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001417 int source = 0;
Yingyi Bu391f09e2015-10-29 13:49:39 -07001418}
1419{
1420 lit = Identifier()
1421 {
Yingyi Bub9169b62016-02-26 21:21:49 -08001422 boolean meetParens = false;
1423 }
1424 (
Yingyi Buc9bfe252016-03-01 00:02:40 -08001425 LOOKAHEAD(1)
Yingyi Bub9169b62016-02-26 21:21:49 -08001426 <LEFTPAREN><RIGHTPAREN>
1427 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001428 if(!lit.toLowerCase().equals("meta")){
Yingyi Bub9169b62016-02-26 21:21:49 -08001429 throw new ParseException("The string before () has to be \"meta\".");
1430 }
1431 meetParens = true;
Yingyi Buc9bfe252016-03-01 00:02:40 -08001432 source = 1;
Yingyi Bub9169b62016-02-26 21:21:49 -08001433 }
1434 )?
1435 {
1436 if(!meetParens){
1437 exprList.add(lit);
1438 }
Yingyi Bu391f09e2015-10-29 13:49:39 -07001439 }
1440 (<DOT>
1441 lit = Identifier()
1442 {
1443 exprList.add(lit);
1444 }
1445 )*
1446 {
Yingyi Buc9bfe252016-03-01 00:02:40 -08001447 return new Pair<Integer, List<String>>(source, exprList);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001448 }
1449}
1450
1451
1452String QuotedString() throws ParseException:
1453{
1454}
1455{
1456 <QUOTED_STRING>
1457 {
1458 return removeQuotesAndEscapes(token.image);
1459 }
1460}
1461
1462
1463String StringLiteral() throws ParseException:
1464{
1465}
1466{
1467 <STRING_LITERAL>
1468 {
1469 return removeQuotesAndEscapes(token.image);
1470 }
1471}
1472
1473Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1474{
1475 String first = null;
1476 String second = null;
1477}
1478{
1479 first = Identifier() (<DOT> second = Identifier())?
1480 {
1481 Identifier id1 = null;
1482 Identifier id2 = null;
1483 if (second == null) {
1484 id2 = new Identifier(first);
1485 } else
1486 {
1487 id1 = new Identifier(first);
1488 id2 = new Identifier(second);
1489 }
1490 return new Pair<Identifier,Identifier>(id1, id2);
1491 }
1492}
1493
1494Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
1495{
1496 String first = null;
1497 String second = null;
1498 String third = null;
1499}
1500{
1501 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
1502 {
1503 Identifier id1 = null;
1504 Identifier id2 = null;
1505 Identifier id3 = null;
1506 if (third == null) {
1507 id2 = new Identifier(first);
1508 id3 = new Identifier(second);
1509 } else {
1510 id1 = new Identifier(first);
1511 id2 = new Identifier(second);
1512 id3 = new Identifier(third);
1513 }
1514 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
1515 }
1516}
1517
1518FunctionDecl FunctionDeclaration() throws ParseException:
1519{
1520 FunctionDecl funcDecl;
1521 FunctionSignature signature;
1522 String functionName;
1523 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1524 Expression funcBody;
1525 createNewScope();
1526}
1527{
1528 <DECLARE> <FUNCTION> functionName = Identifier()
1529 paramList = ParameterList()
1530 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
1531 {
1532 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
1533 getCurrentScope().addFunctionDescriptor(signature, false);
1534 funcDecl = new FunctionDecl(signature, paramList, funcBody);
1535 removeCurrentScope();
1536 return funcDecl;
1537 }
1538}
1539
1540
1541Query Query() throws ParseException:
1542{
1543 Query query = new Query();
1544 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1545 setDataverses(query.getDataverses());
1546 setDatasets(query.getDatasets());
1547 Expression expr;
1548}
1549{
1550 (
1551 expr = Expression()
1552 |
1553 expr = SelectExpression(false)
1554 )
1555 {
1556 query.setBody(expr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001557 // we remove the pointers to the locked entities before we return the query object
1558 setDataverses(null);
1559 setDatasets(null);
1560 return query;
1561 }
1562}
1563
1564
1565
1566Expression Expression():
1567{
1568 Expression expr = null;
1569 Expression exprP = null;
1570}
1571{
1572(
1573 LOOKAHEAD(2)
1574 expr = OperatorExpr()
1575 | expr = IfThenElse()
1576 | expr = QuantifiedExpression()
1577)
1578 {
1579 return (exprP==null) ? expr : exprP;
1580 }
1581}
1582
1583
1584
1585Expression OperatorExpr()throws ParseException:
1586{
1587 OperatorExpr op = null;
1588 Expression operand = null;
1589}
1590{
1591 operand = AndExpr()
1592 (
1593
1594 <OR>
1595 {
1596 if (op == null) {
1597 op = new OperatorExpr();
1598 op.addOperand(operand);
1599 op.setCurrentop(true);
1600 }
1601 op.addOperator(token.image);
1602 }
1603
1604 operand = AndExpr()
1605 {
1606 op.addOperand(operand);
1607 }
1608
1609 )*
1610
1611 {
1612 return op==null? operand: op;
1613 }
1614}
1615
1616Expression AndExpr()throws ParseException:
1617{
1618 OperatorExpr op = null;
1619 Expression operand = null;
1620}
1621{
1622 operand = RelExpr()
1623 (
1624
1625 <AND>
1626 {
1627 if (op == null) {
1628 op = new OperatorExpr();
1629 op.addOperand(operand);
1630 op.setCurrentop(true);
1631 }
1632 op.addOperator(token.image);
1633 }
1634
1635 operand = RelExpr()
1636 {
1637 op.addOperand(operand);
1638 }
1639
1640 )*
1641
1642 {
1643 return op==null? operand: op;
1644 }
1645}
1646
1647
1648
1649Expression RelExpr()throws ParseException:
1650{
1651 OperatorExpr op = null;
1652 Expression operand = null;
1653 boolean broadcast = false;
1654 IExpressionAnnotation annotation = null;
1655}
1656{
1657 operand = AddExpr()
1658 {
1659 if (operand instanceof VariableExpr) {
1660 String hint = getHint(token);
1661 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1662 broadcast = true;
1663 }
1664 }
1665 }
1666
1667 (
1668 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
1669 {
1670 String mhint = getHint(token);
1671 if (mhint != null) {
1672 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1673 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1674 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1675 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1676 }
1677 }
1678 if (op == null) {
1679 op = new OperatorExpr();
1680 op.addOperand(operand, broadcast);
1681 op.setCurrentop(true);
1682 broadcast = false;
1683 }
1684 op.addOperator(token.image);
1685 }
1686
1687 operand = AddExpr()
1688 {
1689 broadcast = false;
1690 if (operand instanceof VariableExpr) {
1691 String hint = getHint(token);
1692 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1693 broadcast = true;
1694 }
1695 }
1696 op.addOperand(operand, broadcast);
1697 }
1698 )?
1699
1700 {
1701 if (annotation != null) {
1702 op.addHint(annotation);
1703 }
1704 return op==null? operand: op;
1705 }
1706}
1707
1708Expression AddExpr()throws ParseException:
1709{
1710 OperatorExpr op = null;
1711 Expression operand = null;
1712}
1713{
1714 operand = MultExpr()
1715 (
1716 LOOKAHEAD(1)
1717 (<PLUS> | <MINUS>)
1718 {
1719 if (op == null) {
1720 op = new OperatorExpr();
1721 op.addOperand(operand);
1722 op.setCurrentop(true);
1723 }
1724 ((OperatorExpr)op).addOperator(token.image);
1725 }
1726
1727 operand = MultExpr()
1728 {
1729 op.addOperand(operand);
1730 }
1731 )*
1732
1733 {
1734 return op==null? operand: op;
1735 }
1736}
1737
1738Expression MultExpr()throws ParseException:
1739{
1740 OperatorExpr op = null;
1741 Expression operand = null;
1742}
1743{
1744 operand = UnaryExpr()
1745
1746 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1747 {
1748 if (op == null) {
1749 op = new OperatorExpr();
1750 op.addOperand(operand);
1751 op.setCurrentop(true);
1752 }
1753 op.addOperator(token.image);
1754 }
1755 operand = UnaryExpr()
1756 {
1757 op.addOperand(operand);
1758 }
1759 )*
1760
1761 {
1762 return op==null?operand:op;
1763 }
1764}
1765
1766Expression UnaryExpr() throws ParseException:
1767{
1768 Expression uexpr = null;
1769 Expression expr = null;
1770}
1771{
1772 ( (<PLUS> | <MINUS>)
1773 {
1774 uexpr = new UnaryExpr();
1775 if("+".equals(token.image))
1776 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1777 else if("-".equals(token.image))
1778 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1779 else
1780 throw new ParseException();
1781 }
1782 )?
1783
1784 expr = ValueExpr()
1785 {
1786 if(uexpr!=null){
1787 ((UnaryExpr)uexpr).setExpr(expr);
1788 return uexpr;
1789 }
1790 else{
1791 return expr;
1792 }
1793 }
1794}
1795
1796Expression ValueExpr()throws ParseException:
1797{
1798 Expression expr = null;
1799 Identifier ident = null;
1800 AbstractAccessor fa = null;
1801 Expression indexExpr = null;
1802}
1803{
1804 expr = PrimaryExpr() (
1805 ident = Field()
1806 {
1807 fa = (fa == null ? new FieldAccessor(expr, ident)
1808 : new FieldAccessor(fa, ident));
1809 }
1810 | indexExpr = Index()
1811 {
1812 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1813 : new IndexAccessor(fa, indexExpr));
1814 }
1815 )*
1816 {
1817 return fa == null ? expr : fa;
1818 }
1819}
1820
1821Identifier Field() throws ParseException:
1822{
1823 String ident = null;
1824}
1825{
1826 <DOT> ident = Identifier()
1827 {
1828 return new Identifier(ident);
1829 }
1830}
1831
1832Expression Index() throws ParseException:
1833{
1834 Expression expr = null;
1835}
1836{
1837 <LEFTBRACKET> ( expr = Expression()
1838 {
1839 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1840 {
1841 Literal lit = ((LiteralExpr)expr).getValue();
1842 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1843 lit.getLiteralType() != Literal.Type.LONG) {
1844 throw new ParseException("Index should be an INTEGER");
1845 }
1846 }
1847 }
1848
1849 | <QUES> // ANY
1850
1851 )
1852
1853 <RIGHTBRACKET>
1854 {
1855 return expr;
1856 }
1857}
1858
1859
1860Expression PrimaryExpr()throws ParseException:
1861{
1862 Expression expr = null;
1863}
1864{
1865 ( LOOKAHEAD(4)
1866 expr = FunctionCallExpr()
1867 | expr = Literal()
1868 | expr = VariableRef()
1869 | expr = ListConstructor()
1870 | expr = RecordConstructor()
1871 | expr = ParenthesizedExpression()
1872 )
1873 {
1874 return expr;
1875 }
1876}
1877
1878Expression Literal() throws ParseException:
1879{
1880 LiteralExpr lit = new LiteralExpr();
1881 String str = null;
1882}
1883{
1884 ( str = StringLiteral()
1885 {
1886 lit.setValue(new StringLiteral(str));
1887 }
1888 | <INTEGER_LITERAL>
1889 {
1890 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1891 }
1892 | <FLOAT_LITERAL>
1893 {
1894 lit.setValue(new FloatLiteral(new Float(token.image)));
1895 }
1896 | <DOUBLE_LITERAL>
1897 {
1898 lit.setValue(new DoubleLiteral(new Double(token.image)));
1899 }
1900 | <NULL>
1901 {
1902 lit.setValue(NullLiteral.INSTANCE);
1903 }
1904 | <TRUE>
1905 {
1906 lit.setValue(TrueLiteral.INSTANCE);
1907 }
1908 | <FALSE>
1909 {
1910 lit.setValue(FalseLiteral.INSTANCE);
1911 }
1912 )
1913 {
1914 return lit;
1915 }
1916}
1917
1918
1919VariableExpr VariableRef() throws ParseException:
1920{
1921 VariableExpr varExp = new VariableExpr();
1922 VarIdentifier var = new VarIdentifier();
1923}
1924{
1925 { String id = null; }
1926 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1927 {
1928 Identifier ident = lookupSymbol(id);
1929 if (isInForbiddenScopes(id)) {
1930 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.");
1931 }
1932 if(ident != null) { // exist such ident
1933 varExp.setIsNewVar(false);
1934 varExp.setVar((VarIdentifier)ident);
1935 } else {
1936 varExp.setVar(var);
1937 }
1938 var.setValue(id);
1939 return varExp;
1940 }
1941}
1942
1943
1944VariableExpr Variable() throws ParseException:
1945{
1946 VariableExpr varExp = new VariableExpr();
1947 VarIdentifier var = new VarIdentifier();
1948}
1949{
1950 { String id = null; }
1951 (<IDENTIFIER> { id = token.image; } | id = QuotedString())
1952 {
1953 Identifier ident = lookupSymbol(id);
1954 if(ident != null) { // exist such ident
1955 varExp.setIsNewVar(false);
1956 }
1957 varExp.setVar(var);
Yingyi Bucaea8f02015-11-16 15:12:15 -08001958 var.setValue(id);
Yingyi Bu391f09e2015-10-29 13:49:39 -07001959 return varExp;
1960 }
1961}
1962
1963Expression ListConstructor() throws ParseException:
1964{
1965 Expression expr = null;
1966}
1967{
1968 (
1969 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1970 )
1971
1972 {
1973 return expr;
1974 }
1975}
1976
1977
1978ListConstructor OrderedListConstructor() throws ParseException:
1979{
1980 ListConstructor expr = new ListConstructor();
1981 List<Expression> exprList = null;
1982 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1983}
1984{
1985 <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
1986 {
1987 expr.setExprList(exprList);
1988 return expr;
1989 }
1990}
1991
1992ListConstructor UnorderedListConstructor() throws ParseException:
1993{
1994 ListConstructor expr = new ListConstructor();
1995 List<Expression> exprList = null;
1996 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1997}
1998{
1999 <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
2000 {
2001 expr.setExprList(exprList);
2002 return expr;
2003 }
2004}
2005
2006List<Expression> ExpressionList() throws ParseException:
2007{
2008 Expression expr = null;
2009 List<Expression> list = null;
2010 List<Expression> exprList = new ArrayList<Expression>();
2011}
2012{
2013 (
2014 expr = Expression() { exprList.add(expr); }
2015 (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
2016 )?
2017 (LOOKAHEAD(1) Comma())?
2018 {
2019 return exprList;
2020 }
2021}
2022
2023void Comma():
2024{}
2025{
2026 <COMMA>
2027}
2028
2029RecordConstructor RecordConstructor() throws ParseException:
2030{
2031 RecordConstructor expr = new RecordConstructor();
2032 FieldBinding tmp = null;
2033 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
2034}
2035{
2036 <LEFTBRACE> (tmp = FieldBinding()
2037 {
2038 fbList.add(tmp);
2039 }
2040 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
2041 {
2042 expr.setFbList(fbList);
2043 return expr;
2044 }
2045}
2046
2047FieldBinding FieldBinding() throws ParseException:
2048{
2049 FieldBinding fb = new FieldBinding();
2050 Expression left, right;
2051}
2052{
2053 left = Expression() <COLON> right = Expression()
2054 {
2055 fb.setLeftExpr(left);
2056 fb.setRightExpr(right);
2057 return fb;
2058 }
2059}
2060
2061
2062Expression FunctionCallExpr() throws ParseException:
2063{
2064 CallExpr callExpr;
2065 List<Expression> argList = new ArrayList<Expression>();
2066 Expression tmp;
2067 int arity = 0;
2068 FunctionName funcName = null;
2069 String hint = null;
2070}
2071{
2072 funcName = FunctionName()
2073 {
2074 hint = funcName.hint;
2075 }
2076 <LEFTPAREN> (tmp = Expression()
2077 {
2078 argList.add(tmp);
2079 arity ++;
2080 }
2081 (<COMMA> tmp = Expression()
2082 {
2083 argList.add(tmp);
2084 arity++;
2085 }
2086 )*)? <RIGHTPAREN>
2087 {
2088 // TODO use funcName.library
2089 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
2090 FunctionSignature signature
2091 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
2092 if (signature == null) {
2093 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
2094 }
2095 callExpr = new CallExpr(signature,argList);
2096 if (hint != null) {
2097 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2098 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2099 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2100 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2101 }
2102 }
2103 return callExpr;
2104 }
2105}
2106
2107Expression ParenthesizedExpression() throws ParseException:
2108{
2109 Expression expr;
2110}
2111{
2112 (
2113 LOOKAHEAD(2)
2114 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2115 |
2116 expr = Subquery()
2117 )
2118 {
2119 return expr;
2120 }
2121}
2122
2123Expression IfThenElse() throws ParseException:
2124{
2125 Expression condExpr;
2126 Expression thenExpr;
2127 Expression elseExpr;
2128 IfExpr ifExpr = new IfExpr();
2129}
2130{
2131 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
2132
2133 {
2134 ifExpr.setCondExpr(condExpr);
2135 ifExpr.setThenExpr(thenExpr);
2136 ifExpr.setElseExpr(elseExpr);
2137 return ifExpr;
2138 }
2139}
2140
2141SelectExpression SelectExpression(boolean subquery) throws ParseException: {
2142 List<LetClause> letClauses = new ArrayList<LetClause>();
2143 SelectSetOperation selectSetOperation;
2144 OrderbyClause orderbyClause = null;
2145 LimitClause limitClause = null;
2146 createNewScope();
2147} {
2148 ( letClauses = LetClause() )?
2149 selectSetOperation = SelectSetOperation()
2150 (orderbyClause = OrderbyClause() {})?
2151 (limitClause = LimitClause() {})?
2152 {
2153 return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
2154 }
2155}
2156
2157SelectSetOperation SelectSetOperation() throws ParseException: {
2158 SetOperationInput setOperationInputLeft;
2159 List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>();
2160}
2161{
2162 {
2163 SelectBlock selectBlockLeft = null;
2164 SelectExpression subqueryLeft = null;
2165 Expression expr = null;
2166 }
2167 selectBlockLeft = SelectBlock()
2168 {
2169 setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft);
2170 }
2171 (
2172 {
2173 SetOpType opType = SetOpType.UNION;
2174 boolean setSemantics = true;
2175 SelectBlock selectBlockRight = null;
2176 SelectExpression subqueryRight = null;
2177 }
2178 (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )?
2179 (selectBlockRight = SelectBlock()| subqueryRight = Subquery())
2180 {
2181 setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight)));
2182 }
2183 )*
2184 {
2185 return new SelectSetOperation(setOperationInputLeft, setOperationRights);
2186 }
2187}
2188
2189SelectExpression Subquery() throws ParseException: {
2190 SelectExpression selectExpr = null;
2191}
2192{
2193 <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN>
2194 {
2195 return selectExpr;
2196 }
2197}
2198
2199SelectBlock SelectBlock() throws ParseException: {
2200 SelectClause selectClause = null;
2201 FromClause fromClause = null;
2202 List<LetClause> fromLetClauses = null;
2203 WhereClause whereClause = null;
2204 GroupbyClause groupbyClause = null;
2205 List<LetClause> gbyLetClauses = null;
2206 HavingClause havingClause = null;
2207}
2208{
2209 (
2210 selectClause = SelectClause()
2211 (
2212 LOOKAHEAD(1)
2213 fromClause = FromClause()
2214 (
2215 LOOKAHEAD(1)
2216 fromLetClauses = LetClause()
2217 )?
2218 )?
2219 (whereClause = WhereClause())?
2220 (
2221 groupbyClause = GroupbyClause()
2222 (
2223 LOOKAHEAD(1)
2224 gbyLetClauses = LetClause()
2225 )?
2226 (havingClause = HavingClause())?
2227 )?
2228 |
2229 fromClause = FromClause()
2230 (
2231 LOOKAHEAD(1)
2232 fromLetClauses = LetClause()
2233 )?
2234 (whereClause = WhereClause())?
2235 (
2236 groupbyClause = GroupbyClause()
2237 (
2238 gbyLetClauses = LetClause()
2239 )?
2240 (havingClause = HavingClause())?
2241 )?
2242 selectClause = SelectClause()
2243 )
2244 {
2245 return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
2246 }
2247}
2248
2249SelectClause SelectClause() throws ParseException: {
2250 SelectRegular selectRegular = null;
2251 SelectElement selectElement = null;
2252 boolean distinct = false;
2253}
2254{
2255 <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
2256 (
2257 selectRegular = SelectRegular()
2258 |
2259 selectElement = SelectElement()
2260 )
2261 {
2262 return new SelectClause(selectElement, selectRegular, distinct);
2263 }
2264}
2265
2266SelectRegular SelectRegular() throws ParseException: {
2267 List<Projection> projections = new ArrayList<Projection>();
2268}
2269{
2270 {
2271 Projection projection = null;
2272 }
2273 projection = Projection() { projections.add(projection); }
2274 ( LOOKAHEAD(2) <COMMA>
2275 projection = Projection() {projections.add(projection);}
2276 )*
2277 {
2278 return new SelectRegular(projections);
2279 }
2280}
2281
2282SelectElement SelectElement() throws ParseException: {
2283 Expression expr = null;
2284 String name = null;
2285}
2286{
2287 (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
2288 {
2289 return new SelectElement(expr);
2290 }
2291}
2292
2293Projection Projection() throws ParseException: {
2294 Expression expr = null;
2295 Identifier identifier = null;
2296 String name = null;
2297 boolean star = false;
2298 boolean exprStar = false;
2299}
2300{
2301 (
2302 LOOKAHEAD(2)
2303 expr= Expression() (<AS>)? name = Identifier()
2304 | expr = Expression() <DOT> <MUL> {exprStar = true; }
2305 | <MUL> {star = true; }
2306 )
2307 {
2308 return new Projection(expr, name, star, exprStar);
2309 }
2310}
2311
2312FromClause FromClause() throws ParseException :
2313{
2314 List<FromTerm> fromTerms = new ArrayList<FromTerm>();
2315 extendCurrentScope();
2316}
2317{
2318 {
2319 FromTerm fromTerm = null;
2320 }
2321 <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
2322 (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
2323 {
2324 return new FromClause(fromTerms);
2325 }
2326}
2327
2328FromTerm FromTerm() throws ParseException :
2329{
2330 Expression leftExpr = null;
2331 VariableExpr leftVar = null;
2332 VariableExpr posVar = null;
2333 List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
2334}
2335{
2336 leftExpr = Expression() (<AS>)? leftVar = Variable() (<AT> posVar = Variable())?
2337 (
2338 {JoinType joinType = JoinType.INNER; }
2339 (joinType = JoinType())?
2340 {
2341 AbstractBinaryCorrelateClause correlateClause = null;
2342 }
2343 (correlateClause = JoinClause(joinType)
2344 |
2345 correlateClause = NestClause(joinType)
2346 |
2347 correlateClause = UnnestClause(joinType)
2348 )
2349 {
2350 correlateClauses.add(correlateClause);
2351 }
2352 )*
2353 {
2354 return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
2355 }
2356}
2357
2358JoinClause JoinClause(JoinType joinType) throws ParseException :
2359{
2360 Expression rightExpr = null;
2361 VariableExpr rightVar = null;
2362 VariableExpr posVar = null;
2363 Expression conditionExpr = null;
2364}
2365{
2366 <JOIN> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2367 {
2368 return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2369 }
2370}
2371
2372NestClause NestClause(JoinType joinType) throws ParseException :
2373{
2374 Expression rightExpr = null;
2375 VariableExpr rightVar = null;
2376 VariableExpr posVar = null;
2377 Expression conditionExpr = null;
2378}
2379{
2380 <NEST> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
2381 {
2382 return new NestClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
2383 }
2384}
2385
2386UnnestClause UnnestClause(JoinType joinType) throws ParseException :
2387{
2388 Expression rightExpr;
2389 VariableExpr rightVar;
2390 VariableExpr posVar = null;
2391}
2392{
2393 (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())?
2394 {
2395 return new UnnestClause(joinType, rightExpr, rightVar, posVar);
2396 }
2397}
2398
2399
2400JoinType JoinType() throws ParseException :
2401{
2402 JoinType joinType = JoinType.INNER;
2403}
2404{
2405 (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; })
2406 {
2407 return joinType;
2408 }
2409}
2410
2411List<LetClause> LetClause() throws ParseException:
2412{
2413 List<LetClause> letList = new ArrayList<LetClause>();
2414 LetClause letClause;
2415}
2416{
2417 (
2418 (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })*
2419 |
2420 <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })*
2421 )
2422 {
2423 return letList;
2424 }
2425}
2426
2427WhereClause WhereClause()throws ParseException :
2428{
2429 WhereClause wc = new WhereClause();
2430 Expression whereExpr;
2431}
2432{
2433 <WHERE> whereExpr = Expression()
2434 {
2435 wc.setWhereExpr(whereExpr);
2436 return wc;
2437 }
2438}
2439
2440OrderbyClause OrderbyClause()throws ParseException :
2441{
2442 OrderbyClause oc = new OrderbyClause();
2443 Expression orderbyExpr;
2444 List<Expression> orderbyList = new ArrayList<Expression>();
2445 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2446 int numOfOrderby = 0;
2447}
2448{
2449 <ORDER>
2450 {
2451 String hint = getHint(token);
2452 if (hint != null) {
2453 if (hint.startsWith(INMEMORY_HINT)) {
2454 String splits[] = hint.split(" +");
2455 int numFrames = Integer.parseInt(splits[1]);
2456 int numTuples = Integer.parseInt(splits[2]);
2457 oc.setNumFrames(numFrames);
2458 oc.setNumTuples(numTuples);
2459 }
2460 }
2461 }
2462 <BY> orderbyExpr = Expression()
2463 {
2464 orderbyList.add(orderbyExpr);
2465 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
2466 }
2467 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2468 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2469 {
2470 modifierList.add(modif);
2471 }
2472
2473 (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression()
2474 {
2475 orderbyList.add(orderbyExpr);
2476 modif = OrderbyClause.OrderModifier.ASC;
2477 }
2478 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2479 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
2480 {
2481 modifierList.add(modif);
2482 }
2483 )*
2484
2485 {
2486 oc.setModifierList(modifierList);
2487 oc.setOrderbyList(orderbyList);
2488 return oc;
2489 }
2490}
2491
2492GroupbyClause GroupbyClause()throws ParseException :
2493{
2494 GroupbyClause gbc = new GroupbyClause();
2495 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
2496 VariableExpr var = null;
2497 VariableExpr withVar = null;
2498 Expression expr = null;
2499 VariableExpr decorVar = null;
2500 Expression decorExpr = null;
2501}
2502{
2503 {
2504 Scope newScope = extendCurrentScopeNoPush(true);
2505 // extendCurrentScope(true);
2506 }
2507 <GROUP>
2508 {
2509 String hint = getHint(token);
2510 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
2511 gbc.setHashGroupByHint(true);
2512 }
2513 }
2514 <BY> (
2515 expr = Expression()
2516 (LOOKAHEAD(1) (<AS>)?
2517 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002518 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002519 {
2520 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
2521 vePairList.add(pair1);
2522 }
2523 ( LOOKAHEAD(1) <COMMA>
2524 expr = Expression()
2525 (LOOKAHEAD(1) (<AS>)?
2526 var = Variable()
Yingyi Bucaea8f02015-11-16 15:12:15 -08002527 )?
Yingyi Bu391f09e2015-10-29 13:49:39 -07002528 {
2529 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
2530 vePairList.add(pair2);
2531 }
2532 )*
2533 )
2534 {
2535 gbc.setGbyPairList(vePairList);
2536 gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>());
2537 gbc.setWithVarList(new ArrayList<VariableExpr>());
2538 replaceCurrentScope(newScope);
2539 return gbc;
2540 }
2541}
2542
2543HavingClause HavingClause() throws ParseException:
2544{
2545 Expression filterExpr = null;
2546}
2547{
2548 <HAVING> filterExpr = Expression()
2549 {
2550 return new HavingClause(filterExpr);
2551 }
2552}
2553
2554LimitClause LimitClause() throws ParseException:
2555{
2556 LimitClause lc = new LimitClause();
2557 Expression expr;
2558 pushForbiddenScope(getCurrentScope());
2559}
2560{
2561 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2562 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
2563
2564 {
2565 popForbiddenScope();
2566 return lc;
2567 }
2568}
2569
2570QuantifiedExpression QuantifiedExpression()throws ParseException:
2571{
2572 QuantifiedExpression qc = new QuantifiedExpression();
2573 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2574 Expression satisfiesExpr;
2575 VariableExpr var;
2576 Expression inExpr;
2577 QuantifiedPair pair;
2578}
2579{
2580 {
2581 createNewScope();
2582 }
2583
2584 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2585 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2586 var = Variable() <IN> inExpr = Expression()
2587 {
2588 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002589 quantifiedList.add(pair);
2590 }
2591 (
2592 <COMMA> var = Variable() <IN> inExpr = Expression()
2593 {
2594 pair = new QuantifiedPair(var, inExpr);
Yingyi Bu391f09e2015-10-29 13:49:39 -07002595 quantifiedList.add(pair);
2596 }
2597 )*
2598 <SATISFIES> satisfiesExpr = Expression()
2599 {
2600 qc.setSatisfiesExpr(satisfiesExpr);
2601 qc.setQuantifiedList(quantifiedList);
2602 removeCurrentScope();
2603 return qc;
2604 }
2605}
2606
2607LetClause LetElement() throws ParseException:
2608{
2609 LetClause lc = new LetClause();
2610 VariableExpr varExp;
2611 Expression beExp;
2612 extendCurrentScope();
2613}
2614{
2615 varExp = Variable() <EQ> beExp = Expression()
2616 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002617 lc.setVarExpr(varExp);
2618 lc.setBindingExpr(beExp);
2619 return lc;
2620 }
2621}
2622
2623LetClause WithElement() throws ParseException:
2624{
2625 LetClause lc = new LetClause();
2626 VariableExpr varExp;
2627 Expression beExp;
2628 extendCurrentScope();
2629}
2630{
2631 varExp = Variable() <AS> beExp = Expression()
2632 {
Yingyi Bu391f09e2015-10-29 13:49:39 -07002633 lc.setVarExpr(varExp);
2634 lc.setBindingExpr(beExp);
2635 return lc;
2636 }
2637}
2638
2639TOKEN_MGR_DECLS:
2640{
2641 public int commentDepth = 0;
2642 public IntStack lexerStateStack = new IntStack();
2643
2644 public void pushState() {
2645 lexerStateStack.push( curLexState );
2646 }
2647
2648 public void popState(String token) {
2649 if (lexerStateStack.size() > 0) {
2650 SwitchTo( lexerStateStack.pop() );
2651 } else {
2652 int errorLine = input_stream.getEndLine();
2653 int errorColumn = input_stream.getEndColumn();
2654 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2655 + "\" but state stack is empty.";
2656 throw new TokenMgrError(msg, -1);
2657 }
2658 }
2659}
2660
2661<DEFAULT,IN_DBL_BRACE>
2662TOKEN [IGNORE_CASE]:
2663{
2664 <ALL : "all">
2665 | <AND : "and">
2666 | <APPLY : "apply">
2667 | <AS : "as">
2668 | <ASC : "asc">
2669 | <AT : "at">
2670 | <AUTOGENERATED : "autogenerated">
2671 | <BTREE : "btree">
2672 | <BY : "by">
2673 | <CASE : "case">
2674 | <CLOSED : "closed">
2675 | <CREATE : "create">
2676 | <COMPACTION : "compaction">
2677 | <COMPACT : "compact">
2678 | <CONNECT : "connect">
2679 | <CORRELATE : "correlate">
2680 | <DATASET : "table">
Yingyi Bu1c0fff52016-03-25 20:23:30 -07002681 | <COLLECTION : "collection">
Yingyi Bu391f09e2015-10-29 13:49:39 -07002682 | <DATAVERSE : "database">
2683 | <DECLARE : "declare">
2684 | <DEFINITION : "definition">
2685 | <DELETE : "delete">
2686 | <DESC : "desc">
2687 | <DISCONNECT : "disconnect">
2688 | <DISTINCT : "distinct">
2689 | <DROP : "drop">
2690 | <ELEMENT : "element">
2691 | <ELSE : "else">
2692 | <ENFORCED : "enforced">
2693 | <EVERY : "every">
2694 | <EXCEPT : "except">
2695 | <EXISTS : "exists">
2696 | <EXTERNAL : "external">
2697 | <FEED : "feed">
2698 | <FILTER : "filter">
2699 | <FLATTEN : "flatten">
2700 | <FOR : "for">
2701 | <FORMAT : "format">
2702 | <FROM : "from">
2703 | <FULL : "full">
2704 | <FUNCTION : "function">
2705 | <GROUP : "group">
2706 | <HAVING : "having">
2707 | <HINTS : "hints">
2708 | <IF : "if">
2709 | <INTO : "into">
2710 | <IN : "in">
2711 | <INDEX : "index">
2712 | <INGESTION : "ingestion">
2713 | <INNER : "inner">
2714 | <INSERT : "insert">
2715 | <INTERNAL : "internal">
2716 | <INTERSECT : "intersect">
2717 | <JOIN : "join">
2718 | <KEYWORD : "keyword">
2719 | <KEY : "key">
2720 | <LEFT : "left">
2721 | <LETTING : "letting">
2722 | <LET : "let">
2723 | <LIMIT : "limit">
2724 | <LOAD : "load">
2725 | <NEST : "nest">
2726 | <NODEGROUP : "nodegroup">
2727 | <NGRAM : "ngram">
2728 | <OFFSET : "offset">
2729 | <ON : "on">
2730 | <OPEN : "open">
2731 | <OR : "or">
2732 | <ORDER : "order">
2733 | <OUTER : "outer">
2734 | <OUTPUT : "output">
2735 | <PATH : "path">
2736 | <POLICY : "policy">
2737 | <PRESORTED : "pre-sorted">
2738 | <PRIMARY : "primary">
2739 | <RAW : "raw">
2740 | <REFRESH : "refresh">
2741 | <RETURN : "return">
2742 | <RTREE : "rtree">
2743 | <RUN : "run">
2744 | <SATISFIES : "satisfies">
2745 | <SECONDARY : "secondary">
2746 | <SELECT : "select">
2747 | <SET : "set">
2748 | <SOME : "some">
2749 | <TEMPORARY : "temporary">
2750 | <THEN : "then">
2751 | <TYPE : "type">
2752 | <TO : "to">
2753 | <UNION : "union">
2754 | <UNNEST : "unnest">
2755 | <VALUE : "value">
2756 | <WHEN : "when">
2757 | <WHERE : "where">
2758 | <WITH : "with">
2759 | <WRITE : "write">
2760 | <UPDATE : "update">
2761 | <USE : "use">
2762 | <USING : "using">
2763}
2764
2765<DEFAULT,IN_DBL_BRACE>
2766TOKEN :
2767{
2768 <CARET : "^">
2769 | <DIV : "/">
2770 | <IDIV : "idiv">
2771 | <MINUS : "-">
2772 | <MOD : "%">
2773 | <MUL : "*">
2774 | <PLUS : "+">
2775
2776 | <LEFTPAREN : "(">
2777 | <RIGHTPAREN : ")">
2778 | <LEFTBRACKET : "[">
2779 | <RIGHTBRACKET : "]">
2780
2781 | <ATT : "@">
2782 | <COLON : ":">
2783 | <COMMA : ",">
2784 | <DOT : ".">
2785 | <QUES : "?">
2786 | <SEMICOLON : ";">
2787 | <SHARP : "#">
2788
2789 | <LT : "<">
2790 | <GT : ">">
2791 | <LE : "<=">
2792 | <GE : ">=">
2793 | <EQ : "=">
2794 | <NE : "!=">
2795 | <SIMILAR : "~=">
2796}
2797
2798<DEFAULT,IN_DBL_BRACE>
2799TOKEN :
2800{
2801 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
2802}
2803
2804<DEFAULT>
2805TOKEN :
2806{
2807 <RIGHTBRACE : "}"> { popState("}"); }
2808}
2809
2810<DEFAULT,IN_DBL_BRACE>
2811TOKEN :
2812{
2813 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
2814}
2815
2816<IN_DBL_BRACE>
2817TOKEN :
2818{
2819 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
2820}
2821
2822<DEFAULT,IN_DBL_BRACE>
2823TOKEN :
2824{
2825 <INTEGER_LITERAL : (<DIGIT>)+ >
2826}
2827
2828<DEFAULT,IN_DBL_BRACE>
2829TOKEN :
2830{
2831 <NULL : "null">
2832 | <TRUE : "true">
2833 | <FALSE : "false">
2834}
2835
2836<DEFAULT,IN_DBL_BRACE>
2837TOKEN :
2838{
2839 <#DIGIT : ["0" - "9"]>
2840}
2841
2842<DEFAULT,IN_DBL_BRACE>
2843TOKEN:
2844{
2845 < DOUBLE_LITERAL: <DIGITS>
2846 | <DIGITS> ( "." <DIGITS> )?
2847 | "." <DIGITS>
2848 >
2849 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
2850 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2851 | "." <DIGITS> ( "f" | "F" )
2852 >
2853 | <DIGITS : (<DIGIT>)+ >
2854}
2855
2856<DEFAULT,IN_DBL_BRACE>
2857TOKEN :
2858{
2859 <#LETTER : ["A" - "Z", "a" - "z"]>
2860 | <SPECIALCHARS : ["$", "_"]>
2861}
2862
2863<DEFAULT,IN_DBL_BRACE>
2864TOKEN :
2865{
2866 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2867 <QUOTED_STRING : "\"" (
2868 <EscapeQuot>
2869 | <EscapeBslash>
2870 | <EscapeSlash>
2871 | <EscapeBspace>
2872 | <EscapeFormf>
2873 | <EscapeNl>
2874 | <EscapeCr>
2875 | <EscapeTab>
2876 | ~["\"","\\"])* "\"">
2877 | <STRING_LITERAL : "\'" (
2878 <EscapeQuot>
2879 | <EscapeApos>
2880 | <EscapeBslash>
2881 | <EscapeSlash>
2882 | <EscapeBspace>
2883 | <EscapeFormf>
2884 | <EscapeNl>
2885 | <EscapeCr>
2886 | <EscapeTab>
2887 | ~["\'","\\"])* "\'">
2888 | < #EscapeQuot: "\\\"" >
2889 | < #EscapeApos: "\\\'" >
2890 | < #EscapeBslash: "\\\\" >
2891 | < #EscapeSlash: "\\/" >
2892 | < #EscapeBspace: "\\b" >
2893 | < #EscapeFormf: "\\f" >
2894 | < #EscapeNl: "\\n" >
2895 | < #EscapeCr: "\\r" >
2896 | < #EscapeTab: "\\t" >
2897}
2898
2899<DEFAULT,IN_DBL_BRACE>
2900TOKEN :
2901{
2902 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
2903}
2904
2905<DEFAULT,IN_DBL_BRACE>
2906SKIP:
2907{
2908 " "
2909 | "\t"
2910 | "\r"
2911 | "\n"
2912}
2913
2914<DEFAULT,IN_DBL_BRACE>
2915SKIP:
2916{
2917 <"//" (~["\n"])* "\n">
2918}
2919
2920<DEFAULT,IN_DBL_BRACE>
2921SKIP:
2922{
2923 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
2924}
2925
2926<DEFAULT,IN_DBL_BRACE>
2927SKIP:
2928{
2929 <"/*"> { pushState(); } : INSIDE_COMMENT
2930}
2931
2932<INSIDE_COMMENT>
2933SPECIAL_TOKEN:
2934{
2935 <"+"(" ")*(~["*"])*>
2936}
2937
2938<INSIDE_COMMENT>
2939SKIP:
2940{
2941 <"/*"> { pushState(); }
2942}
2943
2944<INSIDE_COMMENT>
2945SKIP:
2946{
2947 <"*/"> { popState("*/"); }
2948 | <~[]>
2949}