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