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