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