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