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