blob: 52d2b836b2a6bb2eebaff2a47d37223cf6cb95aa [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);
Till Westmann14a20a72013-05-09 00:06:24 -0700430 dsetDecl = new DatasetDecl(nameComponents.first,
431 nameComponents.second,
432 new Identifier(typeName),
Ildar Absalyamova5895302015-08-17 23:15:41 -0700433 nodeGroupName != null? new Identifier(nodeGroupName): null,
434 compactionPolicy,
435 compactionPolicyProperties,
Till Westmann14a20a72013-05-09 00:06:24 -0700436 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 {
Ildar Absalyamova5895302015-08-17 23:15:41 -0700456 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields,
zheilbron9082e6c2013-10-24 12:25:21 -0700457 autogenerated,
buyingyiccd67fe2015-05-19 11:53:39 -0700458 filterField,
459 temp);
Till Westmann14a20a72013-05-09 00:06:24 -0700460 dsetDecl = new DatasetDecl(nameComponents.first,
461 nameComponents.second,
462 new Identifier(typeName),
Ildar Absalyamova5895302015-08-17 23:15:41 -0700463 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
464 compactionPolicy,
465 compactionPolicyProperties,
Till Westmann14a20a72013-05-09 00:06:24 -0700466 hints,
467 DatasetType.INTERNAL,
468 idd,
469 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700470 }
471 )
472 {
473 return dsetDecl;
474 }
475}
476
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700477RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
478{
479 RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
480 Pair<Identifier,Identifier> nameComponents = null;
481 String datasetName = null;
482}
483{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800484 "refresh external" <DATASET> nameComponents = QualifiedName()
485 {
486 redss.setDataverseName(nameComponents.first);
487 redss.setDatasetName(nameComponents.second);
488 return redss;
489 }
Abdullah Alamoudid9057732014-06-12 13:38:27 -0700490}
491
Markus Holzemer52c568e2014-12-18 10:51:49 -0800492RunStatement RunStatement() throws ParseException:
493{
494 String system = null;
495 String tmp;
496 ArrayList<String> parameters = new ArrayList<String>();
497 Pair<Identifier,Identifier> nameComponentsFrom = null;
498 Pair<Identifier,Identifier> nameComponentsTo = null;
499}
500{
501 "run" system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>]
502 {
503 parameters.add(tmp);
504 }
505 )*<RIGHTPAREN>
506 <FROM> <DATASET> nameComponentsFrom = QualifiedName()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800507 "to" <DATASET> nameComponentsTo = QualifiedName()
Markus Holzemer52c568e2014-12-18 10:51:49 -0800508 {
509 return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
510 }
511}
512
Till Westmann31c21f92013-05-08 09:21:53 -0700513CreateIndexStatement IndexSpecification() throws ParseException:
514{
515 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700516 String indexName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700517 boolean ifNotExists = false;
518 Pair<Identifier,Identifier> nameComponents = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700519 Pair<List<String>, TypeExpression> fieldPair = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700520 IndexParams indexType = null;
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700521 boolean enforced = false;
Till Westmann31c21f92013-05-08 09:21:53 -0700522}
523{
Till Westmanna4242bc2013-05-08 17:49:55 -0700524 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700525 ifNotExists = IfNotExists()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800526 "on" nameComponents = QualifiedName()
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700527 <LEFTPAREN> ( fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700528 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700529 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700530 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700531 ) (<COMMA> fieldPair = OpenField()
Till Westmann31c21f92013-05-08 09:21:53 -0700532 {
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700533 cis.addFieldExprPair(fieldPair);
Till Westmann31c21f92013-05-08 09:21:53 -0700534 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700535 )* <RIGHTPAREN> ( "type" indexType = IndexType() )? ( "enforced" { enforced = true; } )?
Till Westmann31c21f92013-05-08 09:21:53 -0700536 {
Till Westmann14a20a72013-05-09 00:06:24 -0700537 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700538 cis.setIfNotExists(ifNotExists);
539 cis.setDataverseName(nameComponents.first);
540 cis.setDatasetName(nameComponents.second);
541 if (indexType != null) {
542 cis.setIndexType(indexType.type);
543 cis.setGramLength(indexType.gramLength);
544 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700545 cis.setEnforced(enforced);
Till Westmann31c21f92013-05-08 09:21:53 -0700546 return cis;
547 }
548}
549
salsubaiee0b423fa2013-09-19 19:16:48 -0700550String CompactionPolicy() throws ParseException :
551{
552 String compactionPolicy = null;
553}
554{
555 compactionPolicy = Identifier()
556 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800557 return compactionPolicy;
salsubaiee0b423fa2013-09-19 19:16:48 -0700558 }
559}
560
salsubaieea5af4e02014-07-08 15:20:02 -0700561String FilterField() throws ParseException :
562{
563 String filterField = null;
564}
565{
566 filterField = Identifier()
567 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800568 return filterField;
salsubaieea5af4e02014-07-08 15:20:02 -0700569 }
570}
571
Till Westmann31c21f92013-05-08 09:21:53 -0700572IndexParams IndexType() throws ParseException:
573{
574 IndexType type = null;
575 int gramLength = 0;
576}
577{
578 ("btree"
579 {
580 type = IndexType.BTREE;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800581 }
Till Westmann31c21f92013-05-08 09:21:53 -0700582 | "rtree"
583 {
584 type = IndexType.RTREE;
585 }
586 | "keyword"
587 {
JIMAHNb75446d2013-06-03 08:35:27 -0700588 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700589 }
590 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
591 {
JIMAHNb75446d2013-06-03 08:35:27 -0700592 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700593 gramLength = Integer.valueOf(token.image);
594 }
595 <RIGHTPAREN>)
596 {
597 return new IndexParams(type, gramLength);
598 }
599}
600
601CreateDataverseStatement DataverseSpecification() throws ParseException :
602{
Till Westmann14a20a72013-05-09 00:06:24 -0700603 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700604 boolean ifNotExists = false;
605 String format = null;
606}
607{
Till Westmanna4242bc2013-05-08 17:49:55 -0700608 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700609 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700610 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700611 {
Till Westmann14a20a72013-05-09 00:06:24 -0700612 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700613 }
614}
615
616CreateFunctionStatement FunctionSpecification() throws ParseException:
617{
618 FunctionSignature signature;
619 boolean ifNotExists = false;
620 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
621 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700622 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700623 Expression functionBodyExpr;
624 Token beginPos;
625 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700626 FunctionName fctName = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800627
Till Westmann31c21f92013-05-08 09:21:53 -0700628 createNewScope();
629}
630{
ramangrover299f76a5e2013-06-18 10:25:17 -0700631 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700632 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700633 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700634 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530635 {
636 beginPos = token;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800637 }
Till Westmann96c1f172013-08-01 02:05:48 -0700638 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700639 {
640 endPos = token;
641 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700642 // TODO use fctName.library
643 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700644 getCurrentScope().addFunctionDescriptor(signature, false);
Steven Jacobsa84eee42014-12-16 13:55:08 -0800645 removeCurrentScope();
Till Westmannd7dcb122013-05-16 13:19:09 -0700646 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
647 }
648}
649
ramangrover29a774ef22013-07-17 09:29:18 -0700650CreateFeedStatement FeedSpecification() throws ParseException:
651{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800652 Pair<Identifier,Identifier> nameComponents = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700653 boolean ifNotExists = false;
Chris Hillerye64055d2014-10-11 00:14:39 -0700654 String adapterName = null;
ramangrover29a774ef22013-07-17 09:29:18 -0700655 Map<String,String> properties = null;
656 FunctionSignature appliedFunction = null;
657 CreateFeedStatement cfs = null;
ramangrover29ae85a1d2015-06-26 17:26:05 -0700658 Pair<Identifier,Identifier> sourceNameComponents = null;
659
ramangrover29a774ef22013-07-17 09:29:18 -0700660}
661{
662 (
ramangrover29ae85a1d2015-06-26 17:26:05 -0700663 "secondary" "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
664 <FROM> "feed" sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())?
ramangrover29a774ef22013-07-17 09:29:18 -0700665 {
ramangrover29ae85a1d2015-06-26 17:26:05 -0700666 cfs = new CreateSecondaryFeedStatement(nameComponents,
667 sourceNameComponents, appliedFunction, ifNotExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800668 }
ramangrover29ae85a1d2015-06-26 17:26:05 -0700669 |
670 ("primary")? "feed" nameComponents = QualifiedName() ifNotExists = IfNotExists()
671 "using" adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())?
672 {
673 cfs = new CreatePrimaryFeedStatement(nameComponents,
674 adapterName, properties, appliedFunction, ifNotExists);
675 }
ramangrover29a774ef22013-07-17 09:29:18 -0700676 )
677 {
678 return cfs;
679 }
680}
681
ramangrover29ae85a1d2015-06-26 17:26:05 -0700682CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
683{
684 String policyName = null;
685 String basePolicyName = null;
686 String sourcePolicyFile = null;
687 String definition = null;
688 boolean ifNotExists = false;
689 Map<String,String> properties = null;
690 CreateFeedPolicyStatement cfps = null;
691}
692{
693 (
694 "ingestion" "policy" policyName = Identifier() ifNotExists = IfNotExists()
695 <FROM>
696 ("policy" basePolicyName = Identifier() properties = Configuration() ("definition" definition = StringLiteral())?
697 {
698 cfps = new CreateFeedPolicyStatement(policyName,
699 basePolicyName, properties, definition, ifNotExists);
700 }
701 | "path" sourcePolicyFile = Identifier() ("definition" definition = StringLiteral())?
702 {
703 cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
704 }
705 )
706
707 )
708 {
709 return cfps;
710 }
711}
712
ramangrover29a774ef22013-07-17 09:29:18 -0700713
714
Till Westmannd7dcb122013-05-16 13:19:09 -0700715List<VarIdentifier> ParameterList() throws ParseException:
716{
717 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
718 VarIdentifier var = null;
719}
720{
Till Westmann31c21f92013-05-08 09:21:53 -0700721 <LEFTPAREN> (<VARIABLE>
722 {
723 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700724 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700725 paramList.add(var);
726 getCurrentScope().addNewVarSymbolToScope(var);
727 }
Till Westmann96c1f172013-08-01 02:05:48 -0700728 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700729 {
730 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700731 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700732 paramList.add(var);
733 getCurrentScope().addNewVarSymbolToScope(var);
734 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700735 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700736 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700737 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700738 }
739}
740
741boolean IfNotExists() throws ParseException:
742{
743}
744{
745 ( "if not exists"
746 {
747 return true;
748 }
749 )?
750 {
751 return false;
752 }
753}
754
755FunctionSignature ApplyFunction() throws ParseException:
756{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530757 FunctionName functioName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700758 FunctionSignature funcSig = null;
759}
760{
Raman Grover25a2b2e2013-09-27 18:22:23 +0530761 "apply" "function" functioName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700762 {
Raman Grover25a2b2e2013-09-27 18:22:23 +0530763 String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
764 return new FunctionSignature(functioName.dataverse, fqFunctionName, 1);
Till Westmann31c21f92013-05-08 09:21:53 -0700765 }
766}
767
ramangrover29566b3a92013-05-28 09:07:10 -0700768String GetPolicy() throws ParseException:
769{
770 String policy = null;
771}
772{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800773 "using" "policy" policy = Identifier()
ramangrover29566b3a92013-05-28 09:07:10 -0700774 {
775 return policy;
776 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800777
778}
ramangrover29566b3a92013-05-28 09:07:10 -0700779
Till Westmann31c21f92013-05-08 09:21:53 -0700780FunctionSignature FunctionSignature() throws ParseException:
781{
ramangrover299f76a5e2013-06-18 10:25:17 -0700782 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700783 int arity = 0;
784}
785{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800786 fctName = FunctionName() "@" <INTEGER_LITERAL>
787 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700788 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700789 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
790 throw new ParseException(" invalid arity:" + arity);
791 }
792
ramangrover299f76a5e2013-06-18 10:25:17 -0700793 // TODO use fctName.library
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800794 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
ramangrover2993dd8232013-07-03 22:51:25 -0700795 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700796 }
797}
798
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700799List<List<String>> PrimaryKey() throws ParseException:
Till Westmann31c21f92013-05-08 09:21:53 -0700800{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700801 List<String> tmp = null;
802 List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
Till Westmann31c21f92013-05-08 09:21:53 -0700803}
804{
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700805 "primary" "key" tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700806 {
Till Westmann14a20a72013-05-09 00:06:24 -0700807 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700808 }
Ildar Absalyamov04b2b772015-03-19 15:09:51 -0700809 ( <COMMA> tmp = NestedField()
Till Westmann31c21f92013-05-08 09:21:53 -0700810 {
Till Westmann14a20a72013-05-09 00:06:24 -0700811 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700812 }
813 )*
814 {
815 return primaryKeyFields;
816 }
817}
818
819Statement DropStatement() throws ParseException:
820{
Till Westmann14a20a72013-05-09 00:06:24 -0700821 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700822 Pair<Identifier,Identifier> pairId = null;
823 Triple<Identifier,Identifier,Identifier> tripleId = null;
824 FunctionSignature funcSig = null;
825 boolean ifExists = false;
826 Statement stmt = null;
827}
828{
829 "drop"
830 (
831 <DATASET> pairId = QualifiedName() ifExists = IfExists()
832 {
833 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
834 }
835 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
836 {
837 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
838 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700839 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700840 {
Till Westmann14a20a72013-05-09 00:06:24 -0700841 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700842 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700843 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700844 {
845 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
846 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700847 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700848 {
Till Westmann14a20a72013-05-09 00:06:24 -0700849 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700850 }
851 | "function" funcSig = FunctionSignature() ifExists = IfExists()
852 {
853 stmt = new FunctionDropStatement(funcSig, ifExists);
854 }
ramangrover29a774ef22013-07-17 09:29:18 -0700855 | "feed" pairId = QualifiedName() ifExists = IfExists()
856 {
857 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800858 }
Till Westmann31c21f92013-05-08 09:21:53 -0700859 )
860 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800861 return stmt;
Till Westmann31c21f92013-05-08 09:21:53 -0700862 }
863}
864
865boolean IfExists() throws ParseException :
866{
867}
868{
Till Westmann96c1f172013-08-01 02:05:48 -0700869 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700870 {
871 return true;
872 }
873 )?
874 {
875 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000876 }
877}
878
879InsertStatement InsertStatement() throws ParseException:
880{
Till Westmann31c21f92013-05-08 09:21:53 -0700881 Pair<Identifier,Identifier> nameComponents = null;
882 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000883}
884{
Till Westmann31c21f92013-05-08 09:21:53 -0700885 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
886 {
887 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
888 }
vinayakb38b7ca42012-03-05 05:44:15 +0000889}
890
891DeleteStatement DeleteStatement() throws ParseException:
892{
Till Westmann31c21f92013-05-08 09:21:53 -0700893 VariableExpr var = null;
894 Expression condition = null;
895 Pair<Identifier, Identifier> nameComponents;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300896 // This is related to the new metadata lock management
897 setDataverses(new ArrayList<String>());
898 setDatasets(new ArrayList<String>());
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800899
vinayakb38b7ca42012-03-05 05:44:15 +0000900}
901{
Till Westmann31c21f92013-05-08 09:21:53 -0700902 "delete" var = Variable()
903 {
904 getCurrentScope().addNewVarSymbolToScope(var.getVar());
905 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800906 <FROM> <DATASET> nameComponents = QualifiedName()
salsubaieedf89fbc2013-12-21 19:51:42 -0800907 (<WHERE> condition = Expression())?
908 {
Abdullah Alamoudidb37f662014-07-14 21:51:37 +0300909 // First we get the dataverses and datasets that we want to lock
910 List<String> dataverses = getDataverses();
911 List<String> datasets = getDatasets();
912 // we remove the pointer to the dataverses and datasets
913 setDataverses(null);
914 setDatasets(null);
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800915 return new DeleteStatement(var, nameComponents.first, nameComponents.second,
916 condition, getVarCounter(), dataverses, datasets);
Till Westmann31c21f92013-05-08 09:21:53 -0700917 }
vinayakb38b7ca42012-03-05 05:44:15 +0000918}
919
920UpdateStatement UpdateStatement() throws ParseException:
921{
Till Westmann31c21f92013-05-08 09:21:53 -0700922 VariableExpr vars;
923 Expression target;
924 Expression condition;
925 UpdateClause uc;
926 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000927}
928{
Till Westmann96c1f172013-08-01 02:05:48 -0700929 "update" vars = Variable() <IN> target = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800930 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700931 <LEFTPAREN> (uc = UpdateClause()
932 {
933 ucs.add(uc);
934 }
Till Westmann96c1f172013-08-01 02:05:48 -0700935 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700936 {
937 ucs.add(uc);
938 }
939 )*) <RIGHTPAREN>
940 {
941 return new UpdateStatement(vars, target, condition, ucs);
942 }
vinayakb38b7ca42012-03-05 05:44:15 +0000943}
944
vinayakb38b7ca42012-03-05 05:44:15 +0000945UpdateClause UpdateClause() throws ParseException:
946{
Till Westmann31c21f92013-05-08 09:21:53 -0700947 Expression target = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800948 Expression value = null ;
Till Westmann31c21f92013-05-08 09:21:53 -0700949 InsertStatement is = null;
950 DeleteStatement ds = null;
951 UpdateStatement us = null;
952 Expression condition = null;
953 UpdateClause ifbranch = null;
954 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000955}
956{
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800957 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700958 | is = InsertStatement()
959 | ds = DeleteStatement()
960 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700961 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
962 <THEN> ifbranch = UpdateClause()
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800963 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700964 {
965 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
966 }
vinayakb38b7ca42012-03-05 05:44:15 +0000967}
968
vinayakb38b7ca42012-03-05 05:44:15 +0000969Statement SetStatement() throws ParseException:
970{
971 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700972 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000973}
974{
Till Westmann7d535322013-05-09 00:40:02 -0700975 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700976 {
Till Westmann31c21f92013-05-08 09:21:53 -0700977 return new SetStatement(pn, pv);
978 }
vinayakb38b7ca42012-03-05 05:44:15 +0000979}
980
981Statement WriteStatement() throws ParseException:
982{
Till Westmann14a20a72013-05-09 00:06:24 -0700983 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000984 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000985 Query query;
986 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000987 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000988}
989{
Till Westmann96c1f172013-08-01 02:05:48 -0700990 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700991 ( "using" writerClass = StringLiteral() )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -0800992 {
993 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000994 }
995}
996
zheilbron28e026f2013-11-20 10:15:15 -0800997LoadStatement LoadStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000998{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000999 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001000 Identifier datasetName = null;
1001 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +00001002 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001003 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001004 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001005}
1006{
Till Westmann31c21f92013-05-08 09:21:53 -07001007 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +00001008 {
Till Westmann31c21f92013-05-08 09:21:53 -07001009 dataverseName = nameComponents.first;
1010 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +00001011 }
Till Westmann31c21f92013-05-08 09:21:53 -07001012 "using" adapterName = AdapterName() properties = Configuration()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001013 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +00001014 {
Till Westmann31c21f92013-05-08 09:21:53 -07001015 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001016 }
1017 )?
Till Westmann31c21f92013-05-08 09:21:53 -07001018 {
zheilbron28e026f2013-11-20 10:15:15 -08001019 return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001020 }
vinayakb38b7ca42012-03-05 05:44:15 +00001021}
1022
vinayakb38b7ca42012-03-05 05:44:15 +00001023
Till Westmann31c21f92013-05-08 09:21:53 -07001024String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001025{
ramangrover29669d8f62013-02-11 06:03:32 +00001026 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001027}
1028{
Till Westmann68d99652013-05-09 11:15:21 -07001029 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +00001030 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001031 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +00001032 }
vinayakb38b7ca42012-03-05 05:44:15 +00001033}
1034
salsubaiee0b423fa2013-09-19 19:16:48 -07001035Statement CompactStatement() throws ParseException:
1036{
1037 Pair<Identifier,Identifier> nameComponents = null;
1038 Statement stmt = null;
1039}
1040{
1041 "compact" <DATASET> nameComponents = QualifiedName()
1042 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001043 stmt = new CompactStatement(nameComponents.first, nameComponents.second);
salsubaiee0b423fa2013-09-19 19:16:48 -07001044 }
1045 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001046 return stmt;
salsubaiee0b423fa2013-09-19 19:16:48 -07001047 }
1048}
1049
Till Westmann31c21f92013-05-08 09:21:53 -07001050Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001051{
ramangrover29a774ef22013-07-17 09:29:18 -07001052 Pair<Identifier,Identifier> feedNameComponents = null;
1053 Pair<Identifier,Identifier> datasetNameComponents = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001054
Till Westmann31c21f92013-05-08 09:21:53 -07001055 Map<String,String> configuration = null;
1056 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -07001057 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001058}
1059{
Till Westmann31c21f92013-05-08 09:21:53 -07001060 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001061 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -07001062 {
ramangrover29a774ef22013-07-17 09:29:18 -07001063 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -07001064 }
buyingyi2fd7fa62014-11-24 19:31:55 -08001065 | "disconnect" "feed" feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -07001066 {
ramangrover29a774ef22013-07-17 09:29:18 -07001067 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -07001068 }
1069 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001070 {
Till Westmann31c21f92013-05-08 09:21:53 -07001071 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001072 }
1073}
1074
Till Westmann31c21f92013-05-08 09:21:53 -07001075Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +00001076{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001077 Map<String,String> configuration = new LinkedHashMap<String,String>();
1078 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001079}
1080{
Till Westmann31c21f92013-05-08 09:21:53 -07001081 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001082 {
Till Westmann31c21f92013-05-08 09:21:53 -07001083 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001084 }
Till Westmann96c1f172013-08-01 02:05:48 -07001085 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +00001086 {
Till Westmann31c21f92013-05-08 09:21:53 -07001087 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +00001088 }
Till Westmann31c21f92013-05-08 09:21:53 -07001089 )* )? <RIGHTPAREN>
1090 {
1091 return configuration;
1092 }
1093}
1094
1095Pair<String, String> KeyValuePair() throws ParseException:
1096{
1097 String key;
1098 String value;
1099}
1100{
Till Westmann96c1f172013-08-01 02:05:48 -07001101 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -07001102 {
1103 return new Pair<String, String>(key, value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001104 }
Till Westmann31c21f92013-05-08 09:21:53 -07001105}
1106
1107Map<String,String> Properties() throws ParseException:
1108{
1109 Map<String,String> properties = new HashMap<String,String>();
1110 Pair<String, String> property;
1111}
1112{
1113 ( <LEFTPAREN> property = Property()
1114 {
1115 properties.put(property.first, property.second);
1116 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001117 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -07001118 {
1119 properties.put(property.first, property.second);
1120 }
1121 )* <RIGHTPAREN> )?
1122 {
1123 return properties;
1124 }
1125}
1126
1127Pair<String, String> Property() throws ParseException:
1128{
1129 String key;
1130 String value;
1131}
1132{
Till Westmann96c1f172013-08-01 02:05:48 -07001133 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -07001134 {
1135 try {
1136 value = "" + Long.valueOf(token.image);
1137 } catch (NumberFormatException nfe) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001138 throw new ParseException("inapproriate value: " + token.image);
Till Westmann31c21f92013-05-08 09:21:53 -07001139 }
1140 }
1141 )
1142 {
1143 return new Pair<String, String>(key.toUpperCase(), value);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001144 }
vinayakb38b7ca42012-03-05 05:44:15 +00001145}
1146
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001147TypeExpression IndexedTypeExpr() throws ParseException:
1148{
1149 TypeExpression typeExpr = null;
1150}
1151{
1152 (
1153 typeExpr = TypeReference()
1154 | typeExpr = OrderedListTypeDef()
1155 | typeExpr = UnorderedListTypeDef()
1156 )
1157 {
1158 return typeExpr;
1159 }
1160}
1161
vinayakb38b7ca42012-03-05 05:44:15 +00001162TypeExpression TypeExpr() throws ParseException:
1163{
1164 TypeExpression typeExpr = null;
1165}
1166{
1167 (
1168 typeExpr = RecordTypeDef()
1169 | typeExpr = TypeReference()
1170 | typeExpr = OrderedListTypeDef()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001171 | typeExpr = UnorderedListTypeDef()
1172 )
vinayakb38b7ca42012-03-05 05:44:15 +00001173 {
1174 return typeExpr;
1175 }
1176}
1177
1178RecordTypeDefinition RecordTypeDef() throws ParseException:
1179{
1180 RecordTypeDefinition recType = new RecordTypeDefinition();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001181 RecordTypeDefinition.RecordKind recordKind = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001182}
1183{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001184 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
vinayakb38b7ca42012-03-05 05:44:15 +00001185 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -07001186 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001187 {
1188 String hint = getHint(token);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001189 if (hint != null) {
vinayakb38b7ca42012-03-05 05:44:15 +00001190 String splits[] = hint.split(" +");
1191 if (splits[0].equals(GEN_FIELDS_HINT)) {
1192 if (splits.length != 5) {
1193 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
1194 }
1195 if (!splits[1].equals("int")) {
1196 throw new ParseException("The only supported type for gen-fields is int.");
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001197 }
1198 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
vinayakb38b7ca42012-03-05 05:44:15 +00001199 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001200 recType.setUndeclaredFieldsDataGen(ufdg);
vinayakb38b7ca42012-03-05 05:44:15 +00001201 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001202 }
1203
vinayakb38b7ca42012-03-05 05:44:15 +00001204 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001205 (
1206 RecordField(recType)
1207 ( <COMMA> RecordField(recType) )*
1208 )?
Till Westmann96c1f172013-08-01 02:05:48 -07001209 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001210 {
1211 if (recordKind == null) {
1212 recordKind = RecordTypeDefinition.RecordKind.OPEN;
1213 }
1214 recType.setRecordKind(recordKind);
1215 return recType;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001216 }
vinayakb38b7ca42012-03-05 05:44:15 +00001217}
1218
1219void RecordField(RecordTypeDefinition recType) throws ParseException:
1220{
Till Westmann77cb2f42013-07-15 16:44:19 -07001221 String fieldName;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001222 TypeExpression type = null;
Till Westmann77cb2f42013-07-15 16:44:19 -07001223 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +00001224}
1225{
Till Westmann77cb2f42013-07-15 16:44:19 -07001226 fieldName = Identifier()
1227 {
1228 String hint = getHint(token);
1229 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
1230 }
Till Westmann96c1f172013-08-01 02:05:48 -07001231 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -07001232 {
1233 recType.addField(fieldName, type, nullable, rfdg);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001234 }
vinayakb38b7ca42012-03-05 05:44:15 +00001235}
1236
1237TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001238{
Till Westmann14a20a72013-05-09 00:06:24 -07001239 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001240}
1241{
1242 id = Identifier()
1243 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001244 if (id.equalsIgnoreCase("int")) {
1245 id = "int64";
1246 }
1247
Till Westmann14a20a72013-05-09 00:06:24 -07001248 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -07001249 }
vinayakb38b7ca42012-03-05 05:44:15 +00001250}
1251
1252OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001253{
vinayakb38b7ca42012-03-05 05:44:15 +00001254 TypeExpression type = null;
1255}
1256{
Till Westmann96c1f172013-08-01 02:05:48 -07001257 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001258 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001259 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001260 {
1261 return new OrderedListTypeDefinition(type);
1262 }
1263}
1264
1265
1266UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001267{
vinayakb38b7ca42012-03-05 05:44:15 +00001268 TypeExpression type = null;
1269}
1270{
Till Westmann96c1f172013-08-01 02:05:48 -07001271 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001272 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001273 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001274 {
1275 return new UnorderedListTypeDefinition(type);
1276 }
1277}
1278
ramangrover299f76a5e2013-06-18 10:25:17 -07001279FunctionName FunctionName() throws ParseException:
1280{
1281 String first = null;
1282 String second = null;
1283 String third = null;
1284 boolean secondAfterDot = false;
1285}
1286{
zheilbron555dc9d2013-08-14 19:58:00 -07001287 first = Identifier() ( <DOT> second = Identifier()
ramangrover299f76a5e2013-06-18 10:25:17 -07001288 {
1289 secondAfterDot = true;
1290 }
1291 ("#" third = Identifier())? | "#" second = Identifier() )?
1292 {
1293 FunctionName result = new FunctionName();
1294 if (second == null) {
1295 result.dataverse = defaultDataverse;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001296 result.library = null;
1297 result.function = first;
ramangrover299f76a5e2013-06-18 10:25:17 -07001298 } else if (third == null) {
1299 if (secondAfterDot) {
1300 result.dataverse = first;
1301 result.library = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001302 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001303 } else {
1304 result.dataverse = defaultDataverse;
1305 result.library = first;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001306 result.function = second;
ramangrover299f76a5e2013-06-18 10:25:17 -07001307 }
1308 } else {
1309 result.dataverse = first;
1310 result.library = second;
1311 result.function = third;
1312 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001313
1314 if (result.function.equalsIgnoreCase("int")) {
1315 result.function = "int64";
1316 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001317 return result;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001318 }
ramangrover299f76a5e2013-06-18 10:25:17 -07001319}
Till Westmann31c21f92013-05-08 09:21:53 -07001320
ramangrover299f76a5e2013-06-18 10:25:17 -07001321
1322Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001323{
Till Westmann31c21f92013-05-08 09:21:53 -07001324 Pair<Identifier,Identifier> name = null;
1325}
1326{
1327 name = QualifiedName()
1328 {
1329 if (name.first == null) {
1330 name.first = new Identifier(defaultDataverse);
1331 }
1332 return name;
1333 }
1334}
1335
Till Westmann14a20a72013-05-09 00:06:24 -07001336String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001337{
Till Westmann68d99652013-05-09 11:15:21 -07001338 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001339}
1340{
1341 <IDENTIFIER>
1342 {
Till Westmann14a20a72013-05-09 00:06:24 -07001343 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001344 }
Till Westmann68d99652013-05-09 11:15:21 -07001345 | lit = StringLiteral()
1346 {
1347 return lit;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001348 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001349}
1350
Ildar Absalyamov04b2b772015-03-19 15:09:51 -07001351Pair<List<String>, TypeExpression> OpenField() throws ParseException:
1352{
1353 TypeExpression fieldType = null;
1354 List<String> fieldList = null;
1355}
1356{
1357 fieldList = NestedField()
1358 ( <COLON> fieldType = IndexedTypeExpr() )?
1359 {
1360 return new Pair<List<String>, TypeExpression>(fieldList, fieldType);
1361 }
1362}
1363
1364List<String> NestedField() throws ParseException:
1365{
1366 List<String> exprList = new ArrayList<String>();
1367 String lit = null;
1368}
1369{
1370 lit = Identifier()
1371 {
1372 exprList.add(lit);
1373 }
1374 (<DOT>
1375 lit = Identifier()
1376 {
1377 exprList.add(lit);
1378 }
1379 )*
1380 {
1381 return exprList;
1382 }
1383}
1384
1385
1386
Till Westmann7d535322013-05-09 00:40:02 -07001387String StringLiteral() throws ParseException:
1388{
1389}
1390{
1391 <STRING_LITERAL>
1392 {
1393 return removeQuotesAndEscapes(token.image);
1394 }
1395}
1396
Till Westmann31c21f92013-05-08 09:21:53 -07001397Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1398{
Till Westmann14a20a72013-05-09 00:06:24 -07001399 String first = null;
1400 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001401}
1402{
Till Westmann96c1f172013-08-01 02:05:48 -07001403 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001404 {
Till Westmann14a20a72013-05-09 00:06:24 -07001405 Identifier id1 = null;
1406 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001407 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001408 id2 = new Identifier(first);
1409 } else
1410 {
1411 id1 = new Identifier(first);
1412 id2 = new Identifier(second);
1413 }
1414 return new Pair<Identifier,Identifier>(id1, id2);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001415 }
1416}
1417
Till Westmann31c21f92013-05-08 09:21:53 -07001418Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001419{
Till Westmann14a20a72013-05-09 00:06:24 -07001420 String first = null;
1421 String second = null;
1422 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001423}
1424{
Till Westmann96c1f172013-08-01 02:05:48 -07001425 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001426 {
Till Westmann14a20a72013-05-09 00:06:24 -07001427 Identifier id1 = null;
1428 Identifier id2 = null;
1429 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001430 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001431 id2 = new Identifier(first);
1432 id3 = new Identifier(second);
1433 } else {
1434 id1 = new Identifier(first);
1435 id2 = new Identifier(second);
1436 id3 = new Identifier(third);
1437 }
1438 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001439 }
1440}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001441
vinayakb38b7ca42012-03-05 05:44:15 +00001442FunctionDecl FunctionDeclaration() throws ParseException:
1443{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001444 FunctionDecl funcDecl;
1445 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001446 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001447 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1448 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001449 createNewScope();
1450}
1451{
Till Westmannd7dcb122013-05-16 13:19:09 -07001452 "declare" "function" functionName = Identifier()
1453 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001454 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001455 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001456 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001457 getCurrentScope().addFunctionDescriptor(signature, false);
1458 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001459 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001460 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001461 }
1462}
1463
vinayakb38b7ca42012-03-05 05:44:15 +00001464
Till Westmann31c21f92013-05-08 09:21:53 -07001465Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001466{
1467 Query query = new Query();
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001468 // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked
1469 setDataverses(query.getDataverses());
1470 setDatasets(query.getDatasets());
vinayakb38b7ca42012-03-05 05:44:15 +00001471 Expression expr;
1472}
1473{
Till Westmann31c21f92013-05-08 09:21:53 -07001474 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001475 {
1476 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001477 query.setVarCounter(getVarCounter());
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03001478 // we remove the pointers to the locked entities before we return the query object
1479 setDataverses(null);
1480 setDatasets(null);
vinayakb38b7ca42012-03-05 05:44:15 +00001481 return query;
1482 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001483
vinayakb38b7ca42012-03-05 05:44:15 +00001484}
1485
1486
1487
1488Expression Expression():
1489{
1490 Expression expr = null;
1491 Expression exprP = null;
1492}
1493{
1494(
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001495
vinayakb38b7ca42012-03-05 05:44:15 +00001496//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1497 expr = OperatorExpr()
1498 | expr = IfThenElse()
1499 | expr = FLWOGR()
1500 | expr = QuantifiedExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001501
vinayakb38b7ca42012-03-05 05:44:15 +00001502
1503)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001504 {
1505 return (exprP==null) ? expr : exprP;
1506 }
vinayakb38b7ca42012-03-05 05:44:15 +00001507}
1508
1509
1510
1511Expression OperatorExpr()throws ParseException:
1512{
1513 OperatorExpr op = null;
1514 Expression operand = null;
1515}
1516{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001517 operand = AndExpr()
1518 (
1519
1520 <OR>
1521 {
1522 if (op == null) {
1523 op = new OperatorExpr();
1524 op.addOperand(operand);
1525 op.setCurrentop(true);
1526 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001527 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001528 }
vinayakb38b7ca42012-03-05 05:44:15 +00001529
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001530 operand = AndExpr()
1531 {
1532 op.addOperand(operand);
1533 }
vinayakb38b7ca42012-03-05 05:44:15 +00001534
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001535 )*
1536
1537 {
1538 return op==null? operand: op;
1539 }
vinayakb38b7ca42012-03-05 05:44:15 +00001540}
1541
1542Expression AndExpr()throws ParseException:
1543{
1544 OperatorExpr op = null;
1545 Expression operand = null;
1546}
1547{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001548 operand = RelExpr()
1549 (
1550
1551 <AND>
1552 {
1553 if (op == null) {
1554 op = new OperatorExpr();
1555 op.addOperand(operand);
1556 op.setCurrentop(true);
1557 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001558 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001559 }
vinayakb38b7ca42012-03-05 05:44:15 +00001560
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001561 operand = RelExpr()
1562 {
1563 op.addOperand(operand);
1564 }
vinayakb38b7ca42012-03-05 05:44:15 +00001565
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001566 )*
1567
1568 {
1569 return op==null? operand: op;
1570 }
vinayakb38b7ca42012-03-05 05:44:15 +00001571}
1572
1573
1574
1575Expression RelExpr()throws ParseException:
1576{
1577 OperatorExpr op = null;
1578 Expression operand = null;
1579 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001580 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001581}
1582{
1583 operand = AddExpr()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001584 {
1585 if (operand instanceof VariableExpr) {
1586 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001587 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001588 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001589 }
1590 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001591 }
vinayakb38b7ca42012-03-05 05:44:15 +00001592
1593 (
Till Westmann96c1f172013-08-01 02:05:48 -07001594 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001595 {
1596 String mhint = getHint(token);
1597 if (mhint != null) {
1598 if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
salsubaieedf89fbc2013-12-21 19:51:42 -08001599 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1600 } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
1601 annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
1602 }
alexander.behm07617fd2012-07-25 10:13:50 +00001603 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001604 if (op == null) {
1605 op = new OperatorExpr();
1606 op.addOperand(operand, broadcast);
vinayakb38b7ca42012-03-05 05:44:15 +00001607 op.setCurrentop(true);
1608 broadcast = false;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001609 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001610 op.addOperator(token.image);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001611 }
1612
1613 operand = AddExpr()
1614 {
1615 broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001616 if (operand instanceof VariableExpr) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001617 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001618 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1619 broadcast = true;
1620 }
alexander.behm07617fd2012-07-25 10:13:50 +00001621 }
vinayakb38b7ca42012-03-05 05:44:15 +00001622 op.addOperand(operand, broadcast);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001623 }
vinayakb38b7ca42012-03-05 05:44:15 +00001624 )?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001625
1626 {
1627 if (annotation != null) {
1628 op.addHint(annotation);
1629 }
1630 return op==null? operand: op;
1631 }
vinayakb38b7ca42012-03-05 05:44:15 +00001632}
1633
1634Expression AddExpr()throws ParseException:
1635{
1636 OperatorExpr op = null;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001637 Expression operand = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001638}
1639{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001640 operand = MultExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001641
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001642 ( (<PLUS> | <MINUS>)
1643 {
1644 if (op == null) {
1645 op = new OperatorExpr();
1646 op.addOperand(operand);
1647 op.setCurrentop(true);
1648 }
1649 ((OperatorExpr)op).addOperator(token.image);
1650 }
vinayakb38b7ca42012-03-05 05:44:15 +00001651
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001652 operand = MultExpr()
1653 {
1654 op.addOperand(operand);
1655 }
1656 )*
1657
1658 {
1659 return op==null? operand: op;
1660 }
vinayakb38b7ca42012-03-05 05:44:15 +00001661}
1662
1663Expression MultExpr()throws ParseException:
1664{
1665 OperatorExpr op = null;
1666 Expression operand = null;
1667}
1668{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001669 operand = UnionExpr()
vinayakb38b7ca42012-03-05 05:44:15 +00001670
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001671 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
1672 {
1673 if (op == null) {
1674 op = new OperatorExpr();
vinayakb38b7ca42012-03-05 05:44:15 +00001675 op.addOperand(operand);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001676 op.setCurrentop(true);
1677 }
1678 op.addOperator(token.image);
1679 }
1680 operand = UnionExpr()
1681 {
1682 op.addOperand(operand);
1683 }
1684 )*
1685
1686 {
1687 return op==null?operand:op;
1688 }
vinayakb38b7ca42012-03-05 05:44:15 +00001689}
1690
1691Expression UnionExpr() throws ParseException:
1692{
1693 UnionExpr union = null;
1694 Expression operand1 = null;
1695 Expression operand2 = null;
1696}
1697{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001698 operand1 = UnaryExpr()
1699 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001700 (operand2 = UnaryExpr()) {
1701 if (union == null) {
1702 union = new UnionExpr();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001703 union.addExpr(operand1);
vinayakb38b7ca42012-03-05 05:44:15 +00001704 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001705 union.addExpr(operand2);
vinayakb38b7ca42012-03-05 05:44:15 +00001706 } )*
1707 {
1708 return (union == null)? operand1: union;
1709 }
1710}
1711
1712Expression UnaryExpr() throws ParseException:
1713{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001714 Expression uexpr = null;
1715 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001716}
1717{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001718 ( (<PLUS> | <MINUS>)
1719 {
1720 uexpr = new UnaryExpr();
1721 if("+".equals(token.image))
1722 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
1723 else if("-".equals(token.image))
1724 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1725 else
1726 throw new ParseException();
1727 }
1728 )?
1729
1730 expr = ValueExpr()
1731 {
1732 if(uexpr!=null){
1733 ((UnaryExpr)uexpr).setExpr(expr);
1734 return uexpr;
1735 }
1736 else{
1737 return expr;
1738 }
1739 }
vinayakb38b7ca42012-03-05 05:44:15 +00001740}
1741
Till Westmann04478e72013-05-13 23:01:34 -07001742Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001743{
1744 Expression expr = null;
1745 Identifier ident = null;
1746 AbstractAccessor fa = null;
icetindila611ac72014-05-16 10:10:11 -07001747 Expression indexExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001748}
1749{
Till Westmann04478e72013-05-13 23:01:34 -07001750 expr = PrimaryExpr() ( ident = Field()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001751 {
1752 fa = (fa == null ? new FieldAccessor(expr, ident)
Till Westmann04478e72013-05-13 23:01:34 -07001753 : new FieldAccessor(fa, ident));
1754 }
icetindila611ac72014-05-16 10:10:11 -07001755 | indexExpr = Index()
Till Westmann04478e72013-05-13 23:01:34 -07001756 {
icetindila611ac72014-05-16 10:10:11 -07001757 fa = (fa == null ? new IndexAccessor(expr, indexExpr)
1758 : new IndexAccessor(fa, indexExpr));
Till Westmann04478e72013-05-13 23:01:34 -07001759 }
1760 )*
1761 {
1762 return fa == null ? expr : fa;
1763 }
vinayakb38b7ca42012-03-05 05:44:15 +00001764}
1765
1766Identifier Field() throws ParseException:
1767{
Till Westmann14a20a72013-05-09 00:06:24 -07001768 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001769}
1770{
Till Westmann96c1f172013-08-01 02:05:48 -07001771 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001772 {
Till Westmann14a20a72013-05-09 00:06:24 -07001773 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001774 }
vinayakb38b7ca42012-03-05 05:44:15 +00001775}
1776
icetindila611ac72014-05-16 10:10:11 -07001777Expression Index() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001778{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001779 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001780}
1781{
Till Westmann96c1f172013-08-01 02:05:48 -07001782 <LEFTBRACKET> ( expr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001783 {
1784 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1785 {
1786 Literal lit = ((LiteralExpr)expr).getValue();
1787 if(lit.getLiteralType() != Literal.Type.INTEGER &&
1788 lit.getLiteralType() != Literal.Type.LONG) {
1789 throw new ParseException("Index should be an INTEGER");
vinayakb38b7ca42012-03-05 05:44:15 +00001790 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001791 }
1792 }
vinayakb38b7ca42012-03-05 05:44:15 +00001793
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001794 | <QUES> // ANY
1795
1796 )
vinayakb38b7ca42012-03-05 05:44:15 +00001797
Till Westmann96c1f172013-08-01 02:05:48 -07001798 <RIGHTBRACKET>
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001799 {
1800 return expr;
1801 }
vinayakb38b7ca42012-03-05 05:44:15 +00001802}
1803
1804
1805Expression PrimaryExpr()throws ParseException:
1806{
1807 Expression expr = null;
1808}
1809{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001810 ( LOOKAHEAD(2)
Till Westmann68d99652013-05-09 11:15:21 -07001811 expr = FunctionCallExpr()
1812 | expr = Literal()
1813 | expr = DatasetAccessExpression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001814 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001815 {
1816 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001817 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001818 }
Till Westmann68d99652013-05-09 11:15:21 -07001819 | expr = ListConstructor()
1820 | expr = RecordConstructor()
1821 | expr = ParenthesizedExpression()
1822 )
1823 {
1824 return expr;
1825 }
vinayakb38b7ca42012-03-05 05:44:15 +00001826}
1827
1828Expression Literal() throws ParseException:
1829{
vinayakb38b7ca42012-03-05 05:44:15 +00001830 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001831 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001832}
1833{
Till Westmann7d535322013-05-09 00:40:02 -07001834 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001835 {
Till Westmann7d535322013-05-09 00:40:02 -07001836 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001837 }
1838 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001839 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001840 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
Till Westmanna4242bc2013-05-08 17:49:55 -07001841 }
1842 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001843 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001844 lit.setValue(new FloatLiteral(new Float(token.image)));
1845 }
1846 | <DOUBLE_LITERAL>
1847 {
1848 lit.setValue(new DoubleLiteral(new Double(token.image)));
1849 }
1850 | <NULL>
1851 {
1852 lit.setValue(NullLiteral.INSTANCE);
1853 }
1854 | <TRUE>
1855 {
1856 lit.setValue(TrueLiteral.INSTANCE);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001857 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001858 | <FALSE>
1859 {
1860 lit.setValue(FalseLiteral.INSTANCE);
1861 }
1862 )
vinayakb38b7ca42012-03-05 05:44:15 +00001863 {
1864 return lit;
1865 }
1866}
1867
1868
1869VariableExpr VariableRef() throws ParseException:
1870{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001871 VariableExpr varExp = new VariableExpr();
1872 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001873}
1874{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001875 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001876 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001877 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001878 Identifier ident = lookupSymbol(varName);
1879 if (isInForbiddenScopes(varName)) {
1880 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.");
1881 }
1882 if(ident != null) { // exist such ident
1883 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001884 varExp.setVar((VarIdentifier)ident);
vinayakb38b7ca42012-03-05 05:44:15 +00001885 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001886 varExp.setVar(var);
vinayakb38b7ca42012-03-05 05:44:15 +00001887 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001888 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001889 return varExp;
1890 }
1891}
1892
1893
1894VariableExpr Variable() throws ParseException:
1895{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001896 VariableExpr varExp = new VariableExpr();
1897 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001898}
1899{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001900 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001901 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001902 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001903 if(ident != null) { // exist such ident
1904 varExp.setIsNewVar(false);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001905 }
1906 varExp.setVar(var);
1907 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001908 return varExp;
1909 }
1910}
1911
1912Expression ListConstructor() throws ParseException:
1913{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001914 Expression expr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001915}
1916{
1917 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001918 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
vinayakb38b7ca42012-03-05 05:44:15 +00001919 )
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001920
vinayakb38b7ca42012-03-05 05:44:15 +00001921 {
1922 return expr;
1923 }
1924}
1925
1926
1927ListConstructor OrderedListConstructor() throws ParseException:
1928{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001929 ListConstructor expr = new ListConstructor();
1930 Expression tmp = null;
1931 List<Expression> exprList = new ArrayList<Expression>();
1932 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001933}
1934{
1935
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001936 <LEFTBRACKET>
1937 ( tmp = Expression()
1938 {
1939 exprList.add(tmp);
1940 }
1941
1942 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
1943 )?
1944
Till Westmann96c1f172013-08-01 02:05:48 -07001945 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001946
1947 {
1948 expr.setExprList(exprList);
1949 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001950 }
vinayakb38b7ca42012-03-05 05:44:15 +00001951}
1952
1953ListConstructor UnorderedListConstructor() throws ParseException:
1954{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001955 ListConstructor expr = new ListConstructor();
1956 Expression tmp = null;
1957 List<Expression> exprList = new ArrayList<Expression>();
1958 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
vinayakb38b7ca42012-03-05 05:44:15 +00001959}
1960{
1961
Till Westmann96c1f172013-08-01 02:05:48 -07001962 <LEFTDBLBRACE> ( tmp = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001963 {
1964 exprList.add(tmp);
1965 }
Till Westmann96c1f172013-08-01 02:05:48 -07001966 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001967 {
1968 expr.setExprList(exprList);
1969 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001970 }
vinayakb38b7ca42012-03-05 05:44:15 +00001971}
1972
1973RecordConstructor RecordConstructor() throws ParseException:
1974{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001975 RecordConstructor expr = new RecordConstructor();
1976 FieldBinding tmp = null;
1977 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
vinayakb38b7ca42012-03-05 05:44:15 +00001978}
1979{
Till Westmann96c1f172013-08-01 02:05:48 -07001980 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001981 {
1982 fbList.add(tmp);
1983 }
Till Westmann96c1f172013-08-01 02:05:48 -07001984 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001985 {
1986 expr.setFbList(fbList);
1987 return expr;
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001988 }
vinayakb38b7ca42012-03-05 05:44:15 +00001989}
1990
1991FieldBinding FieldBinding() throws ParseException:
1992{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08001993 FieldBinding fb = new FieldBinding();
1994 Expression left, right;
vinayakb38b7ca42012-03-05 05:44:15 +00001995}
1996{
Till Westmann96c1f172013-08-01 02:05:48 -07001997 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001998 {
1999 fb.setLeftExpr(left);
2000 fb.setRightExpr(right);
2001 return fb;
2002 }
2003}
2004
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002005
vinayakb38b7ca42012-03-05 05:44:15 +00002006Expression FunctionCallExpr() throws ParseException:
2007{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002008 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00002009 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00002010 Expression tmp;
2011 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07002012 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07002013 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002014}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002015{
ramangrover299f76a5e2013-06-18 10:25:17 -07002016 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00002017 {
Till Westmann31c21f92013-05-08 09:21:53 -07002018 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00002019 }
Till Westmann31c21f92013-05-08 09:21:53 -07002020 <LEFTPAREN> (tmp = Expression()
2021 {
2022 argList.add(tmp);
2023 arity ++;
2024 }
Till Westmann96c1f172013-08-01 02:05:48 -07002025 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07002026 {
2027 argList.add(tmp);
2028 arity++;
2029 }
2030 )*)? <RIGHTPAREN>
2031 {
ramangrover299f76a5e2013-06-18 10:25:17 -07002032 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07002033 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07002034 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07002035 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002036 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07002037 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07002038 }
2039 callExpr = new CallExpr(signature,argList);
salsubaieedf89fbc2013-12-21 19:51:42 -08002040 if (hint != null) {
2041 if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
2042 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
2043 } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
2044 callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
2045 }
Till Westmann31c21f92013-05-08 09:21:53 -07002046 }
2047 return callExpr;
2048 }
vinayakb38b7ca42012-03-05 05:44:15 +00002049}
2050
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00002051
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002052Expression DatasetAccessExpression() throws ParseException:
2053{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002054 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07002055 String arg1 = null;
2056 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002057 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002058}
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002059{
Till Westmann14a20a72013-05-09 00:06:24 -07002060 <DATASET>
2061 {
Till Westmann14a20a72013-05-09 00:06:24 -07002062 funcName = token.image;
2063 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002064 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07002065 {
2066 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07002067 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07002068 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07002069 nameArg = ds;
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002070 if(arg2 != null){
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002071 addDataverse(arg1.toString());
2072 addDataset(name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002073 } else {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002074 addDataset(defaultDataverse + "." + name);
Abdullah Alamoudidb37f662014-07-14 21:51:37 +03002075 }
Till Westmann14a20a72013-05-09 00:06:24 -07002076 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002077 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07002078 {
Till Westmann1f7a2362013-05-24 08:43:40 -07002079 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
2080 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
2081 if (signature == null) {
2082 signature = new FunctionSignature(dataverse, funcName, 1);
2083 }
2084 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07002085 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07002086 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07002087 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00002088}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00002089
vinayakb38b7ca42012-03-05 05:44:15 +00002090Expression ParenthesizedExpression() throws ParseException:
2091{
2092 Expression expr;
2093}
2094{
2095 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
2096 {
2097 return expr;
2098 }
2099}
2100
2101Expression IfThenElse() throws ParseException:
2102{
2103 Expression condExpr;
2104 Expression thenExpr;
2105 Expression elseExpr;
2106 IfExpr ifExpr = new IfExpr();
2107}
2108{
Till Westmann96c1f172013-08-01 02:05:48 -07002109 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002110
2111 {
2112 ifExpr.setCondExpr(condExpr);
2113 ifExpr.setThenExpr(thenExpr);
2114 ifExpr.setElseExpr(elseExpr);
2115 return ifExpr;
2116 }
2117}
2118
2119Expression FLWOGR() throws ParseException:
2120{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002121 FLWOGRExpression flworg = new FLWOGRExpression();
2122 List<Clause> clauseList = new ArrayList<Clause>();
2123 Expression returnExpr;
2124 Clause tmp;
2125 createNewScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002126}
2127{
2128 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
buyingyi2fd7fa62014-11-24 19:31:55 -08002129 (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002130
2131 {
2132 flworg.setClauseList(clauseList);
2133 flworg.setReturnExpr(returnExpr);
2134 removeCurrentScope();
2135 return flworg;
2136 }
2137}
2138
2139Clause Clause()throws ParseException :
2140{
2141 Clause clause;
2142}
2143{
2144 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002145 clause = ForClause()
2146 | clause = LetClause()
2147 | clause = WhereClause()
2148 | clause = OrderbyClause()
2149 | clause = GroupClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002150 | clause = LimitClause()
2151 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00002152 )
2153 {
2154 return clause;
2155 }
2156}
2157
2158Clause ForClause()throws ParseException :
2159{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002160 ForClause fc = new ForClause();
2161 VariableExpr varExp;
2162 VariableExpr varPos = null;
2163 Expression inExp;
2164 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002165}
2166{
buyingyi2fd7fa62014-11-24 19:31:55 -08002167 (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00002168 {
2169 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07002170 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002171 fc.setInExpr(inExp);
2172 if (varPos != null) {
2173 fc.setPosExpr(varPos);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002174 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002175 }
2176 return fc;
2177 }
2178}
2179
2180Clause LetClause() throws ParseException:
2181{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002182 LetClause lc = new LetClause();
2183 VariableExpr varExp;
2184 Expression beExp;
2185 extendCurrentScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002186}
2187{
buyingyi2fd7fa62014-11-24 19:31:55 -08002188 (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002189 {
2190 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002191 lc.setVarExpr(varExp);
2192 lc.setBeExpr(beExp);
2193 return lc;
2194 }
2195}
2196
2197Clause WhereClause()throws ParseException :
2198{
2199 WhereClause wc = new WhereClause();
2200 Expression whereExpr;
2201}
2202{
salsubaieedf89fbc2013-12-21 19:51:42 -08002203 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002204 {
2205 wc.setWhereExpr(whereExpr);
2206 return wc;
2207 }
2208}
2209
2210Clause OrderbyClause()throws ParseException :
2211{
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002212 OrderbyClause oc = new OrderbyClause();
2213 Expression orderbyExpr;
2214 List<Expression> orderbyList = new ArrayList<Expression>();
2215 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
2216 int numOfOrderby = 0;
vinayakb38b7ca42012-03-05 05:44:15 +00002217}
2218{
2219 (
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002220 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00002221 {
Eldon Carmand2d78ad2015-05-07 16:23:41 -07002222 String hint = getHint(token);
2223 if (hint != null) {
2224 if (hint.startsWith(INMEMORY_HINT)) {
2225 String splits[] = hint.split(" +");
2226 int numFrames = Integer.parseInt(splits[1]);
2227 int numTuples = Integer.parseInt(splits[2]);
2228 oc.setNumFrames(numFrames);
2229 oc.setNumTuples(numTuples);
2230 }
2231 if (hint.startsWith(RANGE_HINT)) {
2232 oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
2233 }
2234 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002235 }
Till Westmann96c1f172013-08-01 02:05:48 -07002236 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002237 {
2238 orderbyList.add(orderbyExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002239 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
vinayakb38b7ca42012-03-05 05:44:15 +00002240 }
Till Westmann96c1f172013-08-01 02:05:48 -07002241 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2242 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002243 {
2244 modifierList.add(modif);
2245 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002246
Till Westmann96c1f172013-08-01 02:05:48 -07002247 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002248 {
2249 orderbyList.add(orderbyExpr);
2250 modif = OrderbyClause.OrderModifier.ASC;
2251 }
Till Westmann96c1f172013-08-01 02:05:48 -07002252 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
2253 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00002254 {
2255 modifierList.add(modif);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002256 }
vinayakb38b7ca42012-03-05 05:44:15 +00002257 )*
2258)
2259 {
2260 oc.setModifierList(modifierList);
2261 oc.setOrderbyList(orderbyList);
2262 return oc;
2263 }
2264}
2265Clause GroupClause()throws ParseException :
2266{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002267 GroupbyClause gbc = new GroupbyClause();
2268 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
2269 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
vinayakb38b7ca42012-03-05 05:44:15 +00002270 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002271 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
2272 VariableExpr var = null;
2273 VariableExpr withVar = null;
2274 Expression expr = null;
2275 VariableExpr decorVar = null;
2276 Expression decorExpr = null;
vinayakb38b7ca42012-03-05 05:44:15 +00002277}
2278{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002279 {
2280 Scope newScope = extendCurrentScopeNoPush(true);
2281 // extendCurrentScope(true);
2282 }
Till Westmann96c1f172013-08-01 02:05:48 -07002283 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00002284 {
2285 String hint = getHint(token);
2286 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002287 gbc.setHashGroupByHint(true);
2288 }
2289 }
Till Westmann96c1f172013-08-01 02:05:48 -07002290 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002291 {
2292 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002293 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002294 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002295 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002296 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002297 vePairList.add(pair1);
2298 }
Till Westmann96c1f172013-08-01 02:05:48 -07002299 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00002300 {
2301 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07002302 } <ASSIGN>)?
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002303 expr = Expression()
2304 {
2305 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vinayakb38b7ca42012-03-05 05:44:15 +00002306 vePairList.add(pair2);
2307 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002308 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002309 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002310 {
2311 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002312 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
2313 decorPairList.add(pair3);
2314 }
Till Westmann96c1f172013-08-01 02:05:48 -07002315 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002316 {
2317 newScope.addNewVarSymbolToScope(decorVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002318 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002319 decorPairList.add(pair4);
vinayakb38b7ca42012-03-05 05:44:15 +00002320 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002321 )*
2322 )?
buyingyi3ca46d02015-01-27 23:22:09 -08002323 (<WITH>|<KEEPING>) withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002324 {
2325 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002326 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002327 withVarList.add(withVar);
2328 newScope.addNewVarSymbolToScope(withVar.getVar());
2329 }
Till Westmann96c1f172013-08-01 02:05:48 -07002330 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002331 {
2332 if(withVar.getIsNewVar()==true)
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002333 throw new ParseException("can't find variable " + withVar.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00002334 withVarList.add(withVar);
2335 newScope.addNewVarSymbolToScope(withVar.getVar());
2336 })*
2337 {
2338 gbc.setGbyPairList(vePairList);
2339 gbc.setDecorPairList(decorPairList);
2340 gbc.setWithVarList(withVarList);
2341 replaceCurrentScope(newScope);
2342 return gbc;
2343 }
2344}
2345
2346
2347LimitClause LimitClause() throws ParseException:
2348{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002349 LimitClause lc = new LimitClause();
2350 Expression expr;
2351 pushForbiddenScope(getCurrentScope());
vinayakb38b7ca42012-03-05 05:44:15 +00002352}
2353{
Till Westmann96c1f172013-08-01 02:05:48 -07002354 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2355 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002356
2357 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002358 popForbiddenScope();
vinayakb38b7ca42012-03-05 05:44:15 +00002359 return lc;
2360 }
2361}
2362
2363DistinctClause DistinctClause() throws ParseException:
2364{
2365 List<Expression> exprs = new ArrayList<Expression>();
2366 Expression expr;
2367}
2368{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002369 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002370 {
2371 exprs.add(expr);
2372 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002373 (<COMMA> expr = Expression()
2374 {
2375 exprs.add(expr);
2376 }
vinayakb38b7ca42012-03-05 05:44:15 +00002377 )*
2378 {
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002379 return new DistinctClause(exprs);
vinayakb38b7ca42012-03-05 05:44:15 +00002380 }
2381}
2382
vinayakb38b7ca42012-03-05 05:44:15 +00002383QuantifiedExpression QuantifiedExpression()throws ParseException:
2384{
2385 QuantifiedExpression qc = new QuantifiedExpression();
2386 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2387 Expression satisfiesExpr;
2388 VariableExpr var;
2389 Expression inExpr;
2390 QuantifiedPair pair;
2391}
2392{
2393 {
2394 createNewScope();
2395 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002396
Till Westmann96c1f172013-08-01 02:05:48 -07002397 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002398 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2399 var = Variable() <IN> inExpr = Expression()
2400 {
vinayakb38b7ca42012-03-05 05:44:15 +00002401 pair = new QuantifiedPair(var, inExpr);
2402 getCurrentScope().addNewVarSymbolToScope(var.getVar());
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002403 quantifiedList.add(pair);
2404 }
2405 (
2406 <COMMA> var = Variable() <IN> inExpr = Expression()
2407 {
2408 pair = new QuantifiedPair(var, inExpr);
2409 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2410 quantifiedList.add(pair);
2411 }
2412 )*
2413 <SATISFIES> satisfiesExpr = Expression()
2414 {
2415 qc.setSatisfiesExpr(satisfiesExpr);
2416 qc.setQuantifiedList(quantifiedList);
2417 removeCurrentScope();
2418 return qc;
2419 }
vinayakb38b7ca42012-03-05 05:44:15 +00002420}
2421
2422TOKEN_MGR_DECLS:
2423{
Till Westmann96c1f172013-08-01 02:05:48 -07002424 public int commentDepth = 0;
2425 public IntStack lexerStateStack = new IntStack();
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002426
Till Westmann96c1f172013-08-01 02:05:48 -07002427 public void pushState() {
2428 lexerStateStack.push( curLexState );
2429 }
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002430
Till Westmannfd733ee2014-07-10 00:57:37 -07002431 public void popState(String token) {
Till Westmann96c1f172013-08-01 02:05:48 -07002432 if (lexerStateStack.size() > 0) {
2433 SwitchTo( lexerStateStack.pop() );
2434 } else {
Till Westmannfd733ee2014-07-10 00:57:37 -07002435 int errorLine = input_stream.getEndLine();
2436 int errorColumn = input_stream.getEndColumn();
2437 String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
2438 + "\" but state stack is empty.";
2439 throw new TokenMgrError(msg, -1);
Till Westmann96c1f172013-08-01 02:05:48 -07002440 }
2441 }
vinayakb38b7ca42012-03-05 05:44:15 +00002442}
2443
Till Westmann96c1f172013-08-01 02:05:48 -07002444<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002445TOKEN :
2446{
Till Westmann5df7b452013-08-02 13:07:16 -07002447 <ASC : "asc">
2448 | <AT : "at">
2449 | <BY : "by">
2450 | <DATASET : "dataset">
2451 | <DECOR : "decor">
2452 | <DESC : "desc">
2453 | <DISTINCT : "distinct">
2454 | <ELSE : "else">
2455 | <EVERY : "every">
2456 | <FOR : "for">
buyingyi2fd7fa62014-11-24 19:31:55 -08002457 | <FROM : "from">
Till Westmann5df7b452013-08-02 13:07:16 -07002458 | <GROUP : "group">
2459 | <IF : "if">
2460 | <IN : "in">
2461 | <LET : "let">
2462 | <LIMIT : "limit">
2463 | <OFFSET : "offset">
2464 | <ORDER : "order">
2465 | <RETURN : "return">
2466 | <SATISFIES : "satisfies">
buyingyi2fd7fa62014-11-24 19:31:55 -08002467 | <SELECT : "select">
Till Westmann5df7b452013-08-02 13:07:16 -07002468 | <SOME : "some">
2469 | <THEN : "then">
2470 | <UNION : "union">
2471 | <WHERE : "where">
2472 | <WITH : "with">
buyingyi3ca46d02015-01-27 23:22:09 -08002473 | <KEEPING : "keeping">
vinayakb38b7ca42012-03-05 05:44:15 +00002474}
2475
Till Westmann96c1f172013-08-01 02:05:48 -07002476<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002477TOKEN :
2478{
Till Westmann5df7b452013-08-02 13:07:16 -07002479 <CARET : "^">
2480 | <DIV : "/">
2481 | <IDIV : "idiv">
2482 | <MINUS : "-">
2483 | <MOD : "%">
2484 | <MUL : "*">
2485 | <PLUS : "+">
2486
2487 | <LEFTPAREN : "(">
2488 | <RIGHTPAREN : ")">
2489 | <LEFTBRACKET : "[">
2490 | <RIGHTBRACKET : "]">
2491
2492 | <COLON : ":">
2493 | <COMMA : ",">
2494 | <DOT : ".">
2495 | <QUES : "?">
2496
2497 | <LT : "<">
2498 | <GT : ">">
2499 | <LE : "<=">
2500 | <GE : ">=">
2501 | <EQ : "=">
2502 | <NE : "!=">
2503 | <SIMILAR : "~=">
2504 | <ASSIGN : ":=">
2505
2506 | <AND : "and">
2507 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002508}
2509
Till Westmann96c1f172013-08-01 02:05:48 -07002510<DEFAULT,IN_DBL_BRACE>
2511TOKEN :
2512{
Till Westmann5df7b452013-08-02 13:07:16 -07002513 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002514}
2515
2516<DEFAULT>
2517TOKEN :
2518{
Till Westmannfd733ee2014-07-10 00:57:37 -07002519 <RIGHTBRACE : "}"> { popState("}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002520}
2521
Till Westmann96c1f172013-08-01 02:05:48 -07002522<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002523TOKEN :
2524{
Till Westmann5df7b452013-08-02 13:07:16 -07002525 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002526}
2527
Till Westmann96c1f172013-08-01 02:05:48 -07002528<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002529TOKEN :
2530{
Till Westmannfd733ee2014-07-10 00:57:37 -07002531 <RIGHTDBLBRACE : "}}"> { popState("}}"); }
vinayakb38b7ca42012-03-05 05:44:15 +00002532}
2533
Till Westmann96c1f172013-08-01 02:05:48 -07002534<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002535TOKEN :
2536{
Till Westmann5df7b452013-08-02 13:07:16 -07002537 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002538}
2539
Till Westmann96c1f172013-08-01 02:05:48 -07002540<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002541TOKEN :
2542{
Till Westmann5df7b452013-08-02 13:07:16 -07002543 <NULL : "null">
2544 | <TRUE : "true">
2545 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002546}
2547
Till Westmann96c1f172013-08-01 02:05:48 -07002548<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002549TOKEN :
2550{
Till Westmann5df7b452013-08-02 13:07:16 -07002551 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002552}
2553
Till Westmann96c1f172013-08-01 02:05:48 -07002554<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002555TOKEN:
2556{
Till Westmann5df7b452013-08-02 13:07:16 -07002557 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002558 | <DIGITS> ( "." <DIGITS> )?
2559 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002560 >
2561 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002562 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2563 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002564 >
2565 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002566}
2567
Till Westmann96c1f172013-08-01 02:05:48 -07002568<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002569TOKEN :
2570{
Till Westmann5df7b452013-08-02 13:07:16 -07002571 <#LETTER : ["A" - "Z", "a" - "z"]>
2572 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002573}
2574
Till Westmann96c1f172013-08-01 02:05:48 -07002575<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002576TOKEN :
2577{
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002578 // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
2579 <STRING_LITERAL : ("\"" (
2580 <EscapeQuot>
2581 | <EscapeBslash>
2582 | <EscapeSlash>
2583 | <EscapeBspace>
2584 | <EscapeFormf>
2585 | <EscapeNl>
2586 | <EscapeCr>
2587 | <EscapeTab>
2588 | ~["\"","\\"])* "\"")
2589 | ("\'"(
2590 <EscapeApos>
2591 | <EscapeBslash>
2592 | <EscapeSlash>
2593 | <EscapeBspace>
2594 | <EscapeFormf>
2595 | <EscapeNl>
2596 | <EscapeCr>
2597 | <EscapeTab>
2598 | ~["\'","\\"])* "\'")>
Till Westmann5df7b452013-08-02 13:07:16 -07002599 | < #EscapeQuot: "\\\"" >
2600 | < #EscapeApos: "\\\'" >
Till Westmanne0cc01c2014-03-31 10:26:10 -07002601 | < #EscapeBslash: "\\\\" >
Till Westmanne3e8ffa2014-08-02 17:51:23 -07002602 | < #EscapeSlash: "\\/" >
2603 | < #EscapeBspace: "\\b" >
2604 | < #EscapeFormf: "\\f" >
2605 | < #EscapeNl: "\\n" >
2606 | < #EscapeCr: "\\r" >
2607 | < #EscapeTab: "\\t" >
vinayakb38b7ca42012-03-05 05:44:15 +00002608}
2609
Till Westmann96c1f172013-08-01 02:05:48 -07002610<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002611TOKEN :
2612{
Till Westmann5df7b452013-08-02 13:07:16 -07002613 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002614}
2615
Till Westmann96c1f172013-08-01 02:05:48 -07002616<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002617TOKEN :
2618{
Till Westmann5df7b452013-08-02 13:07:16 -07002619 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002620}
2621
Till Westmann96c1f172013-08-01 02:05:48 -07002622<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002623SKIP:
2624{
2625 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002626 | "\t"
2627 | "\r"
2628 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002629}
2630
Till Westmann96c1f172013-08-01 02:05:48 -07002631<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002632SKIP:
2633{
Till Westmann5df7b452013-08-02 13:07:16 -07002634 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002635}
2636
Till Westmann96c1f172013-08-01 02:05:48 -07002637<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002638SKIP:
2639{
Taewoo Kima12d8cd2015-03-04 13:47:08 -08002640 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002641}
2642
Till Westmann96c1f172013-08-01 02:05:48 -07002643<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002644SKIP:
2645{
Till Westmann96c1f172013-08-01 02:05:48 -07002646 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002647}
2648
2649<INSIDE_COMMENT>
2650SPECIAL_TOKEN:
2651{
Till Westmann5df7b452013-08-02 13:07:16 -07002652 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002653}
2654
2655<INSIDE_COMMENT>
2656SKIP:
2657{
Till Westmann96c1f172013-08-01 02:05:48 -07002658 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002659}
2660
2661<INSIDE_COMMENT>
2662SKIP:
2663{
Till Westmannfd733ee2014-07-10 00:57:37 -07002664 <"*/"> { popState("*/"); }
Till Westmann5df7b452013-08-02 13:07:16 -07002665 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002666}