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