blob: 70449626e00aaef4accf4f96d5c37fda78dfe5f0 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
Taewoo Kima12d8cd2015-03-04 13:47:08 -08003
vinayakb38b7ca42012-03-05 05:44:15 +00004 STATIC = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08005
vinayakb38b7ca42012-03-05 05:44:15 +00006}
7
8
9PARSER_BEGIN(AQLParser)
10
11package edu.uci.ics.asterix.aql.parser;
12
Eldon Carmand2d78ad2015-05-07 16:23:41 -070013// For AQLParserTokenManager
Till Westmann96c1f172013-08-01 02:05:48 -070014import org.apache.xerces.util.IntStack;
15
Eldon Carmand2d78ad2015-05-07 16:23:41 -070016import 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.LinkedHashMap;
27import java.util.List;
28import java.util.Map;
29
30import edu.uci.ics.asterix.aql.base.Clause;
31import edu.uci.ics.asterix.aql.base.Expression;
32import edu.uci.ics.asterix.aql.base.Literal;
33import edu.uci.ics.asterix.aql.base.Statement;
34import edu.uci.ics.asterix.aql.context.RootScopeFactory;
35import edu.uci.ics.asterix.aql.context.Scope;
36import edu.uci.ics.asterix.aql.expression.AbstractAccessor;
37import edu.uci.ics.asterix.aql.expression.CallExpr;
38import edu.uci.ics.asterix.aql.expression.CompactStatement;
39import edu.uci.ics.asterix.aql.expression.ConnectFeedStatement;
ramangrover29ae85a1d2015-06-26 17:26:05 -070040import edu.uci.ics.asterix.aql.expression.CreateFeedPolicyStatement;
41import edu.uci.ics.asterix.aql.expression.CreatePrimaryFeedStatement;
42import edu.uci.ics.asterix.aql.expression.CreateSecondaryFeedStatement;
Eldon Carmand2d78ad2015-05-07 16:23:41 -070043import edu.uci.ics.asterix.aql.expression.CreateDataverseStatement;
44import edu.uci.ics.asterix.aql.expression.CreateFeedStatement;
45import edu.uci.ics.asterix.aql.expression.CreateFunctionStatement;
46import edu.uci.ics.asterix.aql.expression.CreateIndexStatement;
47import edu.uci.ics.asterix.aql.expression.DatasetDecl;
48import edu.uci.ics.asterix.aql.expression.DataverseDecl;
49import edu.uci.ics.asterix.aql.expression.DataverseDropStatement;
50import edu.uci.ics.asterix.aql.expression.DeleteStatement;
51import edu.uci.ics.asterix.aql.expression.DisconnectFeedStatement;
52import edu.uci.ics.asterix.aql.expression.DistinctClause;
53import edu.uci.ics.asterix.aql.expression.DropStatement;
54import edu.uci.ics.asterix.aql.expression.ExternalDetailsDecl;
55import edu.uci.ics.asterix.aql.expression.FLWOGRExpression;
56import edu.uci.ics.asterix.aql.expression.FeedDropStatement;
57import edu.uci.ics.asterix.aql.expression.FieldAccessor;
58import edu.uci.ics.asterix.aql.expression.FieldBinding;
59import edu.uci.ics.asterix.aql.expression.ForClause;
60import edu.uci.ics.asterix.aql.expression.FunctionDecl;
61import edu.uci.ics.asterix.aql.expression.FunctionDropStatement;
62import edu.uci.ics.asterix.aql.expression.GbyVariableExpressionPair;
63import edu.uci.ics.asterix.aql.expression.GroupbyClause;
64import edu.uci.ics.asterix.aql.expression.Identifier;
65import edu.uci.ics.asterix.aql.expression.IfExpr;
66import edu.uci.ics.asterix.aql.expression.IndexAccessor;
67import edu.uci.ics.asterix.aql.expression.IndexDropStatement;
68import edu.uci.ics.asterix.aql.expression.InsertStatement;
69import edu.uci.ics.asterix.aql.expression.InternalDetailsDecl;
70import edu.uci.ics.asterix.aql.expression.LetClause;
71import edu.uci.ics.asterix.aql.expression.LimitClause;
72import edu.uci.ics.asterix.aql.expression.ListConstructor;
73import edu.uci.ics.asterix.aql.expression.LiteralExpr;
74import edu.uci.ics.asterix.aql.expression.LoadStatement;
75import edu.uci.ics.asterix.aql.expression.NodeGroupDropStatement;
76import edu.uci.ics.asterix.aql.expression.NodegroupDecl;
77import edu.uci.ics.asterix.aql.expression.OperatorExpr;
78import edu.uci.ics.asterix.aql.expression.OrderbyClause;
79import edu.uci.ics.asterix.aql.expression.OrderedListTypeDefinition;
80import edu.uci.ics.asterix.aql.expression.QuantifiedExpression;
81import edu.uci.ics.asterix.aql.expression.QuantifiedPair;
82import edu.uci.ics.asterix.aql.expression.Query;
83import edu.uci.ics.asterix.aql.expression.RecordConstructor;
84import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition;
85import edu.uci.ics.asterix.aql.expression.RefreshExternalDatasetStatement;
86import edu.uci.ics.asterix.aql.expression.RunStatement;
87import edu.uci.ics.asterix.aql.expression.SetStatement;
88import edu.uci.ics.asterix.aql.expression.TypeDecl;
89import edu.uci.ics.asterix.aql.expression.TypeDropStatement;
90import edu.uci.ics.asterix.aql.expression.TypeExpression;
91import edu.uci.ics.asterix.aql.expression.TypeReferenceExpression;
92import edu.uci.ics.asterix.aql.expression.UnaryExpr;
93import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
94import edu.uci.ics.asterix.aql.expression.UnionExpr;
95import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
96import edu.uci.ics.asterix.aql.expression.UpdateClause;
97import edu.uci.ics.asterix.aql.expression.UpdateStatement;
98import edu.uci.ics.asterix.aql.expression.VarIdentifier;
99import edu.uci.ics.asterix.aql.expression.VariableExpr;
100import edu.uci.ics.asterix.aql.expression.WhereClause;
101import edu.uci.ics.asterix.aql.expression.WriteStatement;
vinayakb38b7ca42012-03-05 05:44:15 +0000102import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
103import edu.uci.ics.asterix.aql.literal.FalseLiteral;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700104import edu.uci.ics.asterix.aql.literal.FloatLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +0000105import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +0000106import edu.uci.ics.asterix.aql.literal.NullLiteral;
107import edu.uci.ics.asterix.aql.literal.StringLiteral;
108import edu.uci.ics.asterix.aql.literal.TrueLiteral;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700109import edu.uci.ics.asterix.aql.util.RangeMapBuilder;
110import edu.uci.ics.asterix.common.annotations.AutoDataGen;
111import edu.uci.ics.asterix.common.annotations.DateBetweenYearsDataGen;
112import edu.uci.ics.asterix.common.annotations.DatetimeAddRandHoursDataGen;
113import edu.uci.ics.asterix.common.annotations.DatetimeBetweenYearsDataGen;
114import edu.uci.ics.asterix.common.annotations.FieldIntervalDataGen;
115import edu.uci.ics.asterix.common.annotations.FieldValFileDataGen;
116import edu.uci.ics.asterix.common.annotations.FieldValFileSameIndexDataGen;
117import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
118import edu.uci.ics.asterix.common.annotations.InsertRandIntDataGen;
119import edu.uci.ics.asterix.common.annotations.ListDataGen;
120import edu.uci.ics.asterix.common.annotations.ListValFileDataGen;
121import edu.uci.ics.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
122import edu.uci.ics.asterix.common.annotations.TypeDataGen;
123import edu.uci.ics.asterix.common.annotations.UndeclaredFieldsDataGen;
vinayakb38b7ca42012-03-05 05:44:15 +0000124import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
125import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
vinayakb38b7ca42012-03-05 05:44:15 +0000126import edu.uci.ics.asterix.common.exceptions.AsterixException;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000127import edu.uci.ics.asterix.common.functions.FunctionSignature;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700128import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
129import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
130import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
alexander.behm07617fd2012-07-25 10:13:50 +0000131import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
132import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000133import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700134import edu.uci.ics.hyracks.dataflow.common.data.partition.range.IRangeMap;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000135
136
vinayakb38b7ca42012-03-05 05:44:15 +0000137
138
139public class AQLParser extends ScopeChecker {
140
vinayakb38b7ca42012-03-05 05:44:15 +0000141 // optimizer hints
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700142 private static final String AUTO_HINT = "auto";
vinayakb38b7ca42012-03-05 05:44:15 +0000143 private static final String BROADCAST_JOIN_HINT = "bcast";
vinayakb38b7ca42012-03-05 05:44:15 +0000144 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
vinayakb38b7ca42012-03-05 05:44:15 +0000145 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
146 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
Eldon Carmand2d78ad2015-05-07 16:23:41 -0700147 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
148 private static final String HASH_GROUP_BY_HINT = "hash";
149 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
150 private static final String INMEMORY_HINT = "inmem";
151 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
152 private static final String INTERVAL_HINT = "interval";
153 private static final String LIST_HINT = "list";
154 private static final String LIST_VAL_FILE_HINT = "list-val-file";
155 private static final String RANGE_HINT = "range";
156 private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
157 private static final String VAL_FILE_HINT = "val-files";
158 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800159
160 private static final String GEN_FIELDS_HINT = "gen-fields";
161
vinayakb38b7ca42012-03-05 05:44:15 +0000162 // data generator hints
163 private static final String DGEN_HINT = "dgen";
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800164
Till Westmann31c21f92013-05-08 09:21:53 -0700165 private static class IndexParams {
166 public IndexType type;
167 public int gramLength;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800168
Till Westmann31c21f92013-05-08 09:21:53 -0700169 public IndexParams(IndexType type, int gramLength) {
170 this.type = type;
171 this.gramLength = gramLength;
172 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800173 };
174
ramangrover299f76a5e2013-06-18 10:25:17 -0700175 private static class FunctionName {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800176 public String dataverse = null;
177 public String library = null;
178 public String function = null;
179 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700180
vinayakb38b7ca42012-03-05 05:44:15 +0000181 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -0700182 if (t.specialToken == null) {
183 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800184 }
Till Westmann31c21f92013-05-08 09:21:53 -0700185 String s = t.specialToken.image;
186 int n = s.length();
187 if (n < 2) {
188 return null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800189 }
Till Westmann31c21f92013-05-08 09:21:53 -0700190 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000191 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800192
Till Westmann77cb2f42013-07-15 16:44:19 -0700193 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
194 IRecordFieldDataGen rfdg = null;
195 String splits[] = hint.split(" +");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800196 if (splits[0].equals(VAL_FILE_HINT)) {
Till Westmann77cb2f42013-07-15 16:44:19 -0700197 File[] valFiles = new File[splits.length - 1];
198 for (int k=1; k<splits.length; k++) {
199 valFiles[k-1] = new File(splits[k]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800200 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700201 rfdg = new FieldValFileDataGen(valFiles);
202 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
203 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
204 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
205 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
206 } else if (splits[0].equals(LIST_HINT)) {
207 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
208 } else if (splits[0].equals(INTERVAL_HINT)) {
209 FieldIntervalDataGen.ValueType vt;
210 if (splits[1].equals("int")) {
211 vt = FieldIntervalDataGen.ValueType.INT;
212 } else if (splits[1].equals("long")) {
213 vt = FieldIntervalDataGen.ValueType.LONG;
214 } else if (splits[1].equals("float")) {
215 vt = FieldIntervalDataGen.ValueType.FLOAT;
216 } else if (splits[1].equals("double")) {
217 vt = FieldIntervalDataGen.ValueType.DOUBLE;
218 } else {
219 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
220 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800221 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
Till Westmann77cb2f42013-07-15 16:44:19 -0700222 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
223 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
224 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
225 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
226 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
227 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
228 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
229 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
230 } else if (splits[0].equals(AUTO_HINT)) {
231 rfdg = new AutoDataGen(splits[1]);
232 }
233 return rfdg;
234 }
vinayakb38b7ca42012-03-05 05:44:15 +0000235
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000236 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700237 this(new StringReader(s));
238 super.setInput(s);
239 }
vinayakb38b7ca42012-03-05 05:44:15 +0000240
Till Westmann31c21f92013-05-08 09:21:53 -0700241 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
242 File file = new File(args[0]);
243 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
244 AQLParser parser = new AQLParser(fis);
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700245 List<Statement> st = parser.parse();
Till Westmann31c21f92013-05-08 09:21:53 -0700246 //st.accept(new AQLPrintVisitor(), 0);
247 }
Till Westmanne3e8ffa2014-08-02 17:51:23 -0700248
249 public List<Statement> parse() throws ParseException {
250 try {
251 return Statement();
252 } catch (Error e) {
253 // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
254 // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
255 throw new ParseException(e.getMessage());
256 }
257 }
vinayakb38b7ca42012-03-05 05:44:15 +0000258}
259
260PARSER_END(AQLParser)
261
262
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000263List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000264{
vinayakb38b7ca42012-03-05 05:44:15 +0000265 scopeStack.push(RootScopeFactory.createRootScope(this));
266 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700267 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000268}
269{
Till Westmann31c21f92013-05-08 09:21:53 -0700270 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000271 {
Till Westmann31c21f92013-05-08 09:21:53 -0700272 decls.add(stmt);
273 }
274 )*
275 <EOF>
276 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800277 return decls;
Till Westmann31c21f92013-05-08 09:21:53 -0700278 }
279}
280
281Statement SingleStatement() throws ParseException:
282{
283 Statement stmt = null;
284}
285{
286 (
287 stmt = DataverseDeclaration()
288 | stmt = FunctionDeclaration()
289 | stmt = CreateStatement()
290 | stmt = LoadStatement()
291 | stmt = DropStatement()
292 | stmt = WriteStatement()
293 | stmt = SetStatement()
294 | stmt = InsertStatement()
295 | stmt = DeleteStatement()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800296 | stmt = UpdateStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700297 | stmt = FeedStatement()
salsubaiee0b423fa2013-09-19 19:16:48 -0700298 | stmt = CompactStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700299 | stmt = Query()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700300 | stmt = RefreshExternalDatasetStatement()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800301 | stmt = RunStatement()
Till Westmann31c21f92013-05-08 09:21:53 -0700302 )
303 {
304 return stmt;
305 }
306}
307
308DataverseDecl DataverseDeclaration() throws ParseException:
309{
Till Westmann14a20a72013-05-09 00:06:24 -0700310 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700311}
312{
Till Westmanna4242bc2013-05-08 17:49:55 -0700313 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700314 {
Till Westmann14a20a72013-05-09 00:06:24 -0700315 defaultDataverse = dvName;
316 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700317 }
318}
319
320Statement CreateStatement() throws ParseException:
321{
322 String hint = null;
323 boolean dgen = false;
324 Statement stmt = null;
325}
326{
327 "create"
328 (
329 {
330 hint = getHint(token);
331 if (hint != null && hint.startsWith(DGEN_HINT)) {
332 dgen = true;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800333 }
Till Westmann31c21f92013-05-08 09:21:53 -0700334 }
335 stmt = TypeSpecification(hint, dgen)
336 | stmt = NodegroupSpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800337 | stmt = DatasetSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700338 | stmt = IndexSpecification()
339 | stmt = DataverseSpecification()
340 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700341 | stmt = FeedSpecification()
ramangrover29ae85a1d2015-06-26 17:26:05 -0700342 | stmt = FeedPolicySpecification()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800343 )
Till Westmann31c21f92013-05-08 09:21:53 -0700344 {
345 return stmt;
346 }
347}
348
349TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
350{
351 Pair<Identifier,Identifier> nameComponents = null;
352 boolean ifNotExists = false;
353 TypeExpression typeExpr = null;
354}
355{
ramangrover299f76a5e2013-06-18 10:25:17 -0700356 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700357 "as" typeExpr = TypeExpr()
358 {
359 long numValues = -1;
360 String filename = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800361 if (dgen) {
Till Westmann31c21f92013-05-08 09:21:53 -0700362 String splits[] = hint.split(" +");
363 if (splits.length != 3) {
364 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800365 }
Till Westmann31c21f92013-05-08 09:21:53 -0700366 filename = splits[1];
367 numValues = Long.parseLong(splits[2]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800368 }
Till Westmann31c21f92013-05-08 09:21:53 -0700369 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
370 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
371 }
372}
373
374
375NodegroupDecl NodegroupSpecification() throws ParseException:
376{
Till Westmann14a20a72013-05-09 00:06:24 -0700377 String name = null;
378 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700379 boolean ifNotExists = false;
380 List<Identifier>ncNames = null;
381}
382{
Till Westmanna4242bc2013-05-08 17:49:55 -0700383 "nodegroup" name = Identifier()
384 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700385 {
386 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700387 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700388 }
Till Westmann96c1f172013-08-01 02:05:48 -0700389 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700390 {
Till Westmann14a20a72013-05-09 00:06:24 -0700391 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700392 }
393 )*
394 {
Till Westmann14a20a72013-05-09 00:06:24 -0700395 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700396 }
397}
398
399DatasetDecl DatasetSpecification() throws ParseException:
400{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800401 Pair<Identifier,Identifier> nameComponents = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700402 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700403 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700404 String adapterName = null;
405 Map<String,String> properties = null;
salsubaiee801bffe2013-09-22 23:42:35 -0700406 Map<String,String> compactionPolicyProperties = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700407 FunctionSignature appliedFunction = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700408 List<List<String>> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700409 String nodeGroupName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800410 Map<String,String> hints = new HashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700411 DatasetDecl dsetDecl = null;
zheilbron2467f2e2013-08-23 19:07:31 -0700412 boolean autogenerated = false;
salsubaiee0b423fa2013-09-19 19:16:48 -0700413 String compactionPolicy = null;
buyingyiccd67fe2015-05-19 11:53:39 -0700414 boolean temp = false;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700415 List<String> filterField = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700416}
417{
418 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700419 "external" <DATASET> nameComponents = QualifiedName()
420 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
421 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700422 "using" adapterName = AdapterName() properties = Configuration()
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700423 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700424 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700425 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Till Westmann31c21f92013-05-08 09:21:53 -0700426 {
427 ExternalDetailsDecl edd = new ExternalDetailsDecl();
428 edd.setAdapter(adapterName);
429 edd.setProperties(properties);
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700430 edd.setNodegroupName(nodeGroupName != null? new Identifier(nodeGroupName): null);
431 edd.setCompactionPolicy(compactionPolicy);
432 edd.setCompactionPolicyProperties(compactionPolicyProperties);
Till Westmann14a20a72013-05-09 00:06:24 -0700433 dsetDecl = new DatasetDecl(nameComponents.first,
434 nameComponents.second,
435 new Identifier(typeName),
436 hints,
437 DatasetType.EXTERNAL,
438 edd,
439 ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800440 }
Till Westmann31c21f92013-05-08 09:21:53 -0700441
buyingyiccd67fe2015-05-19 11:53:39 -0700442 | ("internal" | "temporary" {
443 temp = token.image.toLowerCase().equals("temporary");
444 }
445 )?
446 <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700447 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
448 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800449 primaryKeyFields = PrimaryKey()
450 ("autogenerated" { autogenerated = true; } )?
zheilbron2467f2e2013-08-23 19:07:31 -0700451 ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700452 ( "hints" hints = Properties() )?
salsubaiee661b9c72014-07-17 17:19:45 -0700453 ( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700454 ( "with filter on" filterField = NestedField() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700455 {
Till Westmann14a20a72013-05-09 00:06:24 -0700456 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
457 ? new Identifier(nodeGroupName)
458 : null,
salsubaiee801bffe2013-09-22 23:42:35 -0700459 primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700460 autogenerated,
salsubaiee801bffe2013-09-22 23:42:35 -0700461 compactionPolicy,
salsubaieea5af4e02014-07-08 15:20:02 -0700462 compactionPolicyProperties,
buyingyiccd67fe2015-05-19 11:53:39 -0700463 filterField,
464 temp);
Till Westmann14a20a72013-05-09 00:06:24 -0700465 dsetDecl = new DatasetDecl(nameComponents.first,
466 nameComponents.second,
467 new Identifier(typeName),
468 hints,
469 DatasetType.INTERNAL,
470 idd,
471 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700472 }
473 )
474 {
475 return dsetDecl;
476 }
477}
478
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700479RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
480{
481 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
482 Pair<Identifier,Identifier> nameComponents = null;
483 String datasetName = null;
484}
485{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800486 "refresh external" <DATASET> nameComponents = QualifiedName()
487 {
488 redss.setDataverseName(nameComponents.first);
489 redss.setDatasetName(nameComponents.second);
490 return redss;
491 }
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700492}
493
Markus Holzemer52c568e2014-12-18 10:51:49 -0800494RunStatement RunStatement() throws ParseException:
495{
496 String system = null;
497 String tmp;
498 ArrayList<String> parameters = new ArrayList<String>();
499 Pair<Identifier,Identifier> nameComponentsFrom = null;
500 Pair<Identifier,Identifier> nameComponentsTo = null;
501}
502{
503 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
504 {
505 parameters.add(tmp);
506 }
507 )*<RIGHTPAREN>
508 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800509 "to" <DATASET> nameComponentsTo = QualifiedName()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800510 {
511 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
512 }
513}
514
Till Westmann31c21f92013-05-08 09:21:53 -0700515CreateIndexStatement IndexSpecification() throws ParseException:
516{
517 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700518 String indexName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700519 boolean ifNotExists = false;
520 Pair<Identifier,Identifier> nameComponents = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700521 Pair<List<String>, TypeExpression> fieldPair = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700522 IndexParams indexType = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700523 boolean enforced = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700524}
525{
Till Westmanna4242bc2013-05-08 17:49:55 -0700526 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700527 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800528 "on" nameComponents = QualifiedName()
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700529 <LEFTPAREN> ( fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700530 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700531 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700532 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700533 ) (<COMMA> fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700534 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700535 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700536 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700537 )* <RIGHTPAREN> ( "type" indexType = IndexType() )? ( "enforced" { enforced = true; } )?
Till Westmann31c21f92013-05-08 09:21:53 -0700538 {
Till Westmann14a20a72013-05-09 00:06:24 -0700539 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700540 cis.setIfNotExists(ifNotExists);
541 cis.setDataverseName(nameComponents.first);
542 cis.setDatasetName(nameComponents.second);
543 if (indexType != null) {
544 cis.setIndexType(indexType.type);
545 cis.setGramLength(indexType.gramLength);
546 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700547 cis.setEnforced(enforced);
Till Westmann31c21f92013-05-08 09:21:53 -0700548 return cis;
549 }
550}
551
salsubaiee0b423fa2013-09-19 19:16:48 -0700552String CompactionPolicy() throws ParseException :
553{
554 String compactionPolicy = null;
555}
556{
557 compactionPolicy = Identifier()
558 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800559 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700560 }
561}
562
salsubaieea5af4e02014-07-08 15:20:02 -0700563String FilterField() throws ParseException :
564{
565 String filterField = null;
566}
567{
568 filterField = Identifier()
569 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800570 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700571 }
572}
573
Till Westmann31c21f92013-05-08 09:21:53 -0700574IndexParams IndexType() throws ParseException:
575{
576 IndexType type = null;
577 int gramLength = 0;
578}
579{
580 ("btree"
581 {
582 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800583 }
Till Westmann31c21f92013-05-08 09:21:53 -0700584 | "rtree"
585 {
586 type = IndexType.RTREE;
587 }
588 | "keyword"
589 {
JIMAHNb75446d2013-06-03 08:35:27 -0700590 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700591 }
592 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
593 {
JIMAHNb75446d2013-06-03 08:35:27 -0700594 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700595 gramLength = Integer.valueOf(token.image);
596 }
597 <RIGHTPAREN>)
598 {
599 return new IndexParams(type, gramLength);
600 }
601}
602
603CreateDataverseStatement DataverseSpecification() throws ParseException :
604{
Till Westmann14a20a72013-05-09 00:06:24 -0700605 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700606 boolean ifNotExists = false;
607 String format = null;
608}
609{
Till Westmanna4242bc2013-05-08 17:49:55 -0700610 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700611 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700612 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700613 {
Till Westmann14a20a72013-05-09 00:06:24 -0700614 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700615 }
616}
617
618CreateFunctionStatement FunctionSpecification() throws ParseException:
619{
620 FunctionSignature signature;
621 boolean ifNotExists = false;
622 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
623 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700624 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700625 Expression functionBodyExpr;
626 Token beginPos;
627 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700628 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800629
Till Westmann31c21f92013-05-08 09:21:53 -0700630 createNewScope();
631}
632{
ramangrover299f76a5e2013-06-18 10:25:17 -0700633 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700634 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700635 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700636 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530637 {
638 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800639 }
Till Westmann96c1f172013-08-01 02:05:48 -0700640 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700641 {
642 endPos = token;
643 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700644 // TODO use fctName.library
645 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700646 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800647 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700648 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
649 }
650}
651
ramangrover29a774ef22013-07-17 09:29:18 -0700652CreateFeedStatement FeedSpecification() throws ParseException:
653{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800654 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700655 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700656 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700657 Map<String,String> properties = null;
658 FunctionSignature appliedFunction = null;
659 CreateFeedStatement cfs = null;
ramangrover29ae85a1d2015-06-26 17:26:05 -0700660 Pair<Identifier,Identifier> sourceNameComponents = null;
661
ramangrover29a774ef22013-07-17 09:29:18 -0700662}
663{
664 (
ramangrover29ae85a1d2015-06-26 17:26:05 -0700665 "secondary" "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
666 <FROM> "feed" sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())?
ramangrover29a774ef22013-07-17 09:29:18 -0700667 {
ramangrover29ae85a1d2015-06-26 17:26:05 -0700668 cfs = new CreateSecondaryFeedStatement(nameComponents,
669 sourceNameComponents, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800670 }
ramangrover29ae85a1d2015-06-26 17:26:05 -0700671 |
672 ("primary")? "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
673 "using" adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())?
674 {
675 cfs = new CreatePrimaryFeedStatement(nameComponents,
676 adapterName, properties, appliedFunction, ifNotExists);
677 }
ramangrover29a774ef22013-07-17 09:29:18 -0700678 )
679 {
680 return cfs;
681 }
682}
683
ramangrover29ae85a1d2015-06-26 17:26:05 -0700684CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
685{
686 String policyName = null;
687 String basePolicyName = null;
688 String sourcePolicyFile = null;
689 String definition = null;
690 boolean ifNotExists = false;
691 Map<String,String> properties = null;
692 CreateFeedPolicyStatement cfps = null;
693}
694{
695 (
696 "ingestion" "policy" policyName = Identifier() ifNotExists = IfNotExists()
697 <FROM>
698 ("policy" basePolicyName = Identifier() properties = Configuration() ("definition" definition = StringLiteral())?
699 {
700 cfps = new CreateFeedPolicyStatement(policyName,
701 basePolicyName, properties, definition, ifNotExists);
702 }
703 | "path" sourcePolicyFile = Identifier() ("definition" definition = StringLiteral())?
704 {
705 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
706 }
707 )
708
709 )
710 {
711 return cfps;
712 }
713}
714
ramangrover29a774ef22013-07-17 09:29:18 -0700715
716
Till Westmannd7dcb122013-05-16 13:19:09 -0700717List<VarIdentifier> ParameterList() throws ParseException:
718{
719 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
720 VarIdentifier var = null;
721}
722{
Till Westmann31c21f92013-05-08 09:21:53 -0700723 <LEFTPAREN> (<VARIABLE>
724 {
725 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700726 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700727 paramList.add(var);
728 getCurrentScope().addNewVarSymbolToScope(var);
729 }
Till Westmann96c1f172013-08-01 02:05:48 -0700730 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700731 {
732 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700733 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700734 paramList.add(var);
735 getCurrentScope().addNewVarSymbolToScope(var);
736 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700737 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700738 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700739 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700740 }
741}
742
743boolean IfNotExists() throws ParseException:
744{
745}
746{
747 ( "if not exists"
748 {
749 return true;
750 }
751 )?
752 {
753 return false;
754 }
755}
756
757FunctionSignature ApplyFunction() throws ParseException:
758{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530759 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700760 FunctionSignature funcSig = null;
761}
762{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530763 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700764 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530765 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
766 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700767 }
768}
769
ramangrover29566b3a92013-05-28 09:07:10 -0700770String GetPolicy() throws ParseException:
771{
772 String policy = null;
773}
774{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800775 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700776 {
777 return policy;
778 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800779
780}
ramangrover29566b3a92013-05-28 09:07:10 -0700781
Till Westmann31c21f92013-05-08 09:21:53 -0700782FunctionSignature FunctionSignature() throws ParseException:
783{
ramangrover299f76a5e2013-06-18 10:25:17 -0700784 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700785 int arity = 0;
786}
787{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800788 fctName = FunctionName() "@" <INTEGER_LITERAL>
789 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700790 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700791 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
792 throw new ParseException(" invalid arity:" + arity);
793 }
794
ramangrover299f76a5e2013-06-18 10:25:17 -0700795 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800796 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700797 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700798 }
799}
800
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700801List<List<String>> PrimaryKey() throws ParseException:
Till Westmann31c21f92013-05-08 09:21:53 -0700802{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700803 List<String> tmp = null;
804 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Till Westmann31c21f92013-05-08 09:21:53 -0700805}
806{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700807 "primary" "key" tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700808 {
Till Westmann14a20a72013-05-09 00:06:24 -0700809 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700810 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700811 ( <COMMA> tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700812 {
Till Westmann14a20a72013-05-09 00:06:24 -0700813 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700814 }
815 )*
816 {
817 return primaryKeyFields;
818 }
819}
820
821Statement DropStatement() throws ParseException:
822{
Till Westmann14a20a72013-05-09 00:06:24 -0700823 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700824 Pair<Identifier,Identifier> pairId = null;
825 Triple<Identifier,Identifier,Identifier> tripleId = null;
826 FunctionSignature funcSig = null;
827 boolean ifExists = false;
828 Statement stmt = null;
829}
830{
831 "drop"
832 (
833 <DATASET> pairId = QualifiedName() ifExists = IfExists()
834 {
835 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
836 }
837 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
838 {
839 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
840 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700841 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700842 {
Till Westmann14a20a72013-05-09 00:06:24 -0700843 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700844 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700845 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700846 {
847 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
848 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700849 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700850 {
Till Westmann14a20a72013-05-09 00:06:24 -0700851 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700852 }
853 | "function" funcSig = FunctionSignature() ifExists = IfExists()
854 {
855 stmt = new FunctionDropStatement(funcSig, ifExists);
856 }
ramangrover29a774ef22013-07-17 09:29:18 -0700857 | "feed" pairId = QualifiedName() ifExists = IfExists()
858 {
859 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800860 }
Till Westmann31c21f92013-05-08 09:21:53 -0700861 )
862 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800863 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700864 }
865}
866
867boolean IfExists() throws ParseException :
868{
869}
870{
Till Westmann96c1f172013-08-01 02:05:48 -0700871 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700872 {
873 return true;
874 }
875 )?
876 {
877 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000878 }
879}
880
881InsertStatement InsertStatement() throws ParseException:
882{
Till Westmann31c21f92013-05-08 09:21:53 -0700883 Pair<Identifier,Identifier> nameComponents = null;
884 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000885}
886{
Till Westmann31c21f92013-05-08 09:21:53 -0700887 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
888 {
889 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
890 }
vinayakb38b7ca42012-03-05 05:44:15 +0000891}
892
893DeleteStatement DeleteStatement() throws ParseException:
894{
Till Westmann31c21f92013-05-08 09:21:53 -0700895 VariableExpr var = null;
896 Expression condition = null;
897 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300898 // This is related to the new metadata lock management
899 setDataverses(new ArrayList<String>());
900 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800901
vinayakb38b7ca42012-03-05 05:44:15 +0000902}
903{
Till Westmann31c21f92013-05-08 09:21:53 -0700904 "delete" var = Variable()
905 {
906 getCurrentScope().addNewVarSymbolToScope(var.getVar());
907 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800908 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800909 (<WHERE> condition = Expression())?
910 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300911 // First we get the dataverses and datasets that we want to lock
912 List<String> dataverses = getDataverses();
913 List<String> datasets = getDatasets();
914 // we remove the pointer to the dataverses and datasets
915 setDataverses(null);
916 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800917 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
918 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700919 }
vinayakb38b7ca42012-03-05 05:44:15 +0000920}
921
922UpdateStatement UpdateStatement() throws ParseException:
923{
Till Westmann31c21f92013-05-08 09:21:53 -0700924 VariableExpr vars;
925 Expression target;
926 Expression condition;
927 UpdateClause uc;
928 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000929}
930{
Till Westmann96c1f172013-08-01 02:05:48 -0700931 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800932 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700933 <LEFTPAREN> (uc = UpdateClause()
934 {
935 ucs.add(uc);
936 }
Till Westmann96c1f172013-08-01 02:05:48 -0700937 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700938 {
939 ucs.add(uc);
940 }
941 )*) <RIGHTPAREN>
942 {
943 return new UpdateStatement(vars, target, condition, ucs);
944 }
vinayakb38b7ca42012-03-05 05:44:15 +0000945}
946
vinayakb38b7ca42012-03-05 05:44:15 +0000947UpdateClause UpdateClause() throws ParseException:
948{
Till Westmann31c21f92013-05-08 09:21:53 -0700949 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800950 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700951 InsertStatement is = null;
952 DeleteStatement ds = null;
953 UpdateStatement us = null;
954 Expression condition = null;
955 UpdateClause ifbranch = null;
956 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000957}
958{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800959 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700960 | is = InsertStatement()
961 | ds = DeleteStatement()
962 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700963 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
964 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800965 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700966 {
967 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
968 }
vinayakb38b7ca42012-03-05 05:44:15 +0000969}
970
vinayakb38b7ca42012-03-05 05:44:15 +0000971Statement SetStatement() throws ParseException:
972{
973 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700974 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000975}
976{
Till Westmann7d535322013-05-09 00:40:02 -0700977 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700978 {
Till Westmann31c21f92013-05-08 09:21:53 -0700979 return new SetStatement(pn, pv);
980 }
vinayakb38b7ca42012-03-05 05:44:15 +0000981}
982
983Statement WriteStatement() throws ParseException:
984{
Till Westmann14a20a72013-05-09 00:06:24 -0700985 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000986 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000987 Query query;
988 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000989 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000990}
991{
Till Westmann96c1f172013-08-01 02:05:48 -0700992 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700993 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800994 {
995 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000996 }
997}
998
zheilbron28e026f2013-11-20 10:15:15 -0800999LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001000{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001001 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001002 Identifier datasetName = null;
1003 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +00001004 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001005 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001006 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001007}
1008{
Till Westmann31c21f92013-05-08 09:21:53 -07001009 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +00001010 {
Till Westmann31c21f92013-05-08 09:21:53 -07001011 dataverseName = nameComponents.first;
1012 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001013 }
Till Westmann31c21f92013-05-08 09:21:53 -07001014 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001015 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +00001016 {
Till Westmann31c21f92013-05-08 09:21:53 -07001017 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001018 }
1019 )?
Till Westmann31c21f92013-05-08 09:21:53 -07001020 {
zheilbron28e026f2013-11-20 10:15:15 -08001021 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001022 }
vinayakb38b7ca42012-03-05 05:44:15 +00001023}
1024
vinayakb38b7ca42012-03-05 05:44:15 +00001025
Till Westmann31c21f92013-05-08 09:21:53 -07001026String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001027{
ramangrover29669d8f62013-02-11 06:03:32 +00001028 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001029}
1030{
Till Westmann68d99652013-05-09 11:15:21 -07001031 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +00001032 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001033 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001034 }
vinayakb38b7ca42012-03-05 05:44:15 +00001035}
1036
salsubaiee0b423fa2013-09-19 19:16:48 -07001037Statement CompactStatement() throws ParseException:
1038{
1039 Pair<Identifier,Identifier> nameComponents = null;
1040 Statement stmt = null;
1041}
1042{
1043 "compact" <DATASET> nameComponents = QualifiedName()
1044 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001045 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -07001046 }
1047 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001048 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -07001049 }
1050}
1051
Till Westmann31c21f92013-05-08 09:21:53 -07001052Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001053{
ramangrover29a774ef22013-07-17 09:29:18 -07001054 Pair<Identifier,Identifier> feedNameComponents = null;
1055 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001056
Till Westmann31c21f92013-05-08 09:21:53 -07001057 Map<String,String> configuration = null;
1058 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -07001059 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001060}
1061{
Till Westmann31c21f92013-05-08 09:21:53 -07001062 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001063 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -07001064 {
ramangrover29a774ef22013-07-17 09:29:18 -07001065 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -07001066 }
buyingyi2fd7fa62014-11-24 19:31:55 -08001067 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -07001068 {
ramangrover29a774ef22013-07-17 09:29:18 -07001069 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -07001070 }
1071 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001072 {
Till Westmann31c21f92013-05-08 09:21:53 -07001073 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001074 }
1075}
1076
Till Westmann31c21f92013-05-08 09:21:53 -07001077Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001078{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001079 Map<String,String> configuration = new LinkedHashMap<String,String>();
1080 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001081}
1082{
Till Westmann31c21f92013-05-08 09:21:53 -07001083 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001084 {
Till Westmann31c21f92013-05-08 09:21:53 -07001085 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001086 }
Till Westmann96c1f172013-08-01 02:05:48 -07001087 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001088 {
Till Westmann31c21f92013-05-08 09:21:53 -07001089 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001090 }
Till Westmann31c21f92013-05-08 09:21:53 -07001091 )* )? <RIGHTPAREN>
1092 {
1093 return configuration;
1094 }
1095}
1096
1097Pair<String, String> KeyValuePair() throws ParseException:
1098{
1099 String key;
1100 String value;
1101}
1102{
Till Westmann96c1f172013-08-01 02:05:48 -07001103 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -07001104 {
1105 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001106 }
Till Westmann31c21f92013-05-08 09:21:53 -07001107}
1108
1109Map<String,String> Properties() throws ParseException:
1110{
1111 Map<String,String> properties = new HashMap<String,String>();
1112 Pair<String, String> property;
1113}
1114{
1115 ( <LEFTPAREN> property = Property()
1116 {
1117 properties.put(property.first, property.second);
1118 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001119 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -07001120 {
1121 properties.put(property.first, property.second);
1122 }
1123 )* <RIGHTPAREN> )?
1124 {
1125 return properties;
1126 }
1127}
1128
1129Pair<String, String> Property() throws ParseException:
1130{
1131 String key;
1132 String value;
1133}
1134{
Till Westmann96c1f172013-08-01 02:05:48 -07001135 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001136 {
1137 try {
1138 value = "" + Long.valueOf(token.image);
1139 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001140 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001141 }
1142 }
1143 )
1144 {
1145 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001146 }
vinayakb38b7ca42012-03-05 05:44:15 +00001147}
1148
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001149TypeExpression IndexedTypeExpr() throws ParseException:
1150{
1151 TypeExpression typeExpr = null;
1152}
1153{
1154 (
1155 typeExpr = TypeReference()
1156 | typeExpr = OrderedListTypeDef()
1157 | typeExpr = UnorderedListTypeDef()
1158 )
1159 {
1160 return typeExpr;
1161 }
1162}
1163
vinayakb38b7ca42012-03-05 05:44:15 +00001164TypeExpression TypeExpr() throws ParseException:
1165{
1166 TypeExpression typeExpr = null;
1167}
1168{
1169 (
1170 typeExpr = RecordTypeDef()
1171 | typeExpr = TypeReference()
1172 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001173 | typeExpr = UnorderedListTypeDef()
1174 )
vinayakb38b7ca42012-03-05 05:44:15 +00001175 {
1176 return typeExpr;
1177 }
1178}
1179
1180RecordTypeDefinition RecordTypeDef() throws ParseException:
1181{
1182 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001183 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001184}
1185{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001186 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001187 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001188 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001189 {
1190 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001191 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001192 String splits[] = hint.split(" +");
1193 if (splits[0].equals(GEN_FIELDS_HINT)) {
1194 if (splits.length != 5) {
1195 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1196 }
1197 if (!splits[1].equals("int")) {
1198 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001199 }
1200 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001201 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001202 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001203 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001204 }
1205
vinayakb38b7ca42012-03-05 05:44:15 +00001206 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001207 (
1208 RecordField(recType)
1209 ( <COMMA> RecordField(recType) )*
1210 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001211 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001212 {
1213 if (recordKind == null) {
1214 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1215 }
1216 recType.setRecordKind(recordKind);
1217 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001218 }
vinayakb38b7ca42012-03-05 05:44:15 +00001219}
1220
1221void RecordField(RecordTypeDefinition recType) throws ParseException:
1222{
Till Westmann77cb2f42013-07-15 16:44:19 -07001223 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001224 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001225 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001226}
1227{
Till Westmann77cb2f42013-07-15 16:44:19 -07001228 fieldName = Identifier()
1229 {
1230 String hint = getHint(token);
1231 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1232 }
Till Westmann96c1f172013-08-01 02:05:48 -07001233 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001234 {
1235 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001236 }
vinayakb38b7ca42012-03-05 05:44:15 +00001237}
1238
1239TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001240{
Till Westmann14a20a72013-05-09 00:06:24 -07001241 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001242}
1243{
1244 id = Identifier()
1245 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001246 if (id.equalsIgnoreCase("int")) {
1247 id = "int64";
1248 }
1249
Till Westmann14a20a72013-05-09 00:06:24 -07001250 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001251 }
vinayakb38b7ca42012-03-05 05:44:15 +00001252}
1253
1254OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001255{
vinayakb38b7ca42012-03-05 05:44:15 +00001256 TypeExpression type = null;
1257}
1258{
Till Westmann96c1f172013-08-01 02:05:48 -07001259 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001260 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001261 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001262 {
1263 return new OrderedListTypeDefinition(type);
1264 }
1265}
1266
1267
1268UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001269{
vinayakb38b7ca42012-03-05 05:44:15 +00001270 TypeExpression type = null;
1271}
1272{
Till Westmann96c1f172013-08-01 02:05:48 -07001273 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001274 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001275 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001276 {
1277 return new UnorderedListTypeDefinition(type);
1278 }
1279}
1280
ramangrover299f76a5e2013-06-18 10:25:17 -07001281FunctionName FunctionName() throws ParseException:
1282{
1283 String first = null;
1284 String second = null;
1285 String third = null;
1286 boolean secondAfterDot = false;
1287}
1288{
zheilbron555dc9d2013-08-14 19:58:00 -07001289 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001290 {
1291 secondAfterDot = true;
1292 }
1293 ("#" third = Identifier())? | "#" second = Identifier() )?
1294 {
1295 FunctionName result = new FunctionName();
1296 if (second == null) {
1297 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001298 result.library = null;
1299 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001300 } else if (third == null) {
1301 if (secondAfterDot) {
1302 result.dataverse = first;
1303 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001304 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001305 } else {
1306 result.dataverse = defaultDataverse;
1307 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001308 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001309 }
1310 } else {
1311 result.dataverse = first;
1312 result.library = second;
1313 result.function = third;
1314 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001315
1316 if (result.function.equalsIgnoreCase("int")) {
1317 result.function = "int64";
1318 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001319 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001320 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001321}
Till Westmann31c21f92013-05-08 09:21:53 -07001322
ramangrover299f76a5e2013-06-18 10:25:17 -07001323
1324Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001325{
Till Westmann31c21f92013-05-08 09:21:53 -07001326 Pair<Identifier,Identifier> name = null;
1327}
1328{
1329 name = QualifiedName()
1330 {
1331 if (name.first == null) {
1332 name.first = new Identifier(defaultDataverse);
1333 }
1334 return name;
1335 }
1336}
1337
Till Westmann14a20a72013-05-09 00:06:24 -07001338String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001339{
Till Westmann68d99652013-05-09 11:15:21 -07001340 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001341}
1342{
1343 <IDENTIFIER>
1344 {
Till Westmann14a20a72013-05-09 00:06:24 -07001345 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001346 }
Till Westmann68d99652013-05-09 11:15:21 -07001347 | lit = StringLiteral()
1348 {
1349 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001350 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001351}
1352
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001353Pair<List<String>, TypeExpression> OpenField() throws ParseException:
1354{
1355 TypeExpression fieldType = null;
1356 List<String> fieldList = null;
1357}
1358{
1359 fieldList = NestedField()
1360 ( <COLON> fieldType = IndexedTypeExpr() )?
1361 {
1362 return new Pair<List<String>, TypeExpression>(fieldList, fieldType);
1363 }
1364}
1365
1366List<String> NestedField() throws ParseException:
1367{
1368 List<String> exprList = new ArrayList<String>();
1369 String lit = null;
1370}
1371{
1372 lit = Identifier()
1373 {
1374 exprList.add(lit);
1375 }
1376 (<DOT>
1377 lit = Identifier()
1378 {
1379 exprList.add(lit);
1380 }
1381 )*
1382 {
1383 return exprList;
1384 }
1385}
1386
1387
1388
Till Westmann7d535322013-05-09 00:40:02 -07001389String StringLiteral() throws ParseException:
1390{
1391}
1392{
1393 <STRING_LITERAL>
1394 {
1395 return removeQuotesAndEscapes(token.image);
1396 }
1397}
1398
Till Westmann31c21f92013-05-08 09:21:53 -07001399Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1400{
Till Westmann14a20a72013-05-09 00:06:24 -07001401 String first = null;
1402 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001403}
1404{
Till Westmann96c1f172013-08-01 02:05:48 -07001405 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001406 {
Till Westmann14a20a72013-05-09 00:06:24 -07001407 Identifier id1 = null;
1408 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001409 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001410 id2 = new Identifier(first);
1411 } else
1412 {
1413 id1 = new Identifier(first);
1414 id2 = new Identifier(second);
1415 }
1416 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001417 }
1418}
1419
Till Westmann31c21f92013-05-08 09:21:53 -07001420Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001421{
Till Westmann14a20a72013-05-09 00:06:24 -07001422 String first = null;
1423 String second = null;
1424 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001425}
1426{
Till Westmann96c1f172013-08-01 02:05:48 -07001427 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001428 {
Till Westmann14a20a72013-05-09 00:06:24 -07001429 Identifier id1 = null;
1430 Identifier id2 = null;
1431 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001432 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001433 id2 = new Identifier(first);
1434 id3 = new Identifier(second);
1435 } else {
1436 id1 = new Identifier(first);
1437 id2 = new Identifier(second);
1438 id3 = new Identifier(third);
1439 }
1440 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001441 }
1442}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001443
vinayakb38b7ca42012-03-05 05:44:15 +00001444FunctionDecl FunctionDeclaration() throws ParseException:
1445{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001446 FunctionDecl funcDecl;
1447 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001448 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001449 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1450 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001451 createNewScope();
1452}
1453{
Till Westmannd7dcb122013-05-16 13:19:09 -07001454 "declare" "function" functionName = Identifier()
1455 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001456 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001457 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001458 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001459 getCurrentScope().addFunctionDescriptor(signature, false);
1460 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001461 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001462 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001463 }
1464}
1465
vinayakb38b7ca42012-03-05 05:44:15 +00001466
Till Westmann31c21f92013-05-08 09:21:53 -07001467Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001468{
1469 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001470 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1471 setDataverses(query.getDataverses());
1472 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001473 Expression expr;
1474}
1475{
Till Westmann31c21f92013-05-08 09:21:53 -07001476 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001477 {
1478 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001479 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001480 // we remove the pointers to the locked entities before we return the query object
1481 setDataverses(null);
1482 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001483 return query;
1484 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001485
vinayakb38b7ca42012-03-05 05:44:15 +00001486}
1487
1488
1489
1490Expression Expression():
1491{
1492 Expression expr = null;
1493 Expression exprP = null;
1494}
1495{
1496(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001497
vinayakb38b7ca42012-03-05 05:44:15 +00001498//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1499 expr = OperatorExpr()
1500 | expr = IfThenElse()
1501 | expr = FLWOGR()
1502 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001503
vinayakb38b7ca42012-03-05 05:44:15 +00001504
1505)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001506 {
1507 return (exprP==null) ? expr : exprP;
1508 }
vinayakb38b7ca42012-03-05 05:44:15 +00001509}
1510
1511
1512
1513Expression OperatorExpr()throws ParseException:
1514{
1515 OperatorExpr op = null;
1516 Expression operand = null;
1517}
1518{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001519 operand = AndExpr()
1520 (
1521
1522 <OR>
1523 {
1524 if (op == null) {
1525 op = new OperatorExpr();
1526 op.addOperand(operand);
1527 op.setCurrentop(true);
1528 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001529 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001530 }
vinayakb38b7ca42012-03-05 05:44:15 +00001531
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001532 operand = AndExpr()
1533 {
1534 op.addOperand(operand);
1535 }
vinayakb38b7ca42012-03-05 05:44:15 +00001536
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001537 )*
1538
1539 {
1540 return op==null? operand: op;
1541 }
vinayakb38b7ca42012-03-05 05:44:15 +00001542}
1543
1544Expression AndExpr()throws ParseException:
1545{
1546 OperatorExpr op = null;
1547 Expression operand = null;
1548}
1549{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001550 operand = RelExpr()
1551 (
1552
1553 <AND>
1554 {
1555 if (op == null) {
1556 op = new OperatorExpr();
1557 op.addOperand(operand);
1558 op.setCurrentop(true);
1559 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001560 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001561 }
vinayakb38b7ca42012-03-05 05:44:15 +00001562
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001563 operand = RelExpr()
1564 {
1565 op.addOperand(operand);
1566 }
vinayakb38b7ca42012-03-05 05:44:15 +00001567
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001568 )*
1569
1570 {
1571 return op==null? operand: op;
1572 }
vinayakb38b7ca42012-03-05 05:44:15 +00001573}
1574
1575
1576
1577Expression RelExpr()throws ParseException:
1578{
1579 OperatorExpr op = null;
1580 Expression operand = null;
1581 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001582 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001583}
1584{
1585 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001586 {
1587 if (operand instanceof VariableExpr) {
1588 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001589 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001590 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001591 }
1592 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001593 }
vinayakb38b7ca42012-03-05 05:44:15 +00001594
1595 (
Till Westmann96c1f172013-08-01 02:05:48 -07001596 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001597 {
1598 String mhint = getHint(token);
1599 if (mhint != null) {
1600 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001601 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1602 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1603 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1604 }
alexander.behm07617fd2012-07-25 10:13:50 +00001605 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001606 if (op == null) {
1607 op = new OperatorExpr();
1608 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001609 op.setCurrentop(true);
1610 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001611 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001612 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001613 }
1614
1615 operand = AddExpr()
1616 {
1617 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001618 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001619 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001620 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1621 broadcast = true;
1622 }
alexander.behm07617fd2012-07-25 10:13:50 +00001623 }
vinayakb38b7ca42012-03-05 05:44:15 +00001624 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001625 }
vinayakb38b7ca42012-03-05 05:44:15 +00001626 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001627
1628 {
1629 if (annotation != null) {
1630 op.addHint(annotation);
1631 }
1632 return op==null? operand: op;
1633 }
vinayakb38b7ca42012-03-05 05:44:15 +00001634}
1635
1636Expression AddExpr()throws ParseException:
1637{
1638 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001639 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001640}
1641{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001642 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001643
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001644 ( (<PLUS> | <MINUS>)
1645 {
1646 if (op == null) {
1647 op = new OperatorExpr();
1648 op.addOperand(operand);
1649 op.setCurrentop(true);
1650 }
1651 ((OperatorExpr)op).addOperator(token.image);
1652 }
vinayakb38b7ca42012-03-05 05:44:15 +00001653
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001654 operand = MultExpr()
1655 {
1656 op.addOperand(operand);
1657 }
1658 )*
1659
1660 {
1661 return op==null? operand: op;
1662 }
vinayakb38b7ca42012-03-05 05:44:15 +00001663}
1664
1665Expression MultExpr()throws ParseException:
1666{
1667 OperatorExpr op = null;
1668 Expression operand = null;
1669}
1670{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001671 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001672
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001673 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1674 {
1675 if (op == null) {
1676 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001677 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001678 op.setCurrentop(true);
1679 }
1680 op.addOperator(token.image);
1681 }
1682 operand = UnionExpr()
1683 {
1684 op.addOperand(operand);
1685 }
1686 )*
1687
1688 {
1689 return op==null?operand:op;
1690 }
vinayakb38b7ca42012-03-05 05:44:15 +00001691}
1692
1693Expression UnionExpr() throws ParseException:
1694{
1695 UnionExpr union = null;
1696 Expression operand1 = null;
1697 Expression operand2 = null;
1698}
1699{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001700 operand1 = UnaryExpr()
1701 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001702 (operand2 = UnaryExpr()) {
1703 if (union == null) {
1704 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001705 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001706 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001707 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001708 } )*
1709 {
1710 return (union == null)? operand1: union;
1711 }
1712}
1713
1714Expression UnaryExpr() throws ParseException:
1715{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001716 Expression uexpr = null;
1717 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001718}
1719{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001720 ( (<PLUS> | <MINUS>)
1721 {
1722 uexpr = new UnaryExpr();
1723 if("+".equals(token.image))
1724 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1725 else if("-".equals(token.image))
1726 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1727 else
1728 throw new ParseException();
1729 }
1730 )?
1731
1732 expr = ValueExpr()
1733 {
1734 if(uexpr!=null){
1735 ((UnaryExpr)uexpr).setExpr(expr);
1736 return uexpr;
1737 }
1738 else{
1739 return expr;
1740 }
1741 }
vinayakb38b7ca42012-03-05 05:44:15 +00001742}
1743
Till Westmann04478e72013-05-13 23:01:34 -07001744Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001745{
1746 Expression expr = null;
1747 Identifier ident = null;
1748 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001749 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001750}
1751{
Till Westmann04478e72013-05-13 23:01:34 -07001752 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001753 {
1754 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001755 : new FieldAccessor(fa, ident));
1756 }
icetindila611ac72014-05-16 10:10:11 -07001757 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001758 {
icetindila611ac72014-05-16 10:10:11 -07001759 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1760 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001761 }
1762 )*
1763 {
1764 return fa == null ? expr : fa;
1765 }
vinayakb38b7ca42012-03-05 05:44:15 +00001766}
1767
1768Identifier Field() throws ParseException:
1769{
Till Westmann14a20a72013-05-09 00:06:24 -07001770 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001771}
1772{
Till Westmann96c1f172013-08-01 02:05:48 -07001773 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001774 {
Till Westmann14a20a72013-05-09 00:06:24 -07001775 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001776 }
vinayakb38b7ca42012-03-05 05:44:15 +00001777}
1778
icetindila611ac72014-05-16 10:10:11 -07001779Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001780{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001781 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001782}
1783{
Till Westmann96c1f172013-08-01 02:05:48 -07001784 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001785 {
1786 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1787 {
1788 Literal lit = ((LiteralExpr)expr).getValue();
1789 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1790 lit.getLiteralType() != Literal.Type.LONG) {
1791 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001792 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001793 }
1794 }
vinayakb38b7ca42012-03-05 05:44:15 +00001795
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001796 | <QUES> // ANY
1797
1798 )
vinayakb38b7ca42012-03-05 05:44:15 +00001799
Till Westmann96c1f172013-08-01 02:05:48 -07001800 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001801 {
1802 return expr;
1803 }
vinayakb38b7ca42012-03-05 05:44:15 +00001804}
1805
1806
1807Expression PrimaryExpr()throws ParseException:
1808{
1809 Expression expr = null;
1810}
1811{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001812 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001813 expr = FunctionCallExpr()
1814 | expr = Literal()
1815 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001816 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001817 {
1818 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001819 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001820 }
Till Westmann68d99652013-05-09 11:15:21 -07001821 | expr = ListConstructor()
1822 | expr = RecordConstructor()
1823 | expr = ParenthesizedExpression()
1824 )
1825 {
1826 return expr;
1827 }
vinayakb38b7ca42012-03-05 05:44:15 +00001828}
1829
1830Expression Literal() throws ParseException:
1831{
vinayakb38b7ca42012-03-05 05:44:15 +00001832 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001833 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001834}
1835{
Till Westmann7d535322013-05-09 00:40:02 -07001836 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001837 {
Till Westmann7d535322013-05-09 00:40:02 -07001838 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001839 }
1840 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001841 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001842 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001843 }
1844 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001845 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001846 lit.setValue(new FloatLiteral(new Float(token.image)));
1847 }
1848 | <DOUBLE_LITERAL>
1849 {
1850 lit.setValue(new DoubleLiteral(new Double(token.image)));
1851 }
1852 | <NULL>
1853 {
1854 lit.setValue(NullLiteral.INSTANCE);
1855 }
1856 | <TRUE>
1857 {
1858 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001859 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001860 | <FALSE>
1861 {
1862 lit.setValue(FalseLiteral.INSTANCE);
1863 }
1864 )
vinayakb38b7ca42012-03-05 05:44:15 +00001865 {
1866 return lit;
1867 }
1868}
1869
1870
1871VariableExpr VariableRef() throws ParseException:
1872{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001873 VariableExpr varExp = new VariableExpr();
1874 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001875}
1876{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001877 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001878 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001879 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001880 Identifier ident = lookupSymbol(varName);
1881 if (isInForbiddenScopes(varName)) {
1882 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.");
1883 }
1884 if(ident != null) { // exist such ident
1885 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001886 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001887 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001888 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001889 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001890 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001891 return varExp;
1892 }
1893}
1894
1895
1896VariableExpr Variable() throws ParseException:
1897{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001898 VariableExpr varExp = new VariableExpr();
1899 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001900}
1901{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001902 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001903 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001904 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001905 if(ident != null) { // exist such ident
1906 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001907 }
1908 varExp.setVar(var);
1909 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001910 return varExp;
1911 }
1912}
1913
1914Expression ListConstructor() throws ParseException:
1915{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001916 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001917}
1918{
1919 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001920 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001921 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001922
vinayakb38b7ca42012-03-05 05:44:15 +00001923 {
1924 return expr;
1925 }
1926}
1927
1928
1929ListConstructor OrderedListConstructor() throws ParseException:
1930{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001931 ListConstructor expr = new ListConstructor();
1932 Expression tmp = null;
1933 List<Expression> exprList = new ArrayList<Expression>();
1934 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001935}
1936{
1937
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001938 <LEFTBRACKET>
1939 ( tmp = Expression()
1940 {
1941 exprList.add(tmp);
1942 }
1943
1944 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
1945 )?
1946
Till Westmann96c1f172013-08-01 02:05:48 -07001947 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001948
1949 {
1950 expr.setExprList(exprList);
1951 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001952 }
vinayakb38b7ca42012-03-05 05:44:15 +00001953}
1954
1955ListConstructor UnorderedListConstructor() throws ParseException:
1956{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001957 ListConstructor expr = new ListConstructor();
1958 Expression tmp = null;
1959 List<Expression> exprList = new ArrayList<Expression>();
1960 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001961}
1962{
1963
Till Westmann96c1f172013-08-01 02:05:48 -07001964 <LEFTDBLBRACE> ( tmp = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001965 {
1966 exprList.add(tmp);
1967 }
Till Westmann96c1f172013-08-01 02:05:48 -07001968 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001969 {
1970 expr.setExprList(exprList);
1971 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001972 }
vinayakb38b7ca42012-03-05 05:44:15 +00001973}
1974
1975RecordConstructor RecordConstructor() throws ParseException:
1976{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001977 RecordConstructor expr = new RecordConstructor();
1978 FieldBinding tmp = null;
1979 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00001980}
1981{
Till Westmann96c1f172013-08-01 02:05:48 -07001982 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001983 {
1984 fbList.add(tmp);
1985 }
Till Westmann96c1f172013-08-01 02:05:48 -07001986 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001987 {
1988 expr.setFbList(fbList);
1989 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001990 }
vinayakb38b7ca42012-03-05 05:44:15 +00001991}
1992
1993FieldBinding FieldBinding() throws ParseException:
1994{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001995 FieldBinding fb = new FieldBinding();
1996 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00001997}
1998{
Till Westmann96c1f172013-08-01 02:05:48 -07001999 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002000 {
2001 fb.setLeftExpr(left);
2002 fb.setRightExpr(right);
2003 return fb;
2004 }
2005}
2006
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002007
vinayakb38b7ca42012-03-05 05:44:15 +00002008Expression FunctionCallExpr() throws ParseException:
2009{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002010 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002011 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002012 Expression tmp;
2013 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07002014 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07002015 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002016}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002017{
ramangrover299f76a5e2013-06-18 10:25:17 -07002018 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00002019 {
Till Westmann31c21f92013-05-08 09:21:53 -07002020 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002021 }
Till Westmann31c21f92013-05-08 09:21:53 -07002022 <LEFTPAREN> (tmp = Expression()
2023 {
2024 argList.add(tmp);
2025 arity ++;
2026 }
Till Westmann96c1f172013-08-01 02:05:48 -07002027 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07002028 {
2029 argList.add(tmp);
2030 arity++;
2031 }
2032 )*)? <RIGHTPAREN>
2033 {
ramangrover299f76a5e2013-06-18 10:25:17 -07002034 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07002035 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07002036 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07002037 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002038 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07002039 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002040 }
2041 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08002042 if (hint != null) {
2043 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2044 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2045 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2046 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2047 }
Till Westmann31c21f92013-05-08 09:21:53 -07002048 }
2049 return callExpr;
2050 }
vinayakb38b7ca42012-03-05 05:44:15 +00002051}
2052
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002053
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002054Expression DatasetAccessExpression() throws ParseException:
2055{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002056 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07002057 String arg1 = null;
2058 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002059 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002060}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002061{
Till Westmann14a20a72013-05-09 00:06:24 -07002062 <DATASET>
2063 {
Till Westmann14a20a72013-05-09 00:06:24 -07002064 funcName = token.image;
2065 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002066 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07002067 {
2068 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07002069 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07002070 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07002071 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002072 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002073 addDataverse(arg1.toString());
2074 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002075 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002076 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002077 }
Till Westmann14a20a72013-05-09 00:06:24 -07002078 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002079 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07002080 {
Till Westmann1f7a2362013-05-24 08:43:40 -07002081 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2082 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2083 if (signature == null) {
2084 signature = new FunctionSignature(dataverse, funcName, 1);
2085 }
2086 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07002087 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07002088 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07002089 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002090}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002091
vinayakb38b7ca42012-03-05 05:44:15 +00002092Expression ParenthesizedExpression() throws ParseException:
2093{
2094 Expression expr;
2095}
2096{
2097 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2098 {
2099 return expr;
2100 }
2101}
2102
2103Expression IfThenElse() throws ParseException:
2104{
2105 Expression condExpr;
2106 Expression thenExpr;
2107 Expression elseExpr;
2108 IfExpr ifExpr = new IfExpr();
2109}
2110{
Till Westmann96c1f172013-08-01 02:05:48 -07002111 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002112
2113 {
2114 ifExpr.setCondExpr(condExpr);
2115 ifExpr.setThenExpr(thenExpr);
2116 ifExpr.setElseExpr(elseExpr);
2117 return ifExpr;
2118 }
2119}
2120
2121Expression FLWOGR() throws ParseException:
2122{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002123 FLWOGRExpression flworg = new FLWOGRExpression();
2124 List<Clause> clauseList = new ArrayList<Clause>();
2125 Expression returnExpr;
2126 Clause tmp;
2127 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002128}
2129{
2130 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08002131 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002132
2133 {
2134 flworg.setClauseList(clauseList);
2135 flworg.setReturnExpr(returnExpr);
2136 removeCurrentScope();
2137 return flworg;
2138 }
2139}
2140
2141Clause Clause()throws ParseException :
2142{
2143 Clause clause;
2144}
2145{
2146 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002147 clause = ForClause()
2148 | clause = LetClause()
2149 | clause = WhereClause()
2150 | clause = OrderbyClause()
2151 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002152 | clause = LimitClause()
2153 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002154 )
2155 {
2156 return clause;
2157 }
2158}
2159
2160Clause ForClause()throws ParseException :
2161{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002162 ForClause fc = new ForClause();
2163 VariableExpr varExp;
2164 VariableExpr varPos = null;
2165 Expression inExp;
2166 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002167}
2168{
buyingyi2fd7fa62014-11-24 19:31:55 -08002169 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00002170 {
2171 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07002172 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002173 fc.setInExpr(inExp);
2174 if (varPos != null) {
2175 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002176 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002177 }
2178 return fc;
2179 }
2180}
2181
2182Clause LetClause() throws ParseException:
2183{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002184 LetClause lc = new LetClause();
2185 VariableExpr varExp;
2186 Expression beExp;
2187 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002188}
2189{
buyingyi2fd7fa62014-11-24 19:31:55 -08002190 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002191 {
2192 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002193 lc.setVarExpr(varExp);
2194 lc.setBeExpr(beExp);
2195 return lc;
2196 }
2197}
2198
2199Clause WhereClause()throws ParseException :
2200{
2201 WhereClause wc = new WhereClause();
2202 Expression whereExpr;
2203}
2204{
salsubaieedf89fbc2013-12-21 19:51:42 -08002205 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002206 {
2207 wc.setWhereExpr(whereExpr);
2208 return wc;
2209 }
2210}
2211
2212Clause OrderbyClause()throws ParseException :
2213{
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002214 OrderbyClause oc = new OrderbyClause();
2215 Expression orderbyExpr;
2216 List<Expression> orderbyList = new ArrayList<Expression>();
2217 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2218 int numOfOrderby = 0;
vinayakb38b7ca42012-03-05 05:44:15 +00002219}
2220{
2221 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002222 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002223 {
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002224 String hint = getHint(token);
2225 if (hint != null) {
2226 if (hint.startsWith(INMEMORY_HINT)) {
2227 String splits[] = hint.split(" +");
2228 int numFrames = Integer.parseInt(splits[1]);
2229 int numTuples = Integer.parseInt(splits[2]);
2230 oc.setNumFrames(numFrames);
2231 oc.setNumTuples(numTuples);
2232 }
2233 if (hint.startsWith(RANGE_HINT)) {
2234 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
2235 }
2236 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002237 }
Till Westmann96c1f172013-08-01 02:05:48 -07002238 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002239 {
2240 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002241 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002242 }
Till Westmann96c1f172013-08-01 02:05:48 -07002243 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2244 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002245 {
2246 modifierList.add(modif);
2247 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002248
Till Westmann96c1f172013-08-01 02:05:48 -07002249 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002250 {
2251 orderbyList.add(orderbyExpr);
2252 modif = OrderbyClause.OrderModifier.ASC;
2253 }
Till Westmann96c1f172013-08-01 02:05:48 -07002254 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2255 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002256 {
2257 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002258 }
vinayakb38b7ca42012-03-05 05:44:15 +00002259 )*
2260)
2261 {
2262 oc.setModifierList(modifierList);
2263 oc.setOrderbyList(orderbyList);
2264 return oc;
2265 }
2266}
2267Clause GroupClause()throws ParseException :
2268{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002269 GroupbyClause gbc = new GroupbyClause();
2270 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2271 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002272 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002273 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2274 VariableExpr var = null;
2275 VariableExpr withVar = null;
2276 Expression expr = null;
2277 VariableExpr decorVar = null;
2278 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002279}
2280{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002281 {
2282 Scope newScope = extendCurrentScopeNoPush(true);
2283 // extendCurrentScope(true);
2284 }
Till Westmann96c1f172013-08-01 02:05:48 -07002285 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002286 {
2287 String hint = getHint(token);
2288 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002289 gbc.setHashGroupByHint(true);
2290 }
2291 }
Till Westmann96c1f172013-08-01 02:05:48 -07002292 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002293 {
2294 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002295 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002296 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002297 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002298 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002299 vePairList.add(pair1);
2300 }
Till Westmann96c1f172013-08-01 02:05:48 -07002301 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002302 {
2303 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002304 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002305 expr = Expression()
2306 {
2307 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002308 vePairList.add(pair2);
2309 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002310 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002311 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002312 {
2313 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002314 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2315 decorPairList.add(pair3);
2316 }
Till Westmann96c1f172013-08-01 02:05:48 -07002317 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002318 {
2319 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002320 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002321 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002322 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002323 )*
2324 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002325 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002326 {
2327 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002328 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002329 withVarList.add(withVar);
2330 newScope.addNewVarSymbolToScope(withVar.getVar());
2331 }
Till Westmann96c1f172013-08-01 02:05:48 -07002332 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002333 {
2334 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002335 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002336 withVarList.add(withVar);
2337 newScope.addNewVarSymbolToScope(withVar.getVar());
2338 })*
2339 {
2340 gbc.setGbyPairList(vePairList);
2341 gbc.setDecorPairList(decorPairList);
2342 gbc.setWithVarList(withVarList);
2343 replaceCurrentScope(newScope);
2344 return gbc;
2345 }
2346}
2347
2348
2349LimitClause LimitClause() throws ParseException:
2350{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002351 LimitClause lc = new LimitClause();
2352 Expression expr;
2353 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002354}
2355{
Till Westmann96c1f172013-08-01 02:05:48 -07002356 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2357 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002358
2359 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002360 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002361 return lc;
2362 }
2363}
2364
2365DistinctClause DistinctClause() throws ParseException:
2366{
2367 List<Expression> exprs = new ArrayList<Expression>();
2368 Expression expr;
2369}
2370{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002371 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002372 {
2373 exprs.add(expr);
2374 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002375 (<COMMA> expr = Expression()
2376 {
2377 exprs.add(expr);
2378 }
vinayakb38b7ca42012-03-05 05:44:15 +00002379 )*
2380 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002381 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002382 }
2383}
2384
vinayakb38b7ca42012-03-05 05:44:15 +00002385QuantifiedExpression QuantifiedExpression()throws ParseException:
2386{
2387 QuantifiedExpression qc = new QuantifiedExpression();
2388 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2389 Expression satisfiesExpr;
2390 VariableExpr var;
2391 Expression inExpr;
2392 QuantifiedPair pair;
2393}
2394{
2395 {
2396 createNewScope();
2397 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002398
Till Westmann96c1f172013-08-01 02:05:48 -07002399 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002400 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2401 var = Variable() <IN> inExpr = Expression()
2402 {
vinayakb38b7ca42012-03-05 05:44:15 +00002403 pair = new QuantifiedPair(var, inExpr);
2404 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002405 quantifiedList.add(pair);
2406 }
2407 (
2408 <COMMA> var = Variable() <IN> inExpr = Expression()
2409 {
2410 pair = new QuantifiedPair(var, inExpr);
2411 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2412 quantifiedList.add(pair);
2413 }
2414 )*
2415 <SATISFIES> satisfiesExpr = Expression()
2416 {
2417 qc.setSatisfiesExpr(satisfiesExpr);
2418 qc.setQuantifiedList(quantifiedList);
2419 removeCurrentScope();
2420 return qc;
2421 }
vinayakb38b7ca42012-03-05 05:44:15 +00002422}
2423
2424TOKEN_MGR_DECLS:
2425{
Till Westmann96c1f172013-08-01 02:05:48 -07002426 public int commentDepth = 0;
2427 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002428
Till Westmann96c1f172013-08-01 02:05:48 -07002429 public void pushState() {
2430 lexerStateStack.push( curLexState );
2431 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002432
Till Westmannfd733ee2014-07-10 00:57:37 -07002433 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002434 if (lexerStateStack.size() > 0) {
2435 SwitchTo( lexerStateStack.pop() );
2436 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002437 int errorLine = input_stream.getEndLine();
2438 int errorColumn = input_stream.getEndColumn();
2439 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2440 + "\" but state stack is empty.";
2441 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002442 }
2443 }
vinayakb38b7ca42012-03-05 05:44:15 +00002444}
2445
Till Westmann96c1f172013-08-01 02:05:48 -07002446<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002447TOKEN :
2448{
Till Westmann5df7b452013-08-02 13:07:16 -07002449 <ASC : "asc">
2450 | <AT : "at">
2451 | <BY : "by">
2452 | <DATASET : "dataset">
2453 | <DECOR : "decor">
2454 | <DESC : "desc">
2455 | <DISTINCT : "distinct">
2456 | <ELSE : "else">
2457 | <EVERY : "every">
2458 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002459 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002460 | <GROUP : "group">
2461 | <IF : "if">
2462 | <IN : "in">
2463 | <LET : "let">
2464 | <LIMIT : "limit">
2465 | <OFFSET : "offset">
2466 | <ORDER : "order">
2467 | <RETURN : "return">
2468 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002469 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002470 | <SOME : "some">
2471 | <THEN : "then">
2472 | <UNION : "union">
2473 | <WHERE : "where">
2474 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002475 | <KEEPING : "keeping">
vinayakb38b7ca42012-03-05 05:44:15 +00002476}
2477
Till Westmann96c1f172013-08-01 02:05:48 -07002478<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002479TOKEN :
2480{
Till Westmann5df7b452013-08-02 13:07:16 -07002481 <CARET : "^">
2482 | <DIV : "/">
2483 | <IDIV : "idiv">
2484 | <MINUS : "-">
2485 | <MOD : "%">
2486 | <MUL : "*">
2487 | <PLUS : "+">
2488
2489 | <LEFTPAREN : "(">
2490 | <RIGHTPAREN : ")">
2491 | <LEFTBRACKET : "[">
2492 | <RIGHTBRACKET : "]">
2493
2494 | <COLON : ":">
2495 | <COMMA : ",">
2496 | <DOT : ".">
2497 | <QUES : "?">
2498
2499 | <LT : "<">
2500 | <GT : ">">
2501 | <LE : "<=">
2502 | <GE : ">=">
2503 | <EQ : "=">
2504 | <NE : "!=">
2505 | <SIMILAR : "~=">
2506 | <ASSIGN : ":=">
2507
2508 | <AND : "and">
2509 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002510}
2511
Till Westmann96c1f172013-08-01 02:05:48 -07002512<DEFAULT,IN_DBL_BRACE>
2513TOKEN :
2514{
Till Westmann5df7b452013-08-02 13:07:16 -07002515 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002516}
2517
2518<DEFAULT>
2519TOKEN :
2520{
Till Westmannfd733ee2014-07-10 00:57:37 -07002521 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002522}
2523
Till Westmann96c1f172013-08-01 02:05:48 -07002524<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002525TOKEN :
2526{
Till Westmann5df7b452013-08-02 13:07:16 -07002527 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002528}
2529
Till Westmann96c1f172013-08-01 02:05:48 -07002530<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002531TOKEN :
2532{
Till Westmannfd733ee2014-07-10 00:57:37 -07002533 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002534}
2535
Till Westmann96c1f172013-08-01 02:05:48 -07002536<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002537TOKEN :
2538{
Till Westmann5df7b452013-08-02 13:07:16 -07002539 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002540}
2541
Till Westmann96c1f172013-08-01 02:05:48 -07002542<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002543TOKEN :
2544{
Till Westmann5df7b452013-08-02 13:07:16 -07002545 <NULL : "null">
2546 | <TRUE : "true">
2547 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002548}
2549
Till Westmann96c1f172013-08-01 02:05:48 -07002550<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002551TOKEN :
2552{
Till Westmann5df7b452013-08-02 13:07:16 -07002553 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002554}
2555
Till Westmann96c1f172013-08-01 02:05:48 -07002556<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002557TOKEN:
2558{
Till Westmann5df7b452013-08-02 13:07:16 -07002559 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002560 | <DIGITS> ( "." <DIGITS> )?
2561 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002562 >
2563 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002564 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2565 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002566 >
2567 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002568}
2569
Till Westmann96c1f172013-08-01 02:05:48 -07002570<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002571TOKEN :
2572{
Till Westmann5df7b452013-08-02 13:07:16 -07002573 <#LETTER : ["A" - "Z", "a" - "z"]>
2574 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002575}
2576
Till Westmann96c1f172013-08-01 02:05:48 -07002577<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002578TOKEN :
2579{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002580 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2581 <STRING_LITERAL : ("\"" (
2582 <EscapeQuot>
2583 | <EscapeBslash>
2584 | <EscapeSlash>
2585 | <EscapeBspace>
2586 | <EscapeFormf>
2587 | <EscapeNl>
2588 | <EscapeCr>
2589 | <EscapeTab>
2590 | ~["\"","\\"])* "\"")
2591 | ("\'"(
2592 <EscapeApos>
2593 | <EscapeBslash>
2594 | <EscapeSlash>
2595 | <EscapeBspace>
2596 | <EscapeFormf>
2597 | <EscapeNl>
2598 | <EscapeCr>
2599 | <EscapeTab>
2600 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002601 | < #EscapeQuot: "\\\"" >
2602 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002603 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002604 | < #EscapeSlash: "\\/" >
2605 | < #EscapeBspace: "\\b" >
2606 | < #EscapeFormf: "\\f" >
2607 | < #EscapeNl: "\\n" >
2608 | < #EscapeCr: "\\r" >
2609 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002610}
2611
Till Westmann96c1f172013-08-01 02:05:48 -07002612<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002613TOKEN :
2614{
Till Westmann5df7b452013-08-02 13:07:16 -07002615 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002616}
2617
Till Westmann96c1f172013-08-01 02:05:48 -07002618<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002619TOKEN :
2620{
Till Westmann5df7b452013-08-02 13:07:16 -07002621 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002622}
2623
Till Westmann96c1f172013-08-01 02:05:48 -07002624<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002625SKIP:
2626{
2627 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002628 | "\t"
2629 | "\r"
2630 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002631}
2632
Till Westmann96c1f172013-08-01 02:05:48 -07002633<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002634SKIP:
2635{
Till Westmann5df7b452013-08-02 13:07:16 -07002636 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002637}
2638
Till Westmann96c1f172013-08-01 02:05:48 -07002639<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002640SKIP:
2641{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002642 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002643}
2644
Till Westmann96c1f172013-08-01 02:05:48 -07002645<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002646SKIP:
2647{
Till Westmann96c1f172013-08-01 02:05:48 -07002648 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002649}
2650
2651<INSIDE_COMMENT>
2652SPECIAL_TOKEN:
2653{
Till Westmann5df7b452013-08-02 13:07:16 -07002654 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002655}
2656
2657<INSIDE_COMMENT>
2658SKIP:
2659{
Till Westmann96c1f172013-08-01 02:05:48 -07002660 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002661}
2662
2663<INSIDE_COMMENT>
2664SKIP:
2665{
Till Westmannfd733ee2014-07-10 00:57:37 -07002666 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002667 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002668}