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