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 | { |
Raman Grover | 25a2b2e | 2013-09-27 18:22:23 +0530 | [diff] [blame] | 555 | FunctionName functioName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 556 | FunctionSignature funcSig = null; |
| 557 | } |
| 558 | { |
Raman Grover | 25a2b2e | 2013-09-27 18:22:23 +0530 | [diff] [blame] | 559 | "apply" "function" functioName = FunctionName() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 560 | { |
Raman Grover | 25a2b2e | 2013-09-27 18:22:23 +0530 | [diff] [blame] | 561 | String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function; |
| 562 | return new FunctionSignature(functioName.dataverse, fqFunctionName, 1); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
ramangrover29 | 566b3a9 | 2013-05-28 09:07:10 -0700 | [diff] [blame] | 566 | String GetPolicy() throws ParseException: |
| 567 | { |
| 568 | String policy = null; |
| 569 | } |
| 570 | { |
| 571 | "using" "policy" policy = Identifier() |
| 572 | { |
| 573 | return policy; |
| 574 | } |
| 575 | |
| 576 | } |
| 577 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 578 | FunctionSignature FunctionSignature() throws ParseException: |
| 579 | { |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 580 | FunctionName fctName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 581 | int arity = 0; |
| 582 | } |
| 583 | { |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 584 | fctName = FunctionName() "@" <INTEGER_LITERAL> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 585 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 586 | arity = new Integer(token.image); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 587 | if (arity < 0 && arity != FunctionIdentifier.VARARGS) { |
| 588 | throw new ParseException(" invalid arity:" + arity); |
| 589 | } |
| 590 | |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 591 | // TODO use fctName.library |
ramangrover29 | 93dd823 | 2013-07-03 22:51:25 -0700 | [diff] [blame] | 592 | String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function; |
| 593 | return new FunctionSignature(fctName.dataverse, fqFunctionName, arity); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | List<String> PrimaryKey() throws ParseException: |
| 598 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 599 | String tmp = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 600 | List<String> primaryKeyFields = new ArrayList<String>(); |
| 601 | } |
| 602 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 603 | "primary" "key" tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 604 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 605 | primaryKeyFields.add(tmp); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 606 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 607 | ( <COMMA> tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 608 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 609 | primaryKeyFields.add(tmp); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 610 | } |
| 611 | )* |
| 612 | { |
| 613 | return primaryKeyFields; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | Statement DropStatement() throws ParseException: |
| 618 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 619 | String id = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 620 | Pair<Identifier,Identifier> pairId = null; |
| 621 | Triple<Identifier,Identifier,Identifier> tripleId = null; |
| 622 | FunctionSignature funcSig = null; |
| 623 | boolean ifExists = false; |
| 624 | Statement stmt = null; |
| 625 | } |
| 626 | { |
| 627 | "drop" |
| 628 | ( |
| 629 | <DATASET> pairId = QualifiedName() ifExists = IfExists() |
| 630 | { |
| 631 | stmt = new DropStatement(pairId.first, pairId.second, ifExists); |
| 632 | } |
| 633 | | "index" tripleId = DoubleQualifiedName() ifExists = IfExists() |
| 634 | { |
| 635 | stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); |
| 636 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 637 | | "nodegroup" id = Identifier() ifExists = IfExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 638 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 639 | stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 640 | } |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 641 | | "type" pairId = TypeName() ifExists = IfExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 642 | { |
| 643 | stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); |
| 644 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 645 | | "dataverse" id = Identifier() ifExists = IfExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 646 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 647 | stmt = new DataverseDropStatement(new Identifier(id), ifExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 648 | } |
| 649 | | "function" funcSig = FunctionSignature() ifExists = IfExists() |
| 650 | { |
| 651 | stmt = new FunctionDropStatement(funcSig, ifExists); |
| 652 | } |
ramangrover29 | a774ef2 | 2013-07-17 09:29:18 -0700 | [diff] [blame] | 653 | | "feed" pairId = QualifiedName() ifExists = IfExists() |
| 654 | { |
| 655 | stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists); |
| 656 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 657 | ) |
| 658 | { |
| 659 | return stmt; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | boolean IfExists() throws ParseException : |
| 664 | { |
| 665 | } |
| 666 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 667 | ( <IF> "exists" |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 668 | { |
| 669 | return true; |
| 670 | } |
| 671 | )? |
| 672 | { |
| 673 | return false; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
| 677 | InsertStatement InsertStatement() throws ParseException: |
| 678 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 679 | Pair<Identifier,Identifier> nameComponents = null; |
| 680 | Query query; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 681 | } |
| 682 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 683 | "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query() |
| 684 | { |
| 685 | return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter()); |
| 686 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | DeleteStatement DeleteStatement() throws ParseException: |
| 690 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 691 | VariableExpr var = null; |
| 692 | Expression condition = null; |
| 693 | Pair<Identifier, Identifier> nameComponents; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 694 | } |
| 695 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 696 | "delete" var = Variable() |
| 697 | { |
| 698 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 699 | } |
| 700 | "from" <DATASET> nameComponents = QualifiedName() |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 701 | (<WHERE> condition = Expression())? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 702 | { |
| 703 | return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter()); |
| 704 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | UpdateStatement UpdateStatement() throws ParseException: |
| 708 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 709 | VariableExpr vars; |
| 710 | Expression target; |
| 711 | Expression condition; |
| 712 | UpdateClause uc; |
| 713 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 714 | } |
| 715 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 716 | "update" vars = Variable() <IN> target = Expression() |
| 717 | <WHERE> condition = Expression() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 718 | <LEFTPAREN> (uc = UpdateClause() |
| 719 | { |
| 720 | ucs.add(uc); |
| 721 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 722 | (<COMMA> uc = UpdateClause() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 723 | { |
| 724 | ucs.add(uc); |
| 725 | } |
| 726 | )*) <RIGHTPAREN> |
| 727 | { |
| 728 | return new UpdateStatement(vars, target, condition, ucs); |
| 729 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 730 | } |
| 731 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 732 | UpdateClause UpdateClause() throws ParseException: |
| 733 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 734 | Expression target = null; |
| 735 | Expression value = null ; |
| 736 | InsertStatement is = null; |
| 737 | DeleteStatement ds = null; |
| 738 | UpdateStatement us = null; |
| 739 | Expression condition = null; |
| 740 | UpdateClause ifbranch = null; |
| 741 | UpdateClause elsebranch = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 742 | } |
| 743 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 744 | "set" target = Expression() <ASSIGN> value = Expression() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 745 | | is = InsertStatement() |
| 746 | | ds = DeleteStatement() |
| 747 | | us = UpdateStatement() |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 748 | | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN> |
| 749 | <THEN> ifbranch = UpdateClause() |
| 750 | [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()] |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 751 | { |
| 752 | return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch); |
| 753 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 754 | } |
| 755 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 756 | Statement SetStatement() throws ParseException: |
| 757 | { |
| 758 | String pn = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 759 | String pv = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 760 | } |
| 761 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 762 | "set" pn = Identifier() pv = StringLiteral() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 763 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 764 | return new SetStatement(pn, pv); |
| 765 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | Statement WriteStatement() throws ParseException: |
| 769 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 770 | String nodeName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 771 | String fileName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 772 | Query query; |
| 773 | String writerClass = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 774 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 775 | } |
| 776 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 777 | "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral() |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 778 | ( "using" writerClass = StringLiteral() )? |
Till Westmann | 35a0f70 | 2013-07-01 14:06:34 -0700 | [diff] [blame] | 779 | { |
| 780 | return new WriteStatement(new Identifier(nodeName), fileName, writerClass); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 784 | LoadFromFileStatement LoadStatement() throws ParseException: |
| 785 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 786 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 787 | Identifier datasetName = null; |
| 788 | boolean alreadySorted = false; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 789 | String adapterName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 790 | Map<String,String> properties; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 791 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 792 | } |
| 793 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 794 | "load" <DATASET> nameComponents = QualifiedName() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 795 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 796 | dataverseName = nameComponents.first; |
| 797 | datasetName = nameComponents.second; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 798 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 799 | "using" adapterName = AdapterName() properties = Configuration() |
| 800 | ("pre-sorted" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 801 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 802 | alreadySorted = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 803 | } |
| 804 | )? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 805 | { |
| 806 | return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
| 807 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 808 | } |
| 809 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 810 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 811 | String AdapterName() throws ParseException : |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 812 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 813 | String adapterName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 814 | } |
| 815 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 816 | adapterName = Identifier() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 817 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 818 | return adapterName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 819 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 820 | } |
| 821 | |
salsubaiee | 0b423fa | 2013-09-19 19:16:48 -0700 | [diff] [blame] | 822 | Statement CompactStatement() throws ParseException: |
| 823 | { |
| 824 | Pair<Identifier,Identifier> nameComponents = null; |
| 825 | Statement stmt = null; |
| 826 | } |
| 827 | { |
| 828 | "compact" <DATASET> nameComponents = QualifiedName() |
| 829 | { |
| 830 | stmt = new CompactStatement(nameComponents.first, nameComponents.second); |
| 831 | } |
| 832 | { |
| 833 | return stmt; |
| 834 | } |
| 835 | } |
| 836 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 837 | Statement FeedStatement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 838 | { |
ramangrover29 | a774ef2 | 2013-07-17 09:29:18 -0700 | [diff] [blame] | 839 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 840 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 841 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 842 | Map<String,String> configuration = null; |
| 843 | Statement stmt = null; |
ramangrover29 | 566b3a9 | 2013-05-28 09:07:10 -0700 | [diff] [blame] | 844 | String policy = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 845 | } |
| 846 | { |
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 | "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())? |
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 | stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter()); |
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 | | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 853 | { |
ramangrover29 | a774ef2 | 2013-07-17 09:29:18 -0700 | [diff] [blame] | 854 | stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 855 | } |
| 856 | ) |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 857 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 858 | return stmt; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 862 | Map<String,String> Configuration() throws ParseException : |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 863 | { |
diegogiorgini@gmail.com | eb1910e | 2013-02-14 07:43:00 +0000 | [diff] [blame] | 864 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 865 | Pair<String, String> keyValuePair = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 866 | } |
| 867 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 868 | <LEFTPAREN> ( keyValuePair = KeyValuePair() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 869 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 870 | configuration.put(keyValuePair.first, keyValuePair.second); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 871 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 872 | ( <COMMA> keyValuePair = KeyValuePair() |
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 | configuration.put(keyValuePair.first, keyValuePair.second); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 875 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 876 | )* )? <RIGHTPAREN> |
| 877 | { |
| 878 | return configuration; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | Pair<String, String> KeyValuePair() throws ParseException: |
| 883 | { |
| 884 | String key; |
| 885 | String value; |
| 886 | } |
| 887 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 888 | <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 889 | { |
| 890 | return new Pair<String, String>(key, value); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 891 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | Map<String,String> Properties() throws ParseException: |
| 895 | { |
| 896 | Map<String,String> properties = new HashMap<String,String>(); |
| 897 | Pair<String, String> property; |
| 898 | } |
| 899 | { |
| 900 | ( <LEFTPAREN> property = Property() |
| 901 | { |
| 902 | properties.put(property.first, property.second); |
| 903 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 904 | ( <COMMA> property = Property() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 905 | { |
| 906 | properties.put(property.first, property.second); |
| 907 | } |
| 908 | )* <RIGHTPAREN> )? |
| 909 | { |
| 910 | return properties; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | Pair<String, String> Property() throws ParseException: |
| 915 | { |
| 916 | String key; |
| 917 | String value; |
| 918 | } |
| 919 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 920 | key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 921 | { |
| 922 | try { |
| 923 | value = "" + Long.valueOf(token.image); |
| 924 | } catch (NumberFormatException nfe) { |
| 925 | throw new ParseException("inapproriate value: " + token.image); |
| 926 | } |
| 927 | } |
| 928 | ) |
| 929 | { |
| 930 | return new Pair<String, String>(key.toUpperCase(), value); |
| 931 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | TypeExpression TypeExpr() throws ParseException: |
| 935 | { |
| 936 | TypeExpression typeExpr = null; |
| 937 | } |
| 938 | { |
| 939 | ( |
| 940 | typeExpr = RecordTypeDef() |
| 941 | | typeExpr = TypeReference() |
| 942 | | typeExpr = OrderedListTypeDef() |
| 943 | | typeExpr = UnorderedListTypeDef() |
| 944 | ) |
| 945 | { |
| 946 | return typeExpr; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 951 | { |
| 952 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 953 | RecordTypeDefinition.RecordKind recordKind = null; |
| 954 | } |
| 955 | { |
| 956 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 957 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 958 | <LEFTBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 959 | { |
| 960 | String hint = getHint(token); |
| 961 | if (hint != null) { |
| 962 | String splits[] = hint.split(" +"); |
| 963 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 964 | if (splits.length != 5) { |
| 965 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 966 | } |
| 967 | if (!splits[1].equals("int")) { |
| 968 | throw new ParseException("The only supported type for gen-fields is int."); |
| 969 | } |
| 970 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 971 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 972 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | } |
| 977 | ( |
| 978 | RecordField(recType) |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 979 | ( <COMMA> RecordField(recType) )* |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 980 | )? |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 981 | <RIGHTBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 982 | { |
| 983 | if (recordKind == null) { |
| 984 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 985 | } |
| 986 | recType.setRecordKind(recordKind); |
| 987 | return recType; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 992 | { |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 993 | String fieldName; |
| 994 | TypeExpression type = null; |
| 995 | boolean nullable = false; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 996 | } |
| 997 | { |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 998 | fieldName = Identifier() |
| 999 | { |
| 1000 | String hint = getHint(token); |
| 1001 | IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null; |
| 1002 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1003 | <COLON> type = TypeExpr() (<QUES> { nullable = true; } )? |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 1004 | { |
| 1005 | recType.addField(fieldName, type, nullable, rfdg); |
| 1006 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | TypeReferenceExpression TypeReference() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1010 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1011 | String id = null; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1012 | } |
| 1013 | { |
| 1014 | id = Identifier() |
| 1015 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1016 | return new TypeReferenceExpression(new Identifier(id)); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1017 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1021 | { |
| 1022 | TypeExpression type = null; |
| 1023 | } |
| 1024 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1025 | <LEFTBRACKET> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1026 | ( type = TypeExpr() ) |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1027 | <RIGHTBRACKET> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1028 | { |
| 1029 | return new OrderedListTypeDefinition(type); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1035 | { |
| 1036 | TypeExpression type = null; |
| 1037 | } |
| 1038 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1039 | <LEFTDBLBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1040 | ( type = TypeExpr() ) |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1041 | <RIGHTDBLBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1042 | { |
| 1043 | return new UnorderedListTypeDefinition(type); |
| 1044 | } |
| 1045 | } |
| 1046 | |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1047 | FunctionName FunctionName() throws ParseException: |
| 1048 | { |
| 1049 | String first = null; |
| 1050 | String second = null; |
| 1051 | String third = null; |
| 1052 | boolean secondAfterDot = false; |
| 1053 | } |
| 1054 | { |
Raman Grover | d678090 | 2013-09-24 16:57:32 +0530 | [diff] [blame] | 1055 | first = Identifier() ( <DOT> second = Identifier() |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1056 | { |
| 1057 | secondAfterDot = true; |
| 1058 | } |
| 1059 | ("#" third = Identifier())? | "#" second = Identifier() )? |
| 1060 | { |
| 1061 | FunctionName result = new FunctionName(); |
| 1062 | if (second == null) { |
| 1063 | result.dataverse = defaultDataverse; |
| 1064 | result.library = null; |
| 1065 | result.function = first; |
| 1066 | } else if (third == null) { |
| 1067 | if (secondAfterDot) { |
| 1068 | result.dataverse = first; |
| 1069 | result.library = null; |
| 1070 | result.function = second; |
| 1071 | } else { |
| 1072 | result.dataverse = defaultDataverse; |
| 1073 | result.library = first; |
| 1074 | result.function = second; |
| 1075 | } |
| 1076 | } else { |
| 1077 | result.dataverse = first; |
| 1078 | result.library = second; |
| 1079 | result.function = third; |
| 1080 | } |
| 1081 | return result; |
| 1082 | } |
| 1083 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1084 | |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1085 | |
| 1086 | Pair<Identifier,Identifier> TypeName() throws ParseException: |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1087 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1088 | Pair<Identifier,Identifier> name = null; |
| 1089 | } |
| 1090 | { |
| 1091 | name = QualifiedName() |
| 1092 | { |
| 1093 | if (name.first == null) { |
| 1094 | name.first = new Identifier(defaultDataverse); |
| 1095 | } |
| 1096 | return name; |
| 1097 | } |
| 1098 | } |
| 1099 | |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1100 | String Identifier() throws ParseException: |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1101 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1102 | String lit = null; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1103 | } |
| 1104 | { |
| 1105 | <IDENTIFIER> |
| 1106 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1107 | return token.image; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1108 | } |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1109 | | lit = StringLiteral() |
| 1110 | { |
| 1111 | return lit; |
| 1112 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1115 | String StringLiteral() throws ParseException: |
| 1116 | { |
| 1117 | } |
| 1118 | { |
| 1119 | <STRING_LITERAL> |
| 1120 | { |
| 1121 | return removeQuotesAndEscapes(token.image); |
| 1122 | } |
| 1123 | } |
| 1124 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1125 | Pair<Identifier,Identifier> QualifiedName() throws ParseException: |
| 1126 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1127 | String first = null; |
| 1128 | String second = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1129 | } |
| 1130 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1131 | first = Identifier() (<DOT> second = Identifier())? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1132 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1133 | Identifier id1 = null; |
| 1134 | Identifier id2 = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1135 | if (second == null) { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1136 | id2 = new Identifier(first); |
| 1137 | } else |
| 1138 | { |
| 1139 | id1 = new Identifier(first); |
| 1140 | id2 = new Identifier(second); |
| 1141 | } |
| 1142 | return new Pair<Identifier,Identifier>(id1, id2); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1146 | Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException: |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1147 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1148 | String first = null; |
| 1149 | String second = null; |
| 1150 | String third = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1151 | } |
| 1152 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1153 | first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1154 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1155 | Identifier id1 = null; |
| 1156 | Identifier id2 = null; |
| 1157 | Identifier id3 = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1158 | if (third == null) { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1159 | id2 = new Identifier(first); |
| 1160 | id3 = new Identifier(second); |
| 1161 | } else { |
| 1162 | id1 = new Identifier(first); |
| 1163 | id2 = new Identifier(second); |
| 1164 | id3 = new Identifier(third); |
| 1165 | } |
| 1166 | return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1170 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1171 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1172 | FunctionDecl funcDecl; |
| 1173 | FunctionSignature signature; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1174 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1175 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1176 | Expression funcBody; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1177 | createNewScope(); |
| 1178 | } |
| 1179 | { |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 1180 | "declare" "function" functionName = Identifier() |
| 1181 | paramList = ParameterList() |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1182 | <LEFTBRACE> funcBody = Expression() <RIGHTBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1183 | { |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 1184 | signature = new FunctionSignature(defaultDataverse, functionName, paramList.size()); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1185 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1186 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
Till Westmann | c6c4a74 | 2013-05-20 17:59:21 -0700 | [diff] [blame] | 1187 | removeCurrentScope(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1188 | return funcDecl; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1192 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1193 | Query Query() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1194 | { |
| 1195 | Query query = new Query(); |
| 1196 | Expression expr; |
| 1197 | } |
| 1198 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1199 | expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1200 | { |
| 1201 | query.setBody(expr); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1202 | query.setVarCounter(getVarCounter()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1203 | return query; |
| 1204 | } |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1205 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | Expression Expression(): |
| 1211 | { |
| 1212 | Expression expr = null; |
| 1213 | Expression exprP = null; |
| 1214 | } |
| 1215 | { |
| 1216 | ( |
| 1217 | |
| 1218 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1219 | expr = OperatorExpr() |
| 1220 | | expr = IfThenElse() |
| 1221 | | expr = FLWOGR() |
| 1222 | | expr = QuantifiedExpression() |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1223 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1224 | |
| 1225 | ) |
| 1226 | { |
| 1227 | return (exprP==null) ? expr : exprP; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | Expression OperatorExpr()throws ParseException: |
| 1234 | { |
| 1235 | OperatorExpr op = null; |
| 1236 | Expression operand = null; |
| 1237 | } |
| 1238 | { |
| 1239 | operand = AndExpr() |
| 1240 | ( |
| 1241 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1242 | <OR> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1243 | { |
| 1244 | if (op == null) { |
| 1245 | op = new OperatorExpr(); |
| 1246 | op.addOperand(operand); |
| 1247 | op.setCurrentop(true); |
| 1248 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1249 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | operand = AndExpr() |
| 1253 | { |
| 1254 | op.addOperand(operand); |
| 1255 | } |
| 1256 | |
| 1257 | )* |
| 1258 | |
| 1259 | { |
| 1260 | return op==null? operand: op; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | Expression AndExpr()throws ParseException: |
| 1265 | { |
| 1266 | OperatorExpr op = null; |
| 1267 | Expression operand = null; |
| 1268 | } |
| 1269 | { |
| 1270 | operand = RelExpr() |
| 1271 | ( |
| 1272 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1273 | <AND> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1274 | { |
| 1275 | if (op == null) { |
| 1276 | op = new OperatorExpr(); |
| 1277 | op.addOperand(operand); |
| 1278 | op.setCurrentop(true); |
| 1279 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1280 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | operand = RelExpr() |
| 1284 | { |
| 1285 | op.addOperand(operand); |
| 1286 | } |
| 1287 | |
| 1288 | )* |
| 1289 | |
| 1290 | { |
| 1291 | return op==null? operand: op; |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | Expression RelExpr()throws ParseException: |
| 1298 | { |
| 1299 | OperatorExpr op = null; |
| 1300 | Expression operand = null; |
| 1301 | boolean broadcast = false; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1302 | IExpressionAnnotation annotation = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1303 | } |
| 1304 | { |
| 1305 | operand = AddExpr() |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1306 | { |
| 1307 | if (operand instanceof VariableExpr) { |
| 1308 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1309 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1310 | broadcast = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | ( |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1316 | LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1317 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1318 | String mhint = getHint(token); |
| 1319 | if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1320 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1321 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1322 | if (op == null) { |
| 1323 | op = new OperatorExpr(); |
| 1324 | op.addOperand(operand, broadcast); |
| 1325 | op.setCurrentop(true); |
| 1326 | broadcast = false; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1327 | } |
| 1328 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | operand = AddExpr() |
| 1332 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1333 | broadcast = false; |
| 1334 | if (operand instanceof VariableExpr) { |
| 1335 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1336 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1337 | broadcast = true; |
| 1338 | } |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1339 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1340 | op.addOperand(operand, broadcast); |
| 1341 | } |
| 1342 | )? |
| 1343 | |
| 1344 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1345 | if (annotation != null) { |
| 1346 | op.addHint(annotation); |
| 1347 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1348 | return op==null? operand: op; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | Expression AddExpr()throws ParseException: |
| 1353 | { |
| 1354 | OperatorExpr op = null; |
| 1355 | Expression operand = null; |
| 1356 | } |
| 1357 | { |
| 1358 | operand = MultExpr() |
| 1359 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1360 | ( (<PLUS> | <MINUS>) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1361 | { |
| 1362 | if (op == null) { |
| 1363 | op = new OperatorExpr(); |
| 1364 | op.addOperand(operand); |
| 1365 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1366 | } |
| 1367 | ((OperatorExpr)op).addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | operand = MultExpr() |
| 1371 | { |
| 1372 | op.addOperand(operand); |
| 1373 | } |
| 1374 | )* |
| 1375 | |
| 1376 | { |
| 1377 | return op==null? operand: op; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | Expression MultExpr()throws ParseException: |
| 1382 | { |
| 1383 | OperatorExpr op = null; |
| 1384 | Expression operand = null; |
| 1385 | } |
| 1386 | { |
| 1387 | operand = UnionExpr() |
| 1388 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1389 | (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1390 | { |
| 1391 | if (op == null) { |
| 1392 | op = new OperatorExpr(); |
| 1393 | op.addOperand(operand); |
| 1394 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1395 | } |
| 1396 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1397 | } |
| 1398 | operand = UnionExpr() |
| 1399 | { |
| 1400 | op.addOperand(operand); |
| 1401 | } |
| 1402 | )* |
| 1403 | |
| 1404 | { |
| 1405 | return op==null?operand:op; |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | Expression UnionExpr() throws ParseException: |
| 1410 | { |
| 1411 | UnionExpr union = null; |
| 1412 | Expression operand1 = null; |
| 1413 | Expression operand2 = null; |
| 1414 | } |
| 1415 | { |
| 1416 | operand1 = UnaryExpr() |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1417 | (<UNION> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1418 | (operand2 = UnaryExpr()) { |
| 1419 | if (union == null) { |
| 1420 | union = new UnionExpr(); |
| 1421 | union.addExpr(operand1); |
| 1422 | } |
| 1423 | union.addExpr(operand2); |
| 1424 | } )* |
| 1425 | { |
| 1426 | return (union == null)? operand1: union; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | Expression UnaryExpr() throws ParseException: |
| 1431 | { |
| 1432 | Expression uexpr = null; |
| 1433 | Expression expr = null; |
| 1434 | } |
| 1435 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1436 | ( (<PLUS> | <MINUS>) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1437 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1438 | uexpr = new UnaryExpr(); |
| 1439 | if("+".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1440 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1441 | else if("-".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1442 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1443 | else |
| 1444 | throw new ParseException(); |
| 1445 | } |
| 1446 | )? |
| 1447 | |
| 1448 | expr = ValueExpr() |
| 1449 | { |
| 1450 | if(uexpr!=null){ |
| 1451 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1452 | return uexpr; |
| 1453 | } |
| 1454 | else{ |
| 1455 | return expr; |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1460 | Expression ValueExpr()throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1461 | { |
| 1462 | Expression expr = null; |
| 1463 | Identifier ident = null; |
| 1464 | AbstractAccessor fa = null; |
| 1465 | int index; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1466 | } |
| 1467 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1468 | expr = PrimaryExpr() ( ident = Field() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1469 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1470 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 1471 | : new FieldAccessor(fa, ident)); |
| 1472 | } |
| 1473 | | index = Index() |
| 1474 | { |
| 1475 | fa = (fa == null ? new IndexAccessor(expr, index) |
| 1476 | : new IndexAccessor(fa, index)); |
| 1477 | } |
| 1478 | )* |
| 1479 | { |
| 1480 | return fa == null ? expr : fa; |
| 1481 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | Identifier Field() throws ParseException: |
| 1485 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1486 | String ident = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1487 | } |
| 1488 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1489 | <DOT> ident = Identifier() |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1490 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1491 | return new Identifier(ident); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1492 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | int Index() throws ParseException: |
| 1496 | { |
| 1497 | Expression expr = null; |
| 1498 | int idx = -2; |
| 1499 | } |
| 1500 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1501 | <LEFTBRACKET> ( expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1502 | { |
| 1503 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1504 | { |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1505 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1506 | if(lit.getLiteralType() == Literal.Type.INTEGER || |
| 1507 | lit.getLiteralType() == Literal.Type.LONG) { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1508 | idx = Integer.valueOf(lit.getStringValue()); |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1509 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1510 | else { |
| 1511 | throw new ParseException("Index should be an INTEGER"); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | } |
| 1516 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1517 | | <QUES> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1518 | { |
| 1519 | idx = IndexAccessor.ANY; |
| 1520 | // ANY |
| 1521 | } |
| 1522 | |
| 1523 | ) |
| 1524 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1525 | <RIGHTBRACKET> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1526 | { |
| 1527 | return idx; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | Expression PrimaryExpr()throws ParseException: |
| 1533 | { |
| 1534 | Expression expr = null; |
| 1535 | } |
| 1536 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1537 | ( LOOKAHEAD(2) |
| 1538 | expr = FunctionCallExpr() |
| 1539 | | expr = Literal() |
| 1540 | | expr = DatasetAccessExpression() |
| 1541 | | expr = VariableRef() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1542 | { |
| 1543 | if(((VariableExpr)expr).getIsNewVar() == true) |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1544 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1545 | } |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1546 | | expr = ListConstructor() |
| 1547 | | expr = RecordConstructor() |
| 1548 | | expr = ParenthesizedExpression() |
| 1549 | ) |
| 1550 | { |
| 1551 | return expr; |
| 1552 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | Expression Literal() throws ParseException: |
| 1556 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1557 | LiteralExpr lit = new LiteralExpr(); |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1558 | String str = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1559 | } |
| 1560 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1561 | ( str = StringLiteral() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1562 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1563 | lit.setValue(new StringLiteral(str)); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1564 | } |
| 1565 | | <INTEGER_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1566 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1567 | try { |
| 1568 | lit.setValue(new IntegerLiteral(new Integer(token.image))); |
| 1569 | } catch(NumberFormatException ex) { |
| 1570 | lit.setValue(new LongIntegerLiteral(new Long(token.image))); |
| 1571 | } |
| 1572 | } |
| 1573 | | <FLOAT_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1574 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1575 | lit.setValue(new FloatLiteral(new Float(token.image))); |
| 1576 | } |
| 1577 | | <DOUBLE_LITERAL> |
| 1578 | { |
| 1579 | lit.setValue(new DoubleLiteral(new Double(token.image))); |
| 1580 | } |
| 1581 | | <NULL> |
| 1582 | { |
| 1583 | lit.setValue(NullLiteral.INSTANCE); |
| 1584 | } |
| 1585 | | <TRUE> |
| 1586 | { |
| 1587 | lit.setValue(TrueLiteral.INSTANCE); |
| 1588 | } |
| 1589 | | <FALSE> |
| 1590 | { |
| 1591 | lit.setValue(FalseLiteral.INSTANCE); |
| 1592 | } |
| 1593 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1594 | { |
| 1595 | return lit; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | |
| 1600 | VariableExpr VariableRef() throws ParseException: |
| 1601 | { |
| 1602 | VariableExpr varExp = new VariableExpr(); |
| 1603 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1604 | } |
| 1605 | { |
Till Westmann | 4f58e1a | 2013-05-20 18:29:54 -0700 | [diff] [blame] | 1606 | <VARIABLE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1607 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1608 | String varName = token.image; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1609 | Identifier ident = lookupSymbol(varName); |
| 1610 | if (isInForbiddenScopes(varName)) { |
| 1611 | 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."); |
| 1612 | } |
| 1613 | if(ident != null) { // exist such ident |
| 1614 | varExp.setIsNewVar(false); |
| 1615 | varExp.setVar((VarIdentifier)ident); |
| 1616 | } else { |
| 1617 | varExp.setVar(var); |
| 1618 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1619 | var.setValue(varName); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1620 | return varExp; |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | VariableExpr Variable() throws ParseException: |
| 1626 | { |
| 1627 | VariableExpr varExp = new VariableExpr(); |
| 1628 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1629 | } |
| 1630 | { |
Till Westmann | 4f58e1a | 2013-05-20 18:29:54 -0700 | [diff] [blame] | 1631 | <VARIABLE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1632 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1633 | Identifier ident = lookupSymbol(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1634 | if(ident != null) { // exist such ident |
| 1635 | varExp.setIsNewVar(false); |
| 1636 | } |
| 1637 | varExp.setVar(var); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1638 | var.setValue(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1639 | return varExp; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | Expression ListConstructor() throws ParseException: |
| 1644 | { |
| 1645 | Expression expr = null; |
| 1646 | } |
| 1647 | { |
| 1648 | ( |
| 1649 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1650 | ) |
| 1651 | |
| 1652 | { |
| 1653 | return expr; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1659 | { |
| 1660 | ListConstructor expr = new ListConstructor(); |
| 1661 | Expression tmp = null; |
| 1662 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1663 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1664 | } |
| 1665 | { |
| 1666 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1667 | <LEFTBRACKET> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1668 | ( tmp = Expression() |
| 1669 | { |
| 1670 | exprList.add(tmp); |
| 1671 | } |
| 1672 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1673 | (<COMMA> tmp = Expression() { exprList.add(tmp); })* |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1674 | )? |
| 1675 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1676 | <RIGHTBRACKET> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1677 | |
| 1678 | { |
| 1679 | expr.setExprList(exprList); |
| 1680 | return expr; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1685 | { |
| 1686 | ListConstructor expr = new ListConstructor(); |
| 1687 | Expression tmp = null; |
| 1688 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1689 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 1690 | } |
| 1691 | { |
| 1692 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1693 | <LEFTDBLBRACE> ( tmp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1694 | { |
| 1695 | exprList.add(tmp); |
| 1696 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1697 | (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1698 | { |
| 1699 | expr.setExprList(exprList); |
| 1700 | return expr; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | RecordConstructor RecordConstructor() throws ParseException: |
| 1705 | { |
| 1706 | RecordConstructor expr = new RecordConstructor(); |
| 1707 | FieldBinding tmp = null; |
| 1708 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 1709 | } |
| 1710 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1711 | <LEFTBRACE> (tmp = FieldBinding() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1712 | { |
| 1713 | fbList.add(tmp); |
| 1714 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1715 | (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1716 | { |
| 1717 | expr.setFbList(fbList); |
| 1718 | return expr; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | FieldBinding FieldBinding() throws ParseException: |
| 1723 | { |
| 1724 | FieldBinding fb = new FieldBinding(); |
| 1725 | Expression left, right; |
| 1726 | } |
| 1727 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1728 | left = Expression() <COLON> right = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1729 | { |
| 1730 | fb.setLeftExpr(left); |
| 1731 | fb.setRightExpr(right); |
| 1732 | return fb; |
| 1733 | } |
| 1734 | } |
| 1735 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1736 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1737 | Expression FunctionCallExpr() throws ParseException: |
| 1738 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1739 | CallExpr callExpr; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1740 | List<Expression> argList = new ArrayList<Expression>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1741 | Expression tmp; |
| 1742 | int arity = 0; |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1743 | FunctionName funcName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1744 | String hint = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1745 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1746 | { |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1747 | funcName = FunctionName() |
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 | hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1750 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1751 | <LEFTPAREN> (tmp = Expression() |
| 1752 | { |
| 1753 | argList.add(tmp); |
| 1754 | arity ++; |
| 1755 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1756 | (<COMMA> tmp = Expression() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1757 | { |
| 1758 | argList.add(tmp); |
| 1759 | arity++; |
| 1760 | } |
| 1761 | )*)? <RIGHTPAREN> |
| 1762 | { |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1763 | // TODO use funcName.library |
ramangrover29 | bdba1a8 | 2013-06-21 17:17:52 -0700 | [diff] [blame] | 1764 | String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function; |
ramangrover29 | 9f76a5e | 2013-06-18 10:25:17 -0700 | [diff] [blame] | 1765 | FunctionSignature signature |
ramangrover29 | bdba1a8 | 2013-06-21 17:17:52 -0700 | [diff] [blame] | 1766 | = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1767 | if (signature == null) { |
ramangrover29 | bdba1a8 | 2013-06-21 17:17:52 -0700 | [diff] [blame] | 1768 | signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1769 | } |
| 1770 | callExpr = new CallExpr(signature,argList); |
| 1771 | if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1772 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 1773 | } |
| 1774 | return callExpr; |
| 1775 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
ramangrover29@gmail.com | 5f248e1 | 2013-04-11 01:03:09 +0000 | [diff] [blame] | 1778 | |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1779 | Expression DatasetAccessExpression() throws ParseException: |
| 1780 | { |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1781 | String funcName; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1782 | String arg1 = null; |
| 1783 | String arg2 = null; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1784 | Expression nameArg; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1785 | } |
| 1786 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1787 | <DATASET> |
| 1788 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1789 | funcName = token.image; |
| 1790 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1791 | ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? ) |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1792 | { |
| 1793 | String name = arg2 == null ? arg1 : arg1 + "." + arg2; |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1794 | LiteralExpr ds = new LiteralExpr(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1795 | ds.setValue( new StringLiteral(name) ); |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1796 | nameArg = ds; |
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 | | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) ) |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1799 | { |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1800 | String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; |
| 1801 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1); |
| 1802 | if (signature == null) { |
| 1803 | signature = new FunctionSignature(dataverse, funcName, 1); |
| 1804 | } |
| 1805 | List<Expression> argList = new ArrayList<Expression>(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1806 | argList.add(nameArg); |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1807 | return new CallExpr(signature, argList); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1808 | } |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1809 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1810 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1811 | Expression ParenthesizedExpression() throws ParseException: |
| 1812 | { |
| 1813 | Expression expr; |
| 1814 | } |
| 1815 | { |
| 1816 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1817 | { |
| 1818 | return expr; |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | Expression IfThenElse() throws ParseException: |
| 1823 | { |
| 1824 | Expression condExpr; |
| 1825 | Expression thenExpr; |
| 1826 | Expression elseExpr; |
| 1827 | IfExpr ifExpr = new IfExpr(); |
| 1828 | } |
| 1829 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1830 | <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1831 | |
| 1832 | { |
| 1833 | ifExpr.setCondExpr(condExpr); |
| 1834 | ifExpr.setThenExpr(thenExpr); |
| 1835 | ifExpr.setElseExpr(elseExpr); |
| 1836 | return ifExpr; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | Expression FLWOGR() throws ParseException: |
| 1841 | { |
| 1842 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1843 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1844 | Expression returnExpr; |
| 1845 | Clause tmp; |
| 1846 | createNewScope(); |
| 1847 | } |
| 1848 | { |
| 1849 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1850 | (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1851 | |
| 1852 | { |
| 1853 | flworg.setClauseList(clauseList); |
| 1854 | flworg.setReturnExpr(returnExpr); |
| 1855 | removeCurrentScope(); |
| 1856 | return flworg; |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | Clause Clause()throws ParseException : |
| 1861 | { |
| 1862 | Clause clause; |
| 1863 | } |
| 1864 | { |
| 1865 | ( |
| 1866 | clause = ForClause() |
| 1867 | | clause = LetClause() |
| 1868 | | clause = WhereClause() |
| 1869 | | clause = OrderbyClause() |
| 1870 | | clause = GroupClause() |
| 1871 | | clause = LimitClause() |
| 1872 | | clause = DistinctClause() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1873 | ) |
| 1874 | { |
| 1875 | return clause; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | Clause ForClause()throws ParseException : |
| 1880 | { |
| 1881 | ForClause fc = new ForClause(); |
| 1882 | VariableExpr varExp; |
| 1883 | VariableExpr varPos = null; |
| 1884 | Expression inExp; |
| 1885 | extendCurrentScope(); |
| 1886 | } |
| 1887 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1888 | <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1889 | { |
| 1890 | fc.setVarExpr(varExp); |
Vinayak Borkar | 62e66c0 | 2013-05-28 13:56:11 -0700 | [diff] [blame] | 1891 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1892 | fc.setInExpr(inExp); |
| 1893 | if (varPos != null) { |
| 1894 | fc.setPosExpr(varPos); |
Vinayak Borkar | 62e66c0 | 2013-05-28 13:56:11 -0700 | [diff] [blame] | 1895 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1896 | } |
| 1897 | return fc; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | Clause LetClause() throws ParseException: |
| 1902 | { |
| 1903 | LetClause lc = new LetClause(); |
| 1904 | VariableExpr varExp; |
| 1905 | Expression beExp; |
| 1906 | extendCurrentScope(); |
| 1907 | } |
| 1908 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1909 | <LET> varExp = Variable() <ASSIGN> beExp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1910 | { |
| 1911 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1912 | lc.setVarExpr(varExp); |
| 1913 | lc.setBeExpr(beExp); |
| 1914 | return lc; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | Clause WhereClause()throws ParseException : |
| 1919 | { |
| 1920 | WhereClause wc = new WhereClause(); |
| 1921 | Expression whereExpr; |
| 1922 | } |
| 1923 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1924 | <WHERE> whereExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1925 | { |
| 1926 | wc.setWhereExpr(whereExpr); |
| 1927 | return wc; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | Clause OrderbyClause()throws ParseException : |
| 1932 | { |
| 1933 | OrderbyClause oc = new OrderbyClause(); |
| 1934 | Expression orderbyExpr; |
| 1935 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1936 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1937 | int numOfOrderby = 0; |
| 1938 | } |
| 1939 | { |
| 1940 | ( |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1941 | <ORDER> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1942 | { |
| 1943 | String hint = getHint(token); |
| 1944 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 1945 | String splits[] = hint.split(" +"); |
| 1946 | int numFrames = Integer.parseInt(splits[1]); |
| 1947 | int numTuples = Integer.parseInt(splits[2]); |
| 1948 | oc.setNumFrames(numFrames); |
| 1949 | oc.setNumTuples(numTuples); |
| 1950 | } |
| 1951 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1952 | <BY> orderbyExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1953 | { |
| 1954 | orderbyList.add(orderbyExpr); |
| 1955 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 1956 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1957 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1958 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1959 | { |
| 1960 | modifierList.add(modif); |
| 1961 | } |
| 1962 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1963 | (<COMMA> orderbyExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1964 | { |
| 1965 | orderbyList.add(orderbyExpr); |
| 1966 | modif = OrderbyClause.OrderModifier.ASC; |
| 1967 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1968 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1969 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1970 | { |
| 1971 | modifierList.add(modif); |
| 1972 | } |
| 1973 | )* |
| 1974 | ) |
| 1975 | { |
| 1976 | oc.setModifierList(modifierList); |
| 1977 | oc.setOrderbyList(orderbyList); |
| 1978 | return oc; |
| 1979 | } |
| 1980 | } |
| 1981 | Clause GroupClause()throws ParseException : |
| 1982 | { |
| 1983 | GroupbyClause gbc = new GroupbyClause(); |
| 1984 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1985 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1986 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1987 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1988 | VariableExpr var = null; |
| 1989 | VariableExpr withVar = null; |
| 1990 | Expression expr = null; |
| 1991 | VariableExpr decorVar = null; |
| 1992 | Expression decorExpr = null; |
| 1993 | } |
| 1994 | { |
| 1995 | { |
| 1996 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1997 | // extendCurrentScope(true); |
| 1998 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 1999 | <GROUP> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2000 | { |
| 2001 | String hint = getHint(token); |
| 2002 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 2003 | gbc.setHashGroupByHint(true); |
| 2004 | } |
| 2005 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2006 | <BY> (LOOKAHEAD(2) var = Variable() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2007 | { |
| 2008 | newScope.addNewVarSymbolToScope(var.getVar()); |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2009 | } <ASSIGN>)? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2010 | expr = Expression() |
| 2011 | { |
| 2012 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 2013 | vePairList.add(pair1); |
| 2014 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2015 | (<COMMA> ( LOOKAHEAD(2) var = Variable() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2016 | { |
| 2017 | newScope.addNewVarSymbolToScope(var.getVar()); |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2018 | } <ASSIGN>)? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2019 | expr = Expression() |
| 2020 | { |
| 2021 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 2022 | vePairList.add(pair2); |
| 2023 | } |
| 2024 | )* |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2025 | (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2026 | { |
| 2027 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2028 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2029 | decorPairList.add(pair3); |
| 2030 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2031 | (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2032 | { |
| 2033 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2034 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2035 | decorPairList.add(pair4); |
| 2036 | } |
| 2037 | )* |
| 2038 | )? |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2039 | <WITH> withVar = VariableRef() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2040 | { |
| 2041 | if(withVar.getIsNewVar()==true) |
| 2042 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2043 | withVarList.add(withVar); |
| 2044 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2045 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2046 | (<COMMA> withVar = VariableRef() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2047 | { |
| 2048 | if(withVar.getIsNewVar()==true) |
| 2049 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2050 | withVarList.add(withVar); |
| 2051 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2052 | })* |
| 2053 | { |
| 2054 | gbc.setGbyPairList(vePairList); |
| 2055 | gbc.setDecorPairList(decorPairList); |
| 2056 | gbc.setWithVarList(withVarList); |
| 2057 | replaceCurrentScope(newScope); |
| 2058 | return gbc; |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | |
| 2063 | LimitClause LimitClause() throws ParseException: |
| 2064 | { |
| 2065 | LimitClause lc = new LimitClause(); |
| 2066 | Expression expr; |
| 2067 | pushForbiddenScope(getCurrentScope()); |
| 2068 | } |
| 2069 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2070 | <LIMIT> expr = Expression() { lc.setLimitExpr(expr); } |
| 2071 | (<OFFSET> expr = Expression() { lc.setOffset(expr); })? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2072 | |
| 2073 | { |
| 2074 | popForbiddenScope(); |
| 2075 | return lc; |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | DistinctClause DistinctClause() throws ParseException: |
| 2080 | { |
| 2081 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2082 | Expression expr; |
| 2083 | } |
| 2084 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2085 | <DISTINCT> <BY> expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2086 | { |
| 2087 | exprs.add(expr); |
| 2088 | } |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2089 | (<COMMA> expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2090 | { |
| 2091 | exprs.add(expr); |
| 2092 | } |
| 2093 | )* |
| 2094 | { |
| 2095 | return new DistinctClause(exprs); |
| 2096 | } |
| 2097 | } |
| 2098 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2099 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2100 | { |
| 2101 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2102 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2103 | Expression satisfiesExpr; |
| 2104 | VariableExpr var; |
| 2105 | Expression inExpr; |
| 2106 | QuantifiedPair pair; |
| 2107 | } |
| 2108 | { |
| 2109 | { |
| 2110 | createNewScope(); |
| 2111 | } |
| 2112 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2113 | ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2114 | | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2115 | var = Variable() <IN> inExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2116 | { |
| 2117 | pair = new QuantifiedPair(var, inExpr); |
| 2118 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2119 | quantifiedList.add(pair); |
| 2120 | } |
| 2121 | ( |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2122 | <COMMA> var = Variable() <IN> inExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2123 | { |
| 2124 | pair = new QuantifiedPair(var, inExpr); |
| 2125 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2126 | quantifiedList.add(pair); |
| 2127 | } |
| 2128 | )* |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2129 | <SATISFIES> satisfiesExpr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2130 | { |
| 2131 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2132 | qc.setQuantifiedList(quantifiedList); |
| 2133 | removeCurrentScope(); |
| 2134 | return qc; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | TOKEN_MGR_DECLS: |
| 2139 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2140 | public int commentDepth = 0; |
| 2141 | public IntStack lexerStateStack = new IntStack(); |
| 2142 | |
| 2143 | public void pushState() { |
| 2144 | lexerStateStack.push( curLexState ); |
| 2145 | } |
| 2146 | |
| 2147 | public void popState() { |
| 2148 | if (lexerStateStack.size() > 0) { |
| 2149 | SwitchTo( lexerStateStack.pop() ); |
| 2150 | } else { |
| 2151 | throw new RuntimeException(); |
| 2152 | } |
| 2153 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2156 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2157 | TOKEN : |
| 2158 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2159 | <ASC : "asc"> |
| 2160 | | <AT : "at"> |
| 2161 | | <BY : "by"> |
| 2162 | | <DATASET : "dataset"> |
| 2163 | | <DECOR : "decor"> |
| 2164 | | <DESC : "desc"> |
| 2165 | | <DISTINCT : "distinct"> |
| 2166 | | <ELSE : "else"> |
| 2167 | | <EVERY : "every"> |
| 2168 | | <FOR : "for"> |
| 2169 | | <GROUP : "group"> |
| 2170 | | <IF : "if"> |
| 2171 | | <IN : "in"> |
| 2172 | | <LET : "let"> |
| 2173 | | <LIMIT : "limit"> |
| 2174 | | <OFFSET : "offset"> |
| 2175 | | <ORDER : "order"> |
| 2176 | | <RETURN : "return"> |
| 2177 | | <SATISFIES : "satisfies"> |
| 2178 | | <SOME : "some"> |
| 2179 | | <THEN : "then"> |
| 2180 | | <UNION : "union"> |
| 2181 | | <WHERE : "where"> |
| 2182 | | <WITH : "with"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2185 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2186 | TOKEN : |
| 2187 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2188 | <CARET : "^"> |
| 2189 | | <DIV : "/"> |
| 2190 | | <IDIV : "idiv"> |
| 2191 | | <MINUS : "-"> |
| 2192 | | <MOD : "%"> |
| 2193 | | <MUL : "*"> |
| 2194 | | <PLUS : "+"> |
| 2195 | |
| 2196 | | <LEFTPAREN : "("> |
| 2197 | | <RIGHTPAREN : ")"> |
| 2198 | | <LEFTBRACKET : "["> |
| 2199 | | <RIGHTBRACKET : "]"> |
| 2200 | |
| 2201 | | <COLON : ":"> |
| 2202 | | <COMMA : ","> |
| 2203 | | <DOT : "."> |
| 2204 | | <QUES : "?"> |
| 2205 | |
| 2206 | | <LT : "<"> |
| 2207 | | <GT : ">"> |
| 2208 | | <LE : "<="> |
| 2209 | | <GE : ">="> |
| 2210 | | <EQ : "="> |
| 2211 | | <NE : "!="> |
| 2212 | | <SIMILAR : "~="> |
| 2213 | | <ASSIGN : ":="> |
| 2214 | |
| 2215 | | <AND : "and"> |
| 2216 | | <OR : "or"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2219 | <DEFAULT,IN_DBL_BRACE> |
| 2220 | TOKEN : |
| 2221 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2222 | <LEFTBRACE : "{"> { pushState(); } : DEFAULT |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | <DEFAULT> |
| 2226 | TOKEN : |
| 2227 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2228 | <RIGHTBRACE : "}"> { popState(); } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2231 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2232 | TOKEN : |
| 2233 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2234 | <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2237 | <IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2238 | TOKEN : |
| 2239 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2240 | <RIGHTDBLBRACE : "}}"> { popState(); } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2243 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2244 | TOKEN : |
| 2245 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2246 | <INTEGER_LITERAL : (<DIGIT>)+ > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2249 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2250 | TOKEN : |
| 2251 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2252 | <NULL : "null"> |
| 2253 | | <TRUE : "true"> |
| 2254 | | <FALSE : "false"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2257 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2258 | TOKEN : |
| 2259 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2260 | <#DIGIT : ["0" - "9"]> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2263 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2264 | TOKEN: |
| 2265 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2266 | < DOUBLE_LITERAL: <DIGITS> |
Till Westmann | af0551c | 2013-07-23 14:53:31 -0700 | [diff] [blame] | 2267 | | <DIGITS> ( "." <DIGITS> )? |
| 2268 | | "." <DIGITS> |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2269 | > |
| 2270 | | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" ) |
Till Westmann | af0551c | 2013-07-23 14:53:31 -0700 | [diff] [blame] | 2271 | | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )? |
| 2272 | | "." <DIGITS> ( "f" | "F" ) |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2273 | > |
| 2274 | | <DIGITS : (<DIGIT>)+ > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2277 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2278 | TOKEN : |
| 2279 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2280 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2281 | | <SPECIALCHARS : ["$", "_", "-"]> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2282 | } |
| 2283 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2284 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2285 | TOKEN : |
| 2286 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2287 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2288 | | < #EscapeQuot: "\\\"" > |
| 2289 | | < #EscapeApos: "\\\'" > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2292 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2293 | TOKEN : |
| 2294 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2295 | <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2298 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2299 | TOKEN : |
| 2300 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2301 | <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2304 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2305 | SKIP: |
| 2306 | { |
| 2307 | " " |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2308 | | "\t" |
| 2309 | | "\r" |
| 2310 | | "\n" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2313 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2314 | SKIP: |
| 2315 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2316 | <"//" (~["\n"])* "\n"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2319 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2320 | SKIP: |
| 2321 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2322 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2325 | <DEFAULT,IN_DBL_BRACE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2326 | SKIP: |
| 2327 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2328 | <"/*"> { pushState(); } : INSIDE_COMMENT |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | <INSIDE_COMMENT> |
| 2332 | SPECIAL_TOKEN: |
| 2333 | { |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2334 | <"+"(" ")*(~["*"])*> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | <INSIDE_COMMENT> |
| 2338 | SKIP: |
| 2339 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2340 | <"/*"> { pushState(); } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | <INSIDE_COMMENT> |
| 2344 | SKIP: |
| 2345 | { |
Till Westmann | 96c1f17 | 2013-08-01 02:05:48 -0700 | [diff] [blame] | 2346 | <"*/"> { popState(); } |
Till Westmann | 5df7b45 | 2013-08-02 13:07:16 -0700 | [diff] [blame] | 2347 | | <~[]> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2348 | } |