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