Michael Blow | 82464fb | 2017-03-28 18:48:13 -0400 | [diff] [blame] | 1 | // |
| 2 | // Licensed to the Apache Software Foundation (ASF) under one |
| 3 | // or more contributor license agreements. See the NOTICE file |
| 4 | // distributed with this work for additional information |
| 5 | // regarding copyright ownership. The ASF licenses this file |
| 6 | // to you under the Apache License, Version 2.0 (the |
| 7 | // "License"); you may not use this file except in compliance |
| 8 | // with the License. You may obtain a copy of the License at |
| 9 | // |
| 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | // |
| 12 | // Unless required by applicable law or agreed to in writing, |
| 13 | // software distributed under the License is distributed on an |
| 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | // KIND, either express or implied. See the License for the |
| 16 | // specific language governing permissions and limitations |
| 17 | // under the License. |
| 18 | // |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 19 | options { |
| 20 | |
| 21 | |
| 22 | STATIC = false; |
| 23 | |
| 24 | } |
| 25 | |
| 26 | |
| 27 | PARSER_BEGIN(SQLPPParser) |
| 28 | |
| 29 | package org.apache.asterix.lang.sqlpp.parser; |
| 30 | |
| 31 | // For SQL++ ParserTokenManager |
Till Westmann | e9b2adf | 2016-10-15 12:39:01 -0700 | [diff] [blame] | 32 | import java.util.ArrayDeque; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 33 | |
| 34 | import java.io.BufferedReader; |
| 35 | import java.io.File; |
| 36 | import java.io.FileInputStream; |
| 37 | import java.io.FileNotFoundException; |
| 38 | import java.io.IOException; |
| 39 | import java.io.InputStreamReader; |
| 40 | import java.io.Reader; |
| 41 | import java.io.StringReader; |
| 42 | import java.util.ArrayList; |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 43 | import java.util.Collections; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 44 | import java.util.HashMap; |
| 45 | import java.util.Iterator; |
| 46 | import java.util.LinkedHashMap; |
| 47 | import java.util.List; |
| 48 | import java.util.Map; |
| 49 | |
| 50 | import org.apache.asterix.common.annotations.AutoDataGen; |
| 51 | import org.apache.asterix.common.annotations.DateBetweenYearsDataGen; |
| 52 | import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen; |
| 53 | import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen; |
| 54 | import org.apache.asterix.common.annotations.FieldIntervalDataGen; |
| 55 | import org.apache.asterix.common.annotations.FieldValFileDataGen; |
| 56 | import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen; |
| 57 | import org.apache.asterix.common.annotations.IRecordFieldDataGen; |
| 58 | import org.apache.asterix.common.annotations.InsertRandIntDataGen; |
| 59 | import org.apache.asterix.common.annotations.ListDataGen; |
| 60 | import org.apache.asterix.common.annotations.ListValFileDataGen; |
| 61 | import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation; |
| 62 | import org.apache.asterix.common.annotations.TypeDataGen; |
| 63 | import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen; |
| 64 | import org.apache.asterix.common.config.DatasetConfig.DatasetType; |
| 65 | import org.apache.asterix.common.config.DatasetConfig.IndexType; |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 66 | import org.apache.asterix.common.exceptions.CompilationException; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 67 | import org.apache.asterix.common.functions.FunctionSignature; |
| 68 | import org.apache.asterix.lang.common.base.Expression; |
| 69 | import org.apache.asterix.lang.common.base.Literal; |
| 70 | import org.apache.asterix.lang.common.base.IParser; |
| 71 | import org.apache.asterix.lang.common.base.Statement; |
| 72 | import org.apache.asterix.lang.common.clause.GroupbyClause; |
| 73 | import org.apache.asterix.lang.common.clause.LetClause; |
| 74 | import org.apache.asterix.lang.common.clause.LimitClause; |
| 75 | import org.apache.asterix.lang.common.clause.OrderbyClause; |
| 76 | import org.apache.asterix.lang.common.clause.UpdateClause; |
| 77 | import org.apache.asterix.lang.common.clause.WhereClause; |
| 78 | import org.apache.asterix.lang.common.context.RootScopeFactory; |
| 79 | import org.apache.asterix.lang.common.context.Scope; |
| 80 | import org.apache.asterix.lang.common.expression.AbstractAccessor; |
| 81 | import org.apache.asterix.lang.common.expression.CallExpr; |
| 82 | import org.apache.asterix.lang.common.expression.FieldAccessor; |
| 83 | import org.apache.asterix.lang.common.expression.FieldBinding; |
| 84 | import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair; |
| 85 | import org.apache.asterix.lang.common.expression.IfExpr; |
| 86 | import org.apache.asterix.lang.common.expression.IndexAccessor; |
| 87 | import org.apache.asterix.lang.common.expression.ListConstructor; |
| 88 | import org.apache.asterix.lang.common.expression.LiteralExpr; |
| 89 | import org.apache.asterix.lang.common.expression.OperatorExpr; |
| 90 | import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition; |
| 91 | import org.apache.asterix.lang.common.expression.QuantifiedExpression; |
| 92 | import org.apache.asterix.lang.common.expression.RecordConstructor; |
| 93 | import org.apache.asterix.lang.common.expression.RecordTypeDefinition; |
| 94 | import org.apache.asterix.lang.common.expression.TypeExpression; |
| 95 | import org.apache.asterix.lang.common.expression.TypeReferenceExpression; |
| 96 | import org.apache.asterix.lang.common.expression.UnaryExpr; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 97 | import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition; |
| 98 | import org.apache.asterix.lang.common.expression.VariableExpr; |
| 99 | import org.apache.asterix.lang.common.literal.DoubleLiteral; |
| 100 | import org.apache.asterix.lang.common.literal.FalseLiteral; |
| 101 | import org.apache.asterix.lang.common.literal.FloatLiteral; |
| 102 | import org.apache.asterix.lang.common.literal.LongIntegerLiteral; |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 103 | import org.apache.asterix.lang.common.literal.MissingLiteral; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 104 | import org.apache.asterix.lang.common.literal.NullLiteral; |
| 105 | import org.apache.asterix.lang.common.literal.StringLiteral; |
| 106 | import org.apache.asterix.lang.common.literal.TrueLiteral; |
| 107 | import org.apache.asterix.lang.common.parser.ScopeChecker; |
| 108 | import org.apache.asterix.lang.common.statement.CompactStatement; |
| 109 | import org.apache.asterix.lang.common.statement.ConnectFeedStatement; |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 110 | import org.apache.asterix.lang.common.statement.StartFeedStatement; |
| 111 | import org.apache.asterix.lang.common.statement.StopFeedStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 112 | import org.apache.asterix.lang.common.statement.CreateDataverseStatement; |
| 113 | import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement; |
| 114 | import org.apache.asterix.lang.common.statement.CreateFeedStatement; |
| 115 | import org.apache.asterix.lang.common.statement.CreateFunctionStatement; |
| 116 | import org.apache.asterix.lang.common.statement.CreateIndexStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 117 | import org.apache.asterix.lang.common.statement.DatasetDecl; |
| 118 | import org.apache.asterix.lang.common.statement.DataverseDecl; |
| 119 | import org.apache.asterix.lang.common.statement.DataverseDropStatement; |
| 120 | import org.apache.asterix.lang.common.statement.DeleteStatement; |
| 121 | import org.apache.asterix.lang.common.statement.DisconnectFeedStatement; |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 122 | import org.apache.asterix.lang.common.statement.DropDatasetStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 123 | import org.apache.asterix.lang.common.statement.ExternalDetailsDecl; |
| 124 | import org.apache.asterix.lang.common.statement.FeedDropStatement; |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 125 | import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 126 | import org.apache.asterix.lang.common.statement.FunctionDecl; |
| 127 | import org.apache.asterix.lang.common.statement.FunctionDropStatement; |
| 128 | import org.apache.asterix.lang.common.statement.IndexDropStatement; |
| 129 | import org.apache.asterix.lang.common.statement.InsertStatement; |
| 130 | import org.apache.asterix.lang.common.statement.InternalDetailsDecl; |
| 131 | import org.apache.asterix.lang.common.statement.LoadStatement; |
| 132 | import org.apache.asterix.lang.common.statement.NodeGroupDropStatement; |
| 133 | import org.apache.asterix.lang.common.statement.NodegroupDecl; |
| 134 | import org.apache.asterix.lang.common.statement.Query; |
| 135 | import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement; |
| 136 | import org.apache.asterix.lang.common.statement.RunStatement; |
| 137 | import org.apache.asterix.lang.common.statement.SetStatement; |
| 138 | import org.apache.asterix.lang.common.statement.TypeDecl; |
| 139 | import org.apache.asterix.lang.common.statement.TypeDropStatement; |
| 140 | import org.apache.asterix.lang.common.statement.UpdateStatement; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 141 | import org.apache.asterix.lang.common.statement.UpsertStatement; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 142 | import org.apache.asterix.lang.common.statement.WriteStatement; |
| 143 | import org.apache.asterix.lang.common.struct.Identifier; |
| 144 | import org.apache.asterix.lang.common.struct.QuantifiedPair; |
| 145 | import org.apache.asterix.lang.common.struct.VarIdentifier; |
| 146 | import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause; |
| 147 | import org.apache.asterix.lang.sqlpp.clause.FromClause; |
| 148 | import org.apache.asterix.lang.sqlpp.clause.FromTerm; |
| 149 | import org.apache.asterix.lang.sqlpp.clause.HavingClause; |
| 150 | import org.apache.asterix.lang.sqlpp.clause.JoinClause; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 151 | import org.apache.asterix.lang.sqlpp.clause.Projection; |
| 152 | import org.apache.asterix.lang.sqlpp.clause.SelectBlock; |
| 153 | import org.apache.asterix.lang.sqlpp.clause.SelectClause; |
| 154 | import org.apache.asterix.lang.sqlpp.clause.SelectElement; |
| 155 | import org.apache.asterix.lang.sqlpp.clause.SelectRegular; |
| 156 | import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation; |
| 157 | import org.apache.asterix.lang.sqlpp.clause.UnnestClause; |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 158 | import org.apache.asterix.lang.sqlpp.expression.CaseExpression; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 159 | import org.apache.asterix.lang.sqlpp.expression.SelectExpression; |
| 160 | import org.apache.asterix.lang.sqlpp.optype.JoinType; |
| 161 | import org.apache.asterix.lang.sqlpp.optype.SetOpType; |
| 162 | import org.apache.asterix.lang.sqlpp.struct.SetOperationInput; |
| 163 | import org.apache.asterix.lang.sqlpp.struct.SetOperationRight; |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 164 | import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil; |
Xikui Wang | 96fd402 | 2017-04-10 14:23:31 -0700 | [diff] [blame] | 165 | import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil; |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 166 | import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 167 | import org.apache.hyracks.algebricks.common.utils.Pair; |
| 168 | import org.apache.hyracks.algebricks.common.utils.Triple; |
| 169 | import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 170 | import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
| 171 | import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; |
| 172 | |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 173 | class SQLPPParser extends ScopeChecker implements IParser { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 174 | |
| 175 | // optimizer hints |
| 176 | private static final String AUTO_HINT = "auto"; |
| 177 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 178 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 179 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 180 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 181 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 182 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 183 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
| 184 | private static final String INMEMORY_HINT = "inmem"; |
| 185 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 186 | private static final String INTERVAL_HINT = "interval"; |
| 187 | private static final String LIST_HINT = "list"; |
| 188 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 189 | private static final String RANGE_HINT = "range"; |
| 190 | private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index"; |
| 191 | private static final String VAL_FILE_HINT = "val-files"; |
| 192 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 193 | |
| 194 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 195 | |
| 196 | // data generator hints |
| 197 | private static final String DGEN_HINT = "dgen"; |
| 198 | |
Till Westmann | 7199a56 | 2016-09-17 16:07:32 -0700 | [diff] [blame] | 199 | // error configuration |
| 200 | protected static final boolean REPORT_EXPECTED_TOKENS = false; |
| 201 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 202 | private static class IndexParams { |
| 203 | public IndexType type; |
| 204 | public int gramLength; |
| 205 | |
| 206 | public IndexParams(IndexType type, int gramLength) { |
| 207 | this.type = type; |
| 208 | this.gramLength = gramLength; |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | private static class FunctionName { |
| 213 | public String dataverse = null; |
| 214 | public String library = null; |
| 215 | public String function = null; |
| 216 | public String hint = null; |
| 217 | } |
| 218 | |
| 219 | private static String getHint(Token t) { |
| 220 | if (t.specialToken == null) { |
| 221 | return null; |
| 222 | } |
| 223 | String s = t.specialToken.image; |
| 224 | int n = s.length(); |
| 225 | if (n < 2) { |
| 226 | return null; |
| 227 | } |
| 228 | return s.substring(1).trim(); |
| 229 | } |
| 230 | |
| 231 | private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException { |
| 232 | IRecordFieldDataGen rfdg = null; |
| 233 | String splits[] = hint.split(" +"); |
| 234 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 235 | File[] valFiles = new File[splits.length - 1]; |
| 236 | for (int k=1; k<splits.length; k++) { |
| 237 | valFiles[k-1] = new File(splits[k]); |
| 238 | } |
| 239 | rfdg = new FieldValFileDataGen(valFiles); |
| 240 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 241 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 242 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 243 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 244 | } else if (splits[0].equals(LIST_HINT)) { |
| 245 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 246 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 247 | FieldIntervalDataGen.ValueType vt; |
| 248 | if (splits[1].equals("int")) { |
| 249 | vt = FieldIntervalDataGen.ValueType.INT; |
| 250 | } else if (splits[1].equals("long")) { |
| 251 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 252 | } else if (splits[1].equals("float")) { |
| 253 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 254 | } else if (splits[1].equals("double")) { |
| 255 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 256 | } else { |
| 257 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 258 | } |
| 259 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 260 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 261 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 262 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 263 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 264 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 265 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 266 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 267 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 268 | } else if (splits[0].equals(AUTO_HINT)) { |
| 269 | rfdg = new AutoDataGen(splits[1]); |
| 270 | } |
| 271 | return rfdg; |
| 272 | } |
| 273 | |
Till Westmann | 7199a56 | 2016-09-17 16:07:32 -0700 | [diff] [blame] | 274 | public SQLPPParser(String s) { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 275 | this(new StringReader(s)); |
| 276 | super.setInput(s); |
| 277 | } |
| 278 | |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 279 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 280 | File file = new File(args[0]); |
| 281 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 282 | SQLPPParser parser = new SQLPPParser(fis); |
| 283 | List<Statement> st = parser.parse(); |
| 284 | //st.accept(new SQLPPPrintVisitor(), 0); |
| 285 | } |
| 286 | |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 287 | public List<Statement> parse() throws CompilationException { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 288 | try { |
| 289 | return Statement(); |
| 290 | } catch (Error e) { |
| 291 | // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled |
| 292 | // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes) |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 293 | throw new CompilationException(new ParseException(e.getMessage())); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 294 | } catch (ParseException e) { |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 295 | throw new CompilationException("Syntax error: " + getMessage(e)); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
Till Westmann | 7199a56 | 2016-09-17 16:07:32 -0700 | [diff] [blame] | 298 | |
| 299 | protected String getMessage(ParseException pe) { |
| 300 | Token currentToken = pe.currentToken; |
| 301 | if (currentToken == null) { |
| 302 | return pe.getMessage(); |
| 303 | } |
| 304 | int[][] expectedTokenSequences = pe.expectedTokenSequences; |
| 305 | String[] tokenImage = pe.tokenImage; |
| 306 | String sep = REPORT_EXPECTED_TOKENS ? eol : " "; |
| 307 | StringBuilder expected = REPORT_EXPECTED_TOKENS ? new StringBuilder() : null; |
| 308 | int maxSize = appendExpected(expected, expectedTokenSequences, tokenImage); |
| 309 | Token tok = currentToken.next; |
| 310 | int line = tok.beginLine; |
| 311 | String message = "In line " + line + " >>" + getLine(line) + "<<" + sep + "Encountered "; |
| 312 | for (int i = 0; i < maxSize; i++) { |
| 313 | if (i != 0) { |
| 314 | message += " "; |
| 315 | } |
| 316 | if (tok.kind == 0) { |
| 317 | message += fixQuotes(tokenImage[0]); |
| 318 | break; |
| 319 | } |
Till Westmann | e3c9f27 | 2016-10-09 11:09:26 -0700 | [diff] [blame] | 320 | final String fixedTokenImage = tokenImage[tok.kind]; |
| 321 | if (! tok.image.equalsIgnoreCase(stripQuotes(fixedTokenImage))) { |
| 322 | message += fixQuotes(fixedTokenImage) + " "; |
| 323 | } |
Till Westmann | 7199a56 | 2016-09-17 16:07:32 -0700 | [diff] [blame] | 324 | message += quot + addEscapes(tok.image) + quot; |
| 325 | tok = tok.next; |
| 326 | } |
| 327 | message += " at column " + currentToken.next.beginColumn + "." + sep; |
| 328 | if (REPORT_EXPECTED_TOKENS) { |
| 329 | if (expectedTokenSequences.length == 1) { |
| 330 | message += "Was expecting:" + sep + " "; |
| 331 | } else { |
| 332 | message += "Was expecting one of:" + sep + " "; |
| 333 | } |
| 334 | message += expected.toString(); |
| 335 | } |
| 336 | return message; |
| 337 | } |
| 338 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | PARSER_END(SQLPPParser) |
| 342 | |
| 343 | |
| 344 | List<Statement> Statement() throws ParseException: |
| 345 | { |
| 346 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 347 | List<Statement> decls = new ArrayList<Statement>(); |
| 348 | Statement stmt = null; |
| 349 | } |
| 350 | { |
| 351 | ( stmt = SingleStatement() (<SEMICOLON>)* |
| 352 | { |
| 353 | decls.add(stmt); |
| 354 | } |
| 355 | )* |
Till Westmann | 81870d7 | 2017-03-16 18:11:23 -0700 | [diff] [blame] | 356 | (<SEMICOLON>)* |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 357 | <EOF> |
| 358 | { |
| 359 | return decls; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | Statement SingleStatement() throws ParseException: |
| 364 | { |
| 365 | Statement stmt = null; |
| 366 | } |
| 367 | { |
| 368 | ( |
| 369 | stmt = DataverseDeclaration() |
| 370 | | stmt = FunctionDeclaration() |
| 371 | | stmt = CreateStatement() |
| 372 | | stmt = LoadStatement() |
| 373 | | stmt = DropStatement() |
| 374 | | stmt = WriteStatement() |
| 375 | | stmt = SetStatement() |
| 376 | | stmt = InsertStatement() |
| 377 | | stmt = DeleteStatement() |
| 378 | | stmt = UpdateStatement() |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 379 | | stmt = UpsertStatement() |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 380 | | stmt = ConnectionStatement() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 381 | | stmt = CompactStatement() |
Till Westmann | ef3f027 | 2016-07-27 18:34:01 -0700 | [diff] [blame] | 382 | | stmt = ExplainStatement() |
| 383 | | stmt = Query(false) <SEMICOLON> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 384 | | stmt = RefreshExternalDatasetStatement() |
| 385 | | stmt = RunStatement() |
| 386 | ) |
| 387 | { |
| 388 | return stmt; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 393 | { |
| 394 | String dvName = null; |
| 395 | } |
| 396 | { |
| 397 | <USE> dvName = Identifier() |
| 398 | { |
| 399 | defaultDataverse = dvName; |
| 400 | return new DataverseDecl(new Identifier(dvName)); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | Statement CreateStatement() throws ParseException: |
| 405 | { |
| 406 | String hint = null; |
| 407 | boolean dgen = false; |
| 408 | Statement stmt = null; |
| 409 | } |
| 410 | { |
| 411 | <CREATE> |
| 412 | ( |
| 413 | { |
| 414 | hint = getHint(token); |
| 415 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 416 | dgen = true; |
| 417 | } |
| 418 | } |
| 419 | stmt = TypeSpecification(hint, dgen) |
| 420 | | stmt = NodegroupSpecification() |
| 421 | | stmt = DatasetSpecification() |
| 422 | | stmt = IndexSpecification() |
| 423 | | stmt = DataverseSpecification() |
| 424 | | stmt = FunctionSpecification() |
| 425 | | stmt = FeedSpecification() |
| 426 | | stmt = FeedPolicySpecification() |
| 427 | ) |
| 428 | { |
| 429 | return stmt; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException: |
| 434 | { |
| 435 | Pair<Identifier,Identifier> nameComponents = null; |
| 436 | boolean ifNotExists = false; |
| 437 | TypeExpression typeExpr = null; |
| 438 | } |
| 439 | { |
| 440 | <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists() |
Till Westmann | f602827 | 2016-09-30 14:34:42 -0700 | [diff] [blame] | 441 | <AS> typeExpr = RecordTypeDef() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 442 | { |
| 443 | long numValues = -1; |
| 444 | String filename = null; |
| 445 | if (dgen) { |
| 446 | String splits[] = hint.split(" +"); |
| 447 | if (splits.length != 3) { |
| 448 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 449 | } |
| 450 | filename = splits[1]; |
| 451 | numValues = Long.parseLong(splits[2]); |
| 452 | } |
| 453 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 454 | return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
| 459 | NodegroupDecl NodegroupSpecification() throws ParseException: |
| 460 | { |
| 461 | String name = null; |
| 462 | String tmp = null; |
| 463 | boolean ifNotExists = false; |
| 464 | List<Identifier>ncNames = null; |
| 465 | } |
| 466 | { |
| 467 | <NODEGROUP> name = Identifier() |
| 468 | ifNotExists = IfNotExists() <ON> tmp = Identifier() |
| 469 | { |
| 470 | ncNames = new ArrayList<Identifier>(); |
| 471 | ncNames.add(new Identifier(tmp)); |
| 472 | } |
| 473 | ( <COMMA> tmp = Identifier() |
| 474 | { |
| 475 | ncNames.add(new Identifier(tmp)); |
| 476 | } |
| 477 | )* |
| 478 | { |
| 479 | return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | DatasetDecl DatasetSpecification() throws ParseException: |
| 484 | { |
| 485 | Pair<Identifier,Identifier> nameComponents = null; |
| 486 | boolean ifNotExists = false; |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 487 | Pair<Identifier,Identifier> typeComponents = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 488 | String adapterName = null; |
| 489 | Map<String,String> properties = null; |
| 490 | Map<String,String> compactionPolicyProperties = null; |
| 491 | FunctionSignature appliedFunction = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 492 | Pair<List<Integer>, List<List<String>>> primaryKeyFields = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 493 | String nodeGroupName = null; |
| 494 | Map<String,String> hints = new HashMap<String,String>(); |
| 495 | DatasetDecl dsetDecl = null; |
| 496 | boolean autogenerated = false; |
| 497 | String compactionPolicy = null; |
| 498 | boolean temp = false; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 499 | Pair<Integer, List<String>> filterField = null; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 500 | Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 501 | } |
| 502 | { |
| 503 | ( |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 504 | <EXTERNAL> Dataset() nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 505 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 506 | ifNotExists = IfNotExists() |
| 507 | <USING> adapterName = AdapterName() properties = Configuration() |
| 508 | (<ON> nodeGroupName = Identifier() )? |
| 509 | ( <HINTS> hints = Properties() )? |
| 510 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )? |
| 511 | { |
| 512 | ExternalDetailsDecl edd = new ExternalDetailsDecl(); |
| 513 | edd.setAdapter(adapterName); |
| 514 | edd.setProperties(properties); |
| 515 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 516 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 517 | typeComponents.first, |
| 518 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 519 | metaTypeComponents.first, |
| 520 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 521 | nodeGroupName != null? new Identifier(nodeGroupName): null, |
| 522 | compactionPolicy, |
| 523 | compactionPolicyProperties, |
| 524 | hints, |
| 525 | DatasetType.EXTERNAL, |
| 526 | edd, |
| 527 | ifNotExists); |
| 528 | } |
| 529 | |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 530 | | (<INTERNAL> | <TEMPORARY> { temp = true; })? |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 531 | Dataset() nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 532 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 533 | ( |
| 534 | { String name; } |
| 535 | <WITH> |
| 536 | name = Identifier() |
| 537 | { |
| 538 | if(!name.toLowerCase().equals("meta")){ |
| 539 | throw new ParseException("We can only support one additional associated field called \"meta\"."); |
| 540 | } |
| 541 | } |
| 542 | <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN> |
| 543 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 544 | ifNotExists = IfNotExists() |
| 545 | primaryKeyFields = PrimaryKey() |
| 546 | (<AUTOGENERATED> { autogenerated = true; } )? |
| 547 | (<ON> nodeGroupName = Identifier() )? |
| 548 | ( <HINTS> hints = Properties() )? |
| 549 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )? |
| 550 | ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )? |
| 551 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 552 | if(filterField!=null && filterField.first!=0){ |
| 553 | throw new ParseException("A filter field can only be a field in the main record of the dataset."); |
| 554 | } |
| 555 | InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, |
| 556 | primaryKeyFields.first, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 557 | autogenerated, |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 558 | filterField == null? null : filterField.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 559 | temp); |
| 560 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 561 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 562 | typeComponents.first, |
| 563 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 564 | metaTypeComponents.first, |
| 565 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 566 | nodeGroupName != null ? new Identifier(nodeGroupName) : null, |
| 567 | compactionPolicy, |
| 568 | compactionPolicyProperties, |
| 569 | hints, |
| 570 | DatasetType.INTERNAL, |
| 571 | idd, |
| 572 | ifNotExists); |
| 573 | } |
| 574 | ) |
| 575 | { |
| 576 | return dsetDecl; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException: |
| 581 | { |
| 582 | RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement(); |
| 583 | Pair<Identifier,Identifier> nameComponents = null; |
| 584 | String datasetName = null; |
| 585 | } |
| 586 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 587 | <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 588 | { |
| 589 | redss.setDataverseName(nameComponents.first); |
| 590 | redss.setDatasetName(nameComponents.second); |
| 591 | return redss; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | RunStatement RunStatement() throws ParseException: |
| 596 | { |
| 597 | String system = null; |
| 598 | String tmp; |
| 599 | ArrayList<String> parameters = new ArrayList<String>(); |
| 600 | Pair<Identifier,Identifier> nameComponentsFrom = null; |
| 601 | Pair<Identifier,Identifier> nameComponentsTo = null; |
| 602 | } |
| 603 | { |
| 604 | <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>] |
| 605 | { |
| 606 | parameters.add(tmp); |
| 607 | } |
| 608 | )*<RIGHTPAREN> |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 609 | <FROM> Dataset() nameComponentsFrom = QualifiedName() |
| 610 | <TO> Dataset() nameComponentsTo = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 611 | { |
| 612 | return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | CreateIndexStatement IndexSpecification() throws ParseException: |
| 617 | { |
| 618 | CreateIndexStatement cis = new CreateIndexStatement(); |
| 619 | String indexName = null; |
| 620 | boolean ifNotExists = false; |
| 621 | Pair<Identifier,Identifier> nameComponents = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 622 | Pair<Integer, Pair<List<String>, TypeExpression>> fieldPair = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 623 | IndexParams indexType = null; |
| 624 | boolean enforced = false; |
| 625 | } |
| 626 | { |
| 627 | <INDEX> indexName = Identifier() |
| 628 | ifNotExists = IfNotExists() |
| 629 | <ON> nameComponents = QualifiedName() |
| 630 | <LEFTPAREN> ( fieldPair = OpenField() |
| 631 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 632 | cis.addFieldExprPair(fieldPair.second); |
| 633 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 634 | } |
| 635 | ) (<COMMA> fieldPair = OpenField() |
| 636 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 637 | cis.addFieldExprPair(fieldPair.second); |
| 638 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 639 | } |
| 640 | )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )? |
| 641 | { |
| 642 | cis.setIndexName(new Identifier(indexName)); |
| 643 | cis.setIfNotExists(ifNotExists); |
| 644 | cis.setDataverseName(nameComponents.first); |
| 645 | cis.setDatasetName(nameComponents.second); |
| 646 | if (indexType != null) { |
| 647 | cis.setIndexType(indexType.type); |
| 648 | cis.setGramLength(indexType.gramLength); |
| 649 | } |
| 650 | cis.setEnforced(enforced); |
| 651 | return cis; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | String CompactionPolicy() throws ParseException : |
| 656 | { |
| 657 | String compactionPolicy = null; |
| 658 | } |
| 659 | { |
| 660 | compactionPolicy = Identifier() |
| 661 | { |
| 662 | return compactionPolicy; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | String FilterField() throws ParseException : |
| 667 | { |
| 668 | String filterField = null; |
| 669 | } |
| 670 | { |
| 671 | filterField = Identifier() |
| 672 | { |
| 673 | return filterField; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | IndexParams IndexType() throws ParseException: |
| 678 | { |
| 679 | IndexType type = null; |
| 680 | int gramLength = 0; |
| 681 | } |
| 682 | { |
| 683 | (<BTREE> |
| 684 | { |
| 685 | type = IndexType.BTREE; |
| 686 | } |
| 687 | | <RTREE> |
| 688 | { |
| 689 | type = IndexType.RTREE; |
| 690 | } |
| 691 | | <KEYWORD> |
| 692 | { |
| 693 | type = IndexType.LENGTH_PARTITIONED_WORD_INVIX; |
| 694 | } |
Taewoo Kim | c49405a | 2017-01-04 00:30:43 -0800 | [diff] [blame] | 695 | |<FULLTEXT> |
| 696 | { |
| 697 | type = IndexType.SINGLE_PARTITION_WORD_INVIX; |
| 698 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 699 | | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL> |
| 700 | { |
| 701 | type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX; |
| 702 | gramLength = Integer.valueOf(token.image); |
| 703 | } |
| 704 | <RIGHTPAREN>) |
| 705 | { |
| 706 | return new IndexParams(type, gramLength); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | CreateDataverseStatement DataverseSpecification() throws ParseException : |
| 711 | { |
| 712 | String dvName = null; |
| 713 | boolean ifNotExists = false; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 714 | } |
| 715 | { |
| 716 | <DATAVERSE> dvName = Identifier() |
| 717 | ifNotExists = IfNotExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 718 | { |
Till Westmann | f602827 | 2016-09-30 14:34:42 -0700 | [diff] [blame] | 719 | return new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | CreateFunctionStatement FunctionSpecification() throws ParseException: |
| 724 | { |
| 725 | FunctionSignature signature; |
| 726 | boolean ifNotExists = false; |
| 727 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 728 | String functionBody; |
| 729 | VarIdentifier var = null; |
| 730 | Expression functionBodyExpr; |
| 731 | Token beginPos; |
| 732 | Token endPos; |
| 733 | FunctionName fctName = null; |
| 734 | |
| 735 | createNewScope(); |
| 736 | } |
| 737 | { |
| 738 | <FUNCTION> fctName = FunctionName() |
| 739 | ifNotExists = IfNotExists() |
| 740 | paramList = ParameterList() |
| 741 | <LEFTBRACE> |
| 742 | { |
| 743 | beginPos = token; |
| 744 | } |
| 745 | functionBodyExpr = Expression() <RIGHTBRACE> |
| 746 | { |
| 747 | endPos = token; |
| 748 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 749 | // TODO use fctName.library |
| 750 | signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); |
| 751 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 752 | removeCurrentScope(); |
| 753 | return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | CreateFeedStatement FeedSpecification() throws ParseException: |
| 758 | { |
| 759 | Pair<Identifier,Identifier> nameComponents = null; |
| 760 | boolean ifNotExists = false; |
| 761 | String adapterName = null; |
| 762 | Map<String,String> properties = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 763 | CreateFeedStatement cfs = null; |
| 764 | Pair<Identifier,Identifier> sourceNameComponents = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 765 | } |
| 766 | { |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 767 | <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists() |
| 768 | <USING> adapterName = AdapterName() properties = Configuration() |
| 769 | { |
| 770 | cfs = new CreateFeedStatement(nameComponents, adapterName, properties, ifNotExists); |
| 771 | return cfs; |
| 772 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException: |
| 776 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 777 | String policyName = null; |
| 778 | String basePolicyName = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 779 | String sourcePolicyFile = null; |
| 780 | String definition = null; |
| 781 | boolean ifNotExists = false; |
| 782 | Map<String,String> properties = null; |
| 783 | CreateFeedPolicyStatement cfps = null; |
| 784 | } |
| 785 | { |
| 786 | ( |
| 787 | <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists() |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 788 | <FROM> |
| 789 | (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 790 | { |
| 791 | cfps = new CreateFeedPolicyStatement(policyName, |
| 792 | basePolicyName, properties, definition, ifNotExists); |
| 793 | } |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 794 | | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 795 | { |
| 796 | cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists); |
| 797 | } |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 798 | ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 799 | ) |
| 800 | { |
| 801 | return cfps; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | |
| 806 | |
| 807 | List<VarIdentifier> ParameterList() throws ParseException: |
| 808 | { |
| 809 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 810 | VarIdentifier var = null; |
| 811 | } |
| 812 | { |
| 813 | <LEFTPAREN> (<IDENTIFIER> |
| 814 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 815 | var = SqlppVariableUtil.toInternalVariableIdentifier(token.image); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 816 | paramList.add(var); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 817 | } |
| 818 | (<COMMA> <IDENTIFIER> |
| 819 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 820 | var = SqlppVariableUtil.toInternalVariableIdentifier(token.image); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 821 | paramList.add(var); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 822 | } |
| 823 | )*)? <RIGHTPAREN> |
| 824 | { |
| 825 | return paramList; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | boolean IfNotExists() throws ParseException: |
| 830 | { |
| 831 | } |
| 832 | { |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 833 | ( LOOKAHEAD(1) <IF> <NOT> <EXISTS> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 834 | { |
| 835 | return true; |
| 836 | } |
| 837 | )? |
| 838 | { |
| 839 | return false; |
| 840 | } |
| 841 | } |
| 842 | |
Xikui Wang | 9d63f62 | 2017-05-18 17:50:44 -0700 | [diff] [blame^] | 843 | void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 844 | { |
| 845 | FunctionName functioName = null; |
Xikui Wang | 261dc6d | 2017-03-29 21:23:15 -0700 | [diff] [blame] | 846 | String fqFunctionName = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 847 | } |
| 848 | { |
| 849 | <APPLY> <FUNCTION> functioName = FunctionName() |
| 850 | { |
Xikui Wang | 261dc6d | 2017-03-29 21:23:15 -0700 | [diff] [blame] | 851 | fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function; |
| 852 | funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1)); |
| 853 | } |
| 854 | ( |
| 855 | <COMMA> functioName = FunctionName() |
| 856 | { |
| 857 | fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function; |
| 858 | funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1)); |
| 859 | } |
| 860 | )* |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | String GetPolicy() throws ParseException: |
| 864 | { |
| 865 | String policy = null; |
| 866 | } |
| 867 | { |
| 868 | <USING> <POLICY> policy = Identifier() |
| 869 | { |
| 870 | return policy; |
| 871 | } |
| 872 | |
| 873 | } |
| 874 | |
| 875 | FunctionSignature FunctionSignature() throws ParseException: |
| 876 | { |
| 877 | FunctionName fctName = null; |
| 878 | int arity = 0; |
| 879 | } |
| 880 | { |
| 881 | fctName = FunctionName() <ATT> <INTEGER_LITERAL> |
| 882 | { |
| 883 | arity = new Integer(token.image); |
| 884 | if (arity < 0 && arity != FunctionIdentifier.VARARGS) { |
| 885 | throw new ParseException(" invalid arity:" + arity); |
| 886 | } |
| 887 | |
| 888 | // TODO use fctName.library |
| 889 | String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function; |
| 890 | return new FunctionSignature(fctName.dataverse, fqFunctionName, arity); |
| 891 | } |
| 892 | } |
| 893 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 894 | Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 895 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 896 | Pair<Integer, List<String>> tmp = null; |
| 897 | List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 898 | List<List<String>> primaryKeyFields = new ArrayList<List<String>>(); |
| 899 | } |
| 900 | { |
| 901 | <PRIMARY> <KEY> tmp = NestedField() |
| 902 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 903 | keyFieldSourceIndicators.add(tmp.first); |
| 904 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 905 | } |
| 906 | ( <COMMA> tmp = NestedField() |
| 907 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 908 | keyFieldSourceIndicators.add(tmp.first); |
| 909 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 910 | } |
| 911 | )* |
| 912 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 913 | return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
| 917 | Statement DropStatement() throws ParseException: |
| 918 | { |
| 919 | String id = null; |
| 920 | Pair<Identifier,Identifier> pairId = null; |
| 921 | Triple<Identifier,Identifier,Identifier> tripleId = null; |
| 922 | FunctionSignature funcSig = null; |
| 923 | boolean ifExists = false; |
| 924 | Statement stmt = null; |
| 925 | } |
| 926 | { |
| 927 | <DROP> |
| 928 | ( |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 929 | Dataset() pairId = QualifiedName() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 930 | { |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 931 | stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 932 | } |
| 933 | | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists() |
| 934 | { |
| 935 | stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); |
| 936 | } |
| 937 | | <NODEGROUP> id = Identifier() ifExists = IfExists() |
| 938 | { |
| 939 | stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); |
| 940 | } |
| 941 | | <TYPE> pairId = TypeName() ifExists = IfExists() |
| 942 | { |
| 943 | stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); |
| 944 | } |
| 945 | | <DATAVERSE> id = Identifier() ifExists = IfExists() |
| 946 | { |
| 947 | stmt = new DataverseDropStatement(new Identifier(id), ifExists); |
| 948 | } |
| 949 | | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists() |
| 950 | { |
| 951 | stmt = new FunctionDropStatement(funcSig, ifExists); |
| 952 | } |
| 953 | | <FEED> pairId = QualifiedName() ifExists = IfExists() |
| 954 | { |
| 955 | stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists); |
| 956 | } |
Abdullah Alamoudi | 5dc73ed | 2016-07-28 05:03:13 +0300 | [diff] [blame] | 957 | | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists() |
| 958 | { |
| 959 | stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists); |
| 960 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 961 | ) |
| 962 | { |
| 963 | return stmt; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | boolean IfExists() throws ParseException : |
| 968 | { |
| 969 | } |
| 970 | { |
| 971 | ( LOOKAHEAD(1) <IF> <EXISTS> |
| 972 | { |
| 973 | return true; |
| 974 | } |
| 975 | )? |
| 976 | { |
| 977 | return false; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | InsertStatement InsertStatement() throws ParseException: |
| 982 | { |
| 983 | Pair<Identifier,Identifier> nameComponents = null; |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 984 | VariableExpr var = null; |
| 985 | Query query = null; |
| 986 | Expression returnExpression = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 987 | } |
| 988 | { |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 989 | <INSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())? |
| 990 | query = Query(false) |
| 991 | ( <RETURNING> returnExpression = Expression())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 992 | { |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 993 | if (returnExpression != null && var == null) { |
| 994 | var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true); |
| 995 | } |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 996 | query.setTopLevel(true); |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 997 | return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var, |
| 998 | returnExpression); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | UpsertStatement UpsertStatement() throws ParseException: |
| 1003 | { |
| 1004 | Pair<Identifier,Identifier> nameComponents = null; |
| 1005 | VariableExpr var = null; |
| 1006 | Query query = null; |
| 1007 | Expression returnExpression = null; |
| 1008 | } |
| 1009 | { |
| 1010 | <UPSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())? |
| 1011 | query = Query(false) |
| 1012 | ( <RETURNING> returnExpression = Expression())? |
| 1013 | { |
| 1014 | if (returnExpression != null && var == null) { |
| 1015 | var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true); |
| 1016 | } |
| 1017 | query.setTopLevel(true); |
| 1018 | return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var, |
| 1019 | returnExpression); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | DeleteStatement DeleteStatement() throws ParseException: |
| 1024 | { |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1025 | VariableExpr varExpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1026 | Expression condition = null; |
| 1027 | Pair<Identifier, Identifier> nameComponents; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1028 | } |
| 1029 | { |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1030 | <DELETE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1031 | <FROM> nameComponents = QualifiedName() |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1032 | ((<AS>)? varExpr = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1033 | (<WHERE> condition = Expression())? |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1034 | { |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1035 | if(varExpr == null){ |
| 1036 | varExpr = new VariableExpr(); |
| 1037 | VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue()); |
| 1038 | varExpr.setVar(var); |
| 1039 | } |
| 1040 | return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second, |
Abdullah Alamoudi | 6eb0175 | 2017-04-01 21:51:19 -0700 | [diff] [blame] | 1041 | condition, getVarCounter()); |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 1042 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | UpdateStatement UpdateStatement() throws ParseException: |
| 1046 | { |
| 1047 | VariableExpr vars; |
| 1048 | Expression target; |
| 1049 | Expression condition; |
| 1050 | UpdateClause uc; |
| 1051 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 1052 | } |
| 1053 | { |
| 1054 | <UPDATE> vars = Variable() <IN> target = Expression() |
| 1055 | <WHERE> condition = Expression() |
| 1056 | <LEFTPAREN> (uc = UpdateClause() |
| 1057 | { |
| 1058 | ucs.add(uc); |
| 1059 | } |
| 1060 | (<COMMA> uc = UpdateClause() |
| 1061 | { |
| 1062 | ucs.add(uc); |
| 1063 | } |
| 1064 | )*) <RIGHTPAREN> |
| 1065 | { |
| 1066 | return new UpdateStatement(vars, target, condition, ucs); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | UpdateClause UpdateClause() throws ParseException: |
| 1071 | { |
| 1072 | Expression target = null; |
| 1073 | Expression value = null ; |
| 1074 | InsertStatement is = null; |
| 1075 | DeleteStatement ds = null; |
| 1076 | UpdateStatement us = null; |
| 1077 | Expression condition = null; |
| 1078 | UpdateClause ifbranch = null; |
| 1079 | UpdateClause elsebranch = null; |
| 1080 | } |
| 1081 | { |
| 1082 | (<SET> target = Expression() <EQ> value = Expression() |
| 1083 | | is = InsertStatement() |
| 1084 | | ds = DeleteStatement() |
| 1085 | | us = UpdateStatement() |
| 1086 | | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN> |
| 1087 | <THEN> ifbranch = UpdateClause() |
| 1088 | [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()] |
| 1089 | { |
| 1090 | return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch); |
| 1091 | } |
| 1092 | ) |
| 1093 | } |
| 1094 | |
| 1095 | Statement SetStatement() throws ParseException: |
| 1096 | { |
| 1097 | String pn = null; |
| 1098 | String pv = null; |
| 1099 | } |
| 1100 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1101 | <SET> pn = Identifier() pv = ConstantString() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1102 | { |
| 1103 | return new SetStatement(pn, pv); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | Statement WriteStatement() throws ParseException: |
| 1108 | { |
| 1109 | String nodeName = null; |
| 1110 | String fileName = null; |
| 1111 | Query query; |
| 1112 | String writerClass = null; |
| 1113 | Pair<Identifier,Identifier> nameComponents = null; |
| 1114 | } |
| 1115 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1116 | <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString() |
| 1117 | ( <USING> writerClass = ConstantString() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1118 | { |
| 1119 | return new WriteStatement(new Identifier(nodeName), fileName, writerClass); |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | LoadStatement LoadStatement() throws ParseException: |
| 1124 | { |
| 1125 | Identifier dataverseName = null; |
| 1126 | Identifier datasetName = null; |
| 1127 | boolean alreadySorted = false; |
| 1128 | String adapterName; |
| 1129 | Map<String,String> properties; |
| 1130 | Pair<Identifier,Identifier> nameComponents = null; |
| 1131 | } |
| 1132 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1133 | <LOAD> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1134 | { |
| 1135 | dataverseName = nameComponents.first; |
| 1136 | datasetName = nameComponents.second; |
| 1137 | } |
| 1138 | <USING> adapterName = AdapterName() properties = Configuration() |
| 1139 | (<PRESORTED> |
| 1140 | { |
| 1141 | alreadySorted = true; |
| 1142 | } |
| 1143 | )? |
| 1144 | { |
| 1145 | return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | String AdapterName() throws ParseException : |
| 1151 | { |
| 1152 | String adapterName = null; |
| 1153 | } |
| 1154 | { |
| 1155 | adapterName = Identifier() |
| 1156 | { |
| 1157 | return adapterName; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | Statement CompactStatement() throws ParseException: |
| 1162 | { |
| 1163 | Pair<Identifier,Identifier> nameComponents = null; |
| 1164 | Statement stmt = null; |
| 1165 | } |
| 1166 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1167 | <COMPACT> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1168 | { |
| 1169 | stmt = new CompactStatement(nameComponents.first, nameComponents.second); |
| 1170 | } |
| 1171 | { |
| 1172 | return stmt; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1176 | Statement ConnectionStatement() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1177 | { |
| 1178 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1179 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 1180 | |
| 1181 | Map<String,String> configuration = null; |
| 1182 | Statement stmt = null; |
| 1183 | String policy = null; |
| 1184 | } |
| 1185 | { |
| 1186 | ( |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1187 | <CONNECT> stmt = ConnectStatement() |
| 1188 | | <DISCONNECT> stmt = DisconnectStatement() |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1189 | | <START> stmt = StartStatement() |
| 1190 | | <STOP> stmt = StopStatement() |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1191 | ) |
| 1192 | { |
| 1193 | return stmt; |
| 1194 | } |
| 1195 | } |
| 1196 | |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1197 | Statement StartStatement() throws ParseException: |
| 1198 | { |
| 1199 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1200 | |
| 1201 | Statement stmt = null; |
| 1202 | } |
| 1203 | { |
| 1204 | <FEED> feedNameComponents = QualifiedName() |
| 1205 | { |
| 1206 | stmt = new StartFeedStatement (feedNameComponents); |
| 1207 | return stmt; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | Statement StopStatement () throws ParseException: |
| 1212 | { |
| 1213 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1214 | |
| 1215 | Statement stmt = null; |
| 1216 | } |
| 1217 | { |
| 1218 | <FEED> feedNameComponents = QualifiedName() |
| 1219 | { |
| 1220 | stmt = new StopFeedStatement (feedNameComponents); |
| 1221 | return stmt; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1226 | Statement DisconnectStatement() throws ParseException: |
| 1227 | { |
| 1228 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1229 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 1230 | |
| 1231 | Map<String,String> configuration = null; |
| 1232 | Statement stmt = null; |
| 1233 | String policy = null; |
| 1234 | } |
| 1235 | { |
| 1236 | ( |
| 1237 | <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1238 | { |
| 1239 | stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents); |
| 1240 | } |
| 1241 | ) |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1242 | { |
| 1243 | return stmt; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | Statement ConnectStatement() throws ParseException: |
| 1248 | { |
| 1249 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1250 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 1251 | |
| 1252 | Map<String,String> configuration = null; |
Xikui Wang | 9d63f62 | 2017-05-18 17:50:44 -0700 | [diff] [blame^] | 1253 | List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>(); |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1254 | Statement stmt = null; |
| 1255 | String policy = null; |
| 1256 | } |
| 1257 | { |
| 1258 | ( |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1259 | <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName() |
Xikui Wang | 9d63f62 | 2017-05-18 17:50:44 -0700 | [diff] [blame^] | 1260 | (ApplyFunction(appliedFunctions))? (policy = GetPolicy())? |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1261 | { |
Xikui Wang | 261dc6d | 2017-03-29 21:23:15 -0700 | [diff] [blame] | 1262 | stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions, |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 1263 | policy, getVarCounter()); |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 1264 | } |
| 1265 | ) |
| 1266 | { |
| 1267 | return stmt; |
| 1268 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | Map<String,String> Configuration() throws ParseException : |
| 1272 | { |
| 1273 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
| 1274 | Pair<String, String> keyValuePair = null; |
| 1275 | } |
| 1276 | { |
| 1277 | <LEFTPAREN> ( keyValuePair = KeyValuePair() |
| 1278 | { |
| 1279 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1280 | } |
| 1281 | ( <COMMA> keyValuePair = KeyValuePair() |
| 1282 | { |
| 1283 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1284 | } |
| 1285 | )* )? <RIGHTPAREN> |
| 1286 | { |
| 1287 | return configuration; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | Pair<String, String> KeyValuePair() throws ParseException: |
| 1292 | { |
| 1293 | String key; |
| 1294 | String value; |
| 1295 | } |
| 1296 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1297 | <LEFTPAREN> key = ConstantString() <EQ> value = ConstantString() <RIGHTPAREN> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1298 | { |
| 1299 | return new Pair<String, String>(key, value); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | Map<String,String> Properties() throws ParseException: |
| 1304 | { |
| 1305 | Map<String,String> properties = new HashMap<String,String>(); |
| 1306 | Pair<String, String> property; |
| 1307 | } |
| 1308 | { |
| 1309 | (LOOKAHEAD(1) <LEFTPAREN> property = Property() |
| 1310 | { |
| 1311 | properties.put(property.first, property.second); |
| 1312 | } |
| 1313 | ( <COMMA> property = Property() |
| 1314 | { |
| 1315 | properties.put(property.first, property.second); |
| 1316 | } |
| 1317 | )* <RIGHTPAREN> )? |
| 1318 | { |
| 1319 | return properties; |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | Pair<String, String> Property() throws ParseException: |
| 1324 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1325 | String key = null; |
| 1326 | String value = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1327 | } |
| 1328 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1329 | (key = Identifier() | key = StringLiteral()) |
| 1330 | <EQ> |
| 1331 | ( value = ConstantString() | <INTEGER_LITERAL> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1332 | { |
| 1333 | try { |
| 1334 | value = "" + Long.valueOf(token.image); |
| 1335 | } catch (NumberFormatException nfe) { |
| 1336 | throw new ParseException("inapproriate value: " + token.image); |
| 1337 | } |
| 1338 | } |
| 1339 | ) |
| 1340 | { |
| 1341 | return new Pair<String, String>(key.toUpperCase(), value); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | TypeExpression IndexedTypeExpr() throws ParseException: |
| 1346 | { |
| 1347 | TypeExpression typeExpr = null; |
| 1348 | } |
| 1349 | { |
| 1350 | ( |
| 1351 | typeExpr = TypeReference() |
| 1352 | | typeExpr = OrderedListTypeDef() |
| 1353 | | typeExpr = UnorderedListTypeDef() |
| 1354 | ) |
| 1355 | { |
| 1356 | return typeExpr; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | TypeExpression TypeExpr() throws ParseException: |
| 1361 | { |
| 1362 | TypeExpression typeExpr = null; |
| 1363 | } |
| 1364 | { |
| 1365 | ( |
| 1366 | typeExpr = RecordTypeDef() |
| 1367 | | typeExpr = TypeReference() |
| 1368 | | typeExpr = OrderedListTypeDef() |
| 1369 | | typeExpr = UnorderedListTypeDef() |
| 1370 | ) |
| 1371 | { |
| 1372 | return typeExpr; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 1377 | { |
| 1378 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 1379 | RecordTypeDefinition.RecordKind recordKind = null; |
| 1380 | } |
| 1381 | { |
| 1382 | ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 1383 | | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 1384 | <LEFTBRACE> |
| 1385 | { |
| 1386 | String hint = getHint(token); |
| 1387 | if (hint != null) { |
| 1388 | String splits[] = hint.split(" +"); |
| 1389 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 1390 | if (splits.length != 5) { |
| 1391 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 1392 | } |
| 1393 | if (!splits[1].equals("int")) { |
| 1394 | throw new ParseException("The only supported type for gen-fields is int."); |
| 1395 | } |
| 1396 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 1397 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 1398 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | } |
| 1403 | ( |
| 1404 | RecordField(recType) |
| 1405 | ( <COMMA> RecordField(recType) )* |
| 1406 | )? |
| 1407 | <RIGHTBRACE> |
| 1408 | { |
| 1409 | if (recordKind == null) { |
| 1410 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 1411 | } |
| 1412 | recType.setRecordKind(recordKind); |
| 1413 | return recType; |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 1418 | { |
| 1419 | String fieldName; |
| 1420 | TypeExpression type = null; |
| 1421 | boolean nullable = false; |
| 1422 | } |
| 1423 | { |
| 1424 | fieldName = Identifier() |
| 1425 | { |
| 1426 | String hint = getHint(token); |
| 1427 | IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null; |
| 1428 | } |
| 1429 | <COLON> type = TypeExpr() (<QUES> { nullable = true; } )? |
| 1430 | { |
| 1431 | recType.addField(fieldName, type, nullable, rfdg); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | TypeReferenceExpression TypeReference() throws ParseException: |
| 1436 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1437 | Pair<Identifier,Identifier> id = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1438 | } |
| 1439 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1440 | id = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1441 | { |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1442 | if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) { |
| 1443 | id.second.setValue("int64"); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Abdullah Alamoudi | e4b318f | 2016-09-19 13:31:25 +0300 | [diff] [blame] | 1446 | return new TypeReferenceExpression(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1451 | { |
| 1452 | TypeExpression type = null; |
| 1453 | } |
| 1454 | { |
| 1455 | <LEFTBRACKET> |
| 1456 | ( type = TypeExpr() ) |
| 1457 | <RIGHTBRACKET> |
| 1458 | { |
| 1459 | return new OrderedListTypeDefinition(type); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1465 | { |
| 1466 | TypeExpression type = null; |
| 1467 | } |
| 1468 | { |
| 1469 | <LEFTDBLBRACE> |
| 1470 | ( type = TypeExpr() ) |
| 1471 | <RIGHTDBLBRACE> |
| 1472 | { |
| 1473 | return new UnorderedListTypeDefinition(type); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | FunctionName FunctionName() throws ParseException: |
| 1478 | { |
| 1479 | String first = null; |
| 1480 | String second = null; |
| 1481 | String third = null; |
| 1482 | boolean secondAfterDot = false; |
| 1483 | } |
| 1484 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1485 | first = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1486 | { |
| 1487 | FunctionName result = new FunctionName(); |
| 1488 | result.hint = getHint(token); |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1489 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1490 | ( <DOT> second = Identifier() |
| 1491 | { |
| 1492 | secondAfterDot = true; |
| 1493 | } |
| 1494 | (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )? |
| 1495 | { |
| 1496 | if (second == null) { |
| 1497 | result.dataverse = defaultDataverse; |
| 1498 | result.library = null; |
| 1499 | result.function = first; |
| 1500 | } else if (third == null) { |
| 1501 | if (secondAfterDot) { |
| 1502 | result.dataverse = first; |
| 1503 | result.library = null; |
| 1504 | result.function = second; |
| 1505 | } else { |
| 1506 | result.dataverse = defaultDataverse; |
| 1507 | result.library = first; |
| 1508 | result.function = second; |
| 1509 | } |
| 1510 | } else { |
| 1511 | result.dataverse = first; |
| 1512 | result.library = second; |
| 1513 | result.function = third; |
| 1514 | } |
| 1515 | |
| 1516 | if (result.function.equalsIgnoreCase("int")) { |
| 1517 | result.function = "int64"; |
| 1518 | } |
| 1519 | return result; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | Pair<Identifier,Identifier> TypeName() throws ParseException: |
| 1524 | { |
| 1525 | Pair<Identifier,Identifier> name = null; |
| 1526 | } |
| 1527 | { |
| 1528 | name = QualifiedName() |
| 1529 | { |
| 1530 | if (name.first == null) { |
| 1531 | name.first = new Identifier(defaultDataverse); |
| 1532 | } |
| 1533 | return name; |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | String Identifier() throws ParseException: |
| 1538 | { |
| 1539 | String lit = null; |
| 1540 | } |
| 1541 | { |
| 1542 | (<IDENTIFIER> |
| 1543 | { |
| 1544 | return token.image; |
| 1545 | } |
| 1546 | | lit = QuotedString() |
| 1547 | { |
| 1548 | return lit; |
| 1549 | } |
| 1550 | ) |
| 1551 | } |
| 1552 | |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1553 | void Dataset() throws ParseException: |
| 1554 | { |
| 1555 | } |
| 1556 | { |
| 1557 | (<DATASET>|<COLLECTION>) |
| 1558 | } |
| 1559 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1560 | Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1561 | { |
| 1562 | TypeExpression fieldType = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1563 | Pair<Integer, List<String>> fieldList = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1564 | } |
| 1565 | { |
| 1566 | fieldList = NestedField() |
Mike Carey | af8e19d | 2016-08-25 17:55:17 -0700 | [diff] [blame] | 1567 | ( <COLON> fieldType = IndexedTypeExpr() <QUES>)? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1568 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1569 | return new Pair<Integer, Pair<List<String>, TypeExpression>> |
| 1570 | (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType)); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1574 | Pair<Integer, List<String>> NestedField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1575 | { |
| 1576 | List<String> exprList = new ArrayList<String>(); |
| 1577 | String lit = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1578 | int source = 0; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1579 | } |
| 1580 | { |
| 1581 | lit = Identifier() |
| 1582 | { |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1583 | boolean meetParens = false; |
| 1584 | } |
| 1585 | ( |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1586 | LOOKAHEAD(1) |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1587 | <LEFTPAREN><RIGHTPAREN> |
| 1588 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1589 | if(!lit.toLowerCase().equals("meta")){ |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1590 | throw new ParseException("The string before () has to be \"meta\"."); |
| 1591 | } |
| 1592 | meetParens = true; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1593 | source = 1; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1594 | } |
| 1595 | )? |
| 1596 | { |
| 1597 | if(!meetParens){ |
| 1598 | exprList.add(lit); |
| 1599 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1600 | } |
| 1601 | (<DOT> |
| 1602 | lit = Identifier() |
| 1603 | { |
| 1604 | exprList.add(lit); |
| 1605 | } |
| 1606 | )* |
| 1607 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1608 | return new Pair<Integer, List<String>>(source, exprList); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1609 | } |
| 1610 | } |
| 1611 | |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1612 | String ConstantString() throws ParseException: |
| 1613 | { |
| 1614 | String value = null; |
| 1615 | } |
| 1616 | { |
| 1617 | (value = QuotedString() | value = StringLiteral()) |
| 1618 | { |
| 1619 | return value; |
| 1620 | } |
| 1621 | } |
| 1622 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1623 | |
| 1624 | String QuotedString() throws ParseException: |
| 1625 | { |
| 1626 | } |
| 1627 | { |
| 1628 | <QUOTED_STRING> |
| 1629 | { |
| 1630 | return removeQuotesAndEscapes(token.image); |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | |
| 1635 | String StringLiteral() throws ParseException: |
| 1636 | { |
| 1637 | } |
| 1638 | { |
| 1639 | <STRING_LITERAL> |
| 1640 | { |
| 1641 | return removeQuotesAndEscapes(token.image); |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | Pair<Identifier,Identifier> QualifiedName() throws ParseException: |
| 1646 | { |
| 1647 | String first = null; |
| 1648 | String second = null; |
| 1649 | } |
| 1650 | { |
| 1651 | first = Identifier() (<DOT> second = Identifier())? |
| 1652 | { |
| 1653 | Identifier id1 = null; |
| 1654 | Identifier id2 = null; |
| 1655 | if (second == null) { |
| 1656 | id2 = new Identifier(first); |
| 1657 | } else |
| 1658 | { |
| 1659 | id1 = new Identifier(first); |
| 1660 | id2 = new Identifier(second); |
| 1661 | } |
| 1662 | return new Pair<Identifier,Identifier>(id1, id2); |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException: |
| 1667 | { |
| 1668 | String first = null; |
| 1669 | String second = null; |
| 1670 | String third = null; |
| 1671 | } |
| 1672 | { |
| 1673 | first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())? |
| 1674 | { |
| 1675 | Identifier id1 = null; |
| 1676 | Identifier id2 = null; |
| 1677 | Identifier id3 = null; |
| 1678 | if (third == null) { |
| 1679 | id2 = new Identifier(first); |
| 1680 | id3 = new Identifier(second); |
| 1681 | } else { |
| 1682 | id1 = new Identifier(first); |
| 1683 | id2 = new Identifier(second); |
| 1684 | id3 = new Identifier(third); |
| 1685 | } |
| 1686 | return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1691 | { |
| 1692 | FunctionDecl funcDecl; |
| 1693 | FunctionSignature signature; |
| 1694 | String functionName; |
| 1695 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1696 | Expression funcBody; |
| 1697 | createNewScope(); |
| 1698 | } |
| 1699 | { |
| 1700 | <DECLARE> <FUNCTION> functionName = Identifier() |
| 1701 | paramList = ParameterList() |
| 1702 | <LEFTBRACE> funcBody = Expression() <RIGHTBRACE> |
| 1703 | { |
| 1704 | signature = new FunctionSignature(defaultDataverse, functionName, paramList.size()); |
| 1705 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1706 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
| 1707 | removeCurrentScope(); |
| 1708 | return funcDecl; |
| 1709 | } |
| 1710 | } |
| 1711 | |
Till Westmann | ef3f027 | 2016-07-27 18:34:01 -0700 | [diff] [blame] | 1712 | Query ExplainStatement() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1713 | { |
Till Westmann | ef3f027 | 2016-07-27 18:34:01 -0700 | [diff] [blame] | 1714 | Query query; |
| 1715 | } |
| 1716 | { |
Till Westmann | 516d1a8 | 2016-08-02 14:45:53 -0700 | [diff] [blame] | 1717 | <EXPLAIN> query = Query(true) |
Till Westmann | ef3f027 | 2016-07-27 18:34:01 -0700 | [diff] [blame] | 1718 | { |
| 1719 | return query; |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | Query Query(boolean explain) throws ParseException: |
| 1724 | { |
| 1725 | Query query = new Query(explain); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1726 | Expression expr; |
| 1727 | } |
| 1728 | { |
| 1729 | ( |
| 1730 | expr = Expression() |
| 1731 | | |
| 1732 | expr = SelectExpression(false) |
| 1733 | ) |
| 1734 | { |
| 1735 | query.setBody(expr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1736 | return query; |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | Expression Expression(): |
| 1743 | { |
| 1744 | Expression expr = null; |
| 1745 | Expression exprP = null; |
| 1746 | } |
| 1747 | { |
| 1748 | ( |
| 1749 | LOOKAHEAD(2) |
| 1750 | expr = OperatorExpr() |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 1751 | | expr = CaseExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1752 | | expr = QuantifiedExpression() |
| 1753 | ) |
| 1754 | { |
| 1755 | return (exprP==null) ? expr : exprP; |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | Expression OperatorExpr()throws ParseException: |
| 1762 | { |
| 1763 | OperatorExpr op = null; |
| 1764 | Expression operand = null; |
| 1765 | } |
| 1766 | { |
| 1767 | operand = AndExpr() |
| 1768 | ( |
| 1769 | |
| 1770 | <OR> |
| 1771 | { |
| 1772 | if (op == null) { |
| 1773 | op = new OperatorExpr(); |
| 1774 | op.addOperand(operand); |
| 1775 | op.setCurrentop(true); |
| 1776 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1777 | try{ |
| 1778 | op.addOperator(token.image.toLowerCase()); |
| 1779 | } catch (Exception e){ |
| 1780 | throw new ParseException(e.getMessage()); |
| 1781 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | operand = AndExpr() |
| 1785 | { |
| 1786 | op.addOperand(operand); |
| 1787 | } |
| 1788 | |
| 1789 | )* |
| 1790 | |
| 1791 | { |
| 1792 | return op==null? operand: op; |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | Expression AndExpr()throws ParseException: |
| 1797 | { |
| 1798 | OperatorExpr op = null; |
| 1799 | Expression operand = null; |
| 1800 | } |
| 1801 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1802 | operand = NotExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1803 | ( |
| 1804 | |
| 1805 | <AND> |
| 1806 | { |
| 1807 | if (op == null) { |
| 1808 | op = new OperatorExpr(); |
| 1809 | op.addOperand(operand); |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1810 | op.setCurrentop(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1811 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1812 | try{ |
| 1813 | op.addOperator(token.image.toLowerCase()); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1814 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1815 | throw new ParseException(e.getMessage()); |
| 1816 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1819 | operand = NotExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1820 | { |
| 1821 | op.addOperand(operand); |
| 1822 | } |
| 1823 | |
| 1824 | )* |
| 1825 | |
| 1826 | { |
| 1827 | return op==null? operand: op; |
| 1828 | } |
| 1829 | } |
| 1830 | |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1831 | Expression NotExpr()throws ParseException: |
| 1832 | { |
| 1833 | Expression inputExpr; |
| 1834 | boolean not = false; |
| 1835 | } |
| 1836 | { |
| 1837 | (<NOT> { not = true; } )? inputExpr = RelExpr() |
| 1838 | { |
| 1839 | if(not){ |
| 1840 | FunctionSignature signature = new FunctionSignature(null, "not", 1); |
| 1841 | return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr))); |
| 1842 | } else { |
| 1843 | return inputExpr; |
| 1844 | } |
| 1845 | } |
| 1846 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1847 | |
| 1848 | Expression RelExpr()throws ParseException: |
| 1849 | { |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1850 | boolean not = false; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1851 | OperatorExpr op = null; |
| 1852 | Expression operand = null; |
| 1853 | boolean broadcast = false; |
| 1854 | IExpressionAnnotation annotation = null; |
| 1855 | } |
| 1856 | { |
Yingyi Bu | 6c63834 | 2016-09-02 17:54:34 -0700 | [diff] [blame] | 1857 | operand = BetweenExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1858 | |
| 1859 | ( |
Yingyi Bu | 6e6a80c | 2017-01-21 20:18:49 -0800 | [diff] [blame] | 1860 | LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1861 | { |
| 1862 | String mhint = getHint(token); |
| 1863 | if (mhint != null) { |
| 1864 | if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1865 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1866 | } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 1867 | annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE; |
Yingyi Bu | ea4ec72 | 2016-11-04 01:26:16 -0700 | [diff] [blame] | 1868 | } else if (mhint.equals(BROADCAST_JOIN_HINT)) { |
| 1869 | broadcast = true; |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1870 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1871 | } |
Yingyi Bu | ea4ec72 | 2016-11-04 01:26:16 -0700 | [diff] [blame] | 1872 | |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1873 | String operator = token.image.toLowerCase(); |
Yingyi Bu | 4a4b896 | 2016-09-16 12:09:11 -0700 | [diff] [blame] | 1874 | if (operator.equals("<>")){ |
| 1875 | operator = "!="; |
| 1876 | } |
| 1877 | if (not) { |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1878 | operator = "not_" + operator; |
| 1879 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1880 | if (op == null) { |
| 1881 | op = new OperatorExpr(); |
Yingyi Bu | ea4ec72 | 2016-11-04 01:26:16 -0700 | [diff] [blame] | 1882 | op.addOperand(operand, false); // broadcast is always for the right branch |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1883 | op.setCurrentop(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1884 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1885 | try{ |
| 1886 | op.addOperator(operator); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1887 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1888 | throw new ParseException(e.getMessage()); |
| 1889 | } |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1890 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1891 | |
Yingyi Bu | 6c63834 | 2016-09-02 17:54:34 -0700 | [diff] [blame] | 1892 | operand = BetweenExpr() |
Yingyi Bu | ea4ec72 | 2016-11-04 01:26:16 -0700 | [diff] [blame] | 1893 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1894 | op.addOperand(operand, broadcast); |
Yingyi Bu | ea4ec72 | 2016-11-04 01:26:16 -0700 | [diff] [blame] | 1895 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1896 | )? |
| 1897 | |
| 1898 | { |
| 1899 | if (annotation != null) { |
| 1900 | op.addHint(annotation); |
| 1901 | } |
| 1902 | return op==null? operand: op; |
| 1903 | } |
| 1904 | } |
| 1905 | |
Yingyi Bu | 6e6a80c | 2017-01-21 20:18:49 -0800 | [diff] [blame] | 1906 | |
Yingyi Bu | 6c63834 | 2016-09-02 17:54:34 -0700 | [diff] [blame] | 1907 | Expression BetweenExpr()throws ParseException: |
| 1908 | { |
| 1909 | boolean not = false; |
| 1910 | OperatorExpr op = null; |
| 1911 | Expression operand = null; |
| 1912 | IExpressionAnnotation annotation = null; |
| 1913 | } |
| 1914 | { |
| 1915 | operand = IsExpr() |
| 1916 | ( |
| 1917 | LOOKAHEAD(2) |
| 1918 | (<NOT> { not = true; })? <BETWEEN> |
| 1919 | { |
| 1920 | String mhint = getHint(token); |
| 1921 | if (mhint != null) { |
| 1922 | if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1923 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1924 | } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 1925 | annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE; |
| 1926 | } |
| 1927 | } |
| 1928 | String operator = token.image.toLowerCase(); |
| 1929 | if(not){ |
| 1930 | operator = "not_" + operator; |
| 1931 | } |
| 1932 | if (op == null) { |
| 1933 | op = new OperatorExpr(); |
| 1934 | op.addOperand(operand); |
| 1935 | op.setCurrentop(true); |
| 1936 | } |
| 1937 | try{ |
| 1938 | op.addOperator(operator); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 1939 | } catch (CompilationException e){ |
Yingyi Bu | 6c63834 | 2016-09-02 17:54:34 -0700 | [diff] [blame] | 1940 | throw new ParseException(e.getMessage()); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | operand = IsExpr() |
| 1945 | { |
| 1946 | op.addOperand(operand); |
| 1947 | } |
| 1948 | |
| 1949 | <AND> |
| 1950 | operand = IsExpr() |
| 1951 | { |
| 1952 | op.addOperand(operand); |
| 1953 | } |
| 1954 | )? |
| 1955 | |
| 1956 | { |
| 1957 | if (annotation != null) { |
| 1958 | op.addHint(annotation); |
| 1959 | } |
| 1960 | return op==null? operand: op; |
| 1961 | } |
| 1962 | } |
| 1963 | |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1964 | Expression IsExpr() throws ParseException: |
| 1965 | { |
| 1966 | Expression expr = null; |
| 1967 | Expression operand = null; |
| 1968 | boolean not = false; |
| 1969 | } |
| 1970 | { |
Yingyi Bu | 6e6a80c | 2017-01-21 20:18:49 -0800 | [diff] [blame] | 1971 | operand = LikeExpr() |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1972 | ( <IS> (<NOT> { not = true; })? (<NULL> | <MISSING> | <UNKOWN>) |
| 1973 | { |
| 1974 | String functionName = "is-" + token.image.toLowerCase(); |
| 1975 | FunctionSignature signature = new FunctionSignature(null, functionName, 1); |
| 1976 | expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand))); |
| 1977 | if(not) { |
| 1978 | FunctionSignature notSignature = new FunctionSignature(null, "not", 1); |
| 1979 | expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr))); |
| 1980 | } |
| 1981 | } |
| 1982 | )? |
| 1983 | { |
| 1984 | return expr = expr==null? operand : expr; |
| 1985 | } |
| 1986 | } |
| 1987 | |
Yingyi Bu | 6e6a80c | 2017-01-21 20:18:49 -0800 | [diff] [blame] | 1988 | |
| 1989 | Expression LikeExpr()throws ParseException: |
| 1990 | { |
| 1991 | boolean not = false; |
| 1992 | OperatorExpr op = null; |
| 1993 | Expression operand = null; |
| 1994 | } |
| 1995 | { |
| 1996 | operand = ConcatExpr() |
| 1997 | ( |
| 1998 | LOOKAHEAD(2) |
| 1999 | (<NOT> { not = true; })? <LIKE> |
| 2000 | { |
| 2001 | op = new OperatorExpr(); |
| 2002 | op.addOperand(operand); |
| 2003 | op.setCurrentop(true); |
| 2004 | |
| 2005 | String operator = token.image.toLowerCase(); |
| 2006 | if (not) { |
| 2007 | operator = "not_" + operator; |
| 2008 | } |
| 2009 | try{ |
| 2010 | op.addOperator(operator); |
| 2011 | } catch (CompilationException e){ |
| 2012 | throw new ParseException(e.getMessage()); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | operand = ConcatExpr() |
| 2017 | { |
| 2018 | op.addOperand(operand); |
| 2019 | } |
| 2020 | )? |
| 2021 | |
| 2022 | { |
| 2023 | return op == null ? operand : op; |
| 2024 | } |
| 2025 | } |
| 2026 | |
Yingyi Bu | fdc71eb | 2016-08-24 22:41:57 -0700 | [diff] [blame] | 2027 | Expression ConcatExpr()throws ParseException: |
| 2028 | { |
| 2029 | OperatorExpr op = null; |
| 2030 | Expression operand = null; |
| 2031 | } |
| 2032 | { |
| 2033 | operand = AddExpr() |
| 2034 | ( |
| 2035 | LOOKAHEAD(1) |
| 2036 | (<CONCAT>) |
| 2037 | { |
| 2038 | if (op == null) { |
| 2039 | op = new OperatorExpr(); |
| 2040 | op.addOperand(operand); |
| 2041 | op.setCurrentop(true); |
| 2042 | } |
| 2043 | try{ |
| 2044 | ((OperatorExpr)op).addOperator(token.image); |
| 2045 | } catch (Exception e){ |
| 2046 | throw new ParseException(e.getMessage()); |
| 2047 | } |
| 2048 | } |
| 2049 | operand = AddExpr() |
| 2050 | { |
| 2051 | op.addOperand(operand); |
| 2052 | } |
| 2053 | )* |
| 2054 | |
| 2055 | { |
| 2056 | return op==null? operand: op; |
| 2057 | } |
| 2058 | } |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2059 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2060 | Expression AddExpr()throws ParseException: |
| 2061 | { |
| 2062 | OperatorExpr op = null; |
| 2063 | Expression operand = null; |
| 2064 | } |
| 2065 | { |
| 2066 | operand = MultExpr() |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2067 | ( |
Yingyi Bu | fdc71eb | 2016-08-24 22:41:57 -0700 | [diff] [blame] | 2068 | LOOKAHEAD(1) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2069 | (<PLUS> | <MINUS>) |
| 2070 | { |
| 2071 | if (op == null) { |
| 2072 | op = new OperatorExpr(); |
| 2073 | op.addOperand(operand); |
| 2074 | op.setCurrentop(true); |
| 2075 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2076 | try{ |
| 2077 | ((OperatorExpr)op).addOperator(token.image); |
| 2078 | } catch (Exception e){ |
| 2079 | throw new ParseException(e.getMessage()); |
| 2080 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | operand = MultExpr() |
| 2084 | { |
| 2085 | op.addOperand(operand); |
| 2086 | } |
| 2087 | )* |
| 2088 | |
| 2089 | { |
| 2090 | return op==null? operand: op; |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | Expression MultExpr()throws ParseException: |
| 2095 | { |
| 2096 | OperatorExpr op = null; |
| 2097 | Expression operand = null; |
| 2098 | } |
| 2099 | { |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 2100 | operand = ExponentExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2101 | |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 2102 | (( <MUL> | <DIV> | <MOD> | <IDIV>) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2103 | { |
| 2104 | if (op == null) { |
| 2105 | op = new OperatorExpr(); |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 2106 | op.addOperand(operand); |
| 2107 | op.setCurrentop(true); |
| 2108 | } |
| 2109 | try{ |
| 2110 | op.addOperator(token.image); |
| 2111 | } catch (Exception e){ |
| 2112 | throw new ParseException(e.getMessage()); |
| 2113 | } |
| 2114 | } |
| 2115 | operand = ExponentExpr() |
| 2116 | { |
| 2117 | op.addOperand(operand); |
| 2118 | } |
| 2119 | )* |
| 2120 | |
| 2121 | { |
| 2122 | return op==null?operand:op; |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | Expression ExponentExpr()throws ParseException: |
| 2127 | { |
| 2128 | OperatorExpr op = null; |
| 2129 | Expression operand = null; |
| 2130 | } |
| 2131 | { |
| 2132 | operand = UnaryExpr() |
| 2133 | (<CARET> |
| 2134 | { |
| 2135 | if (op == null) { |
| 2136 | op = new OperatorExpr(); |
| 2137 | op.addOperand(operand); |
| 2138 | op.setCurrentop(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2139 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2140 | try{ |
| 2141 | op.addOperator(token.image); |
| 2142 | } catch (Exception e){ |
| 2143 | throw new ParseException(e.getMessage()); |
| 2144 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2145 | } |
| 2146 | operand = UnaryExpr() |
| 2147 | { |
| 2148 | op.addOperand(operand); |
| 2149 | } |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 2150 | )? |
| 2151 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2152 | return op==null?operand:op; |
Yingyi Bu | 79ccdac | 2016-07-26 23:49:24 -0700 | [diff] [blame] | 2153 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | Expression UnaryExpr() throws ParseException: |
| 2157 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2158 | boolean not = false; |
| 2159 | UnaryExpr uexpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2160 | Expression expr = null; |
| 2161 | } |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2162 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2163 | ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2164 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2165 | String exprType = token.image.toLowerCase(); |
| 2166 | if(not){ |
| 2167 | exprType = "not_" + exprType; |
| 2168 | } |
| 2169 | uexpr = new UnaryExpr(); |
| 2170 | try{ |
| 2171 | uexpr.setExprType(exprType); |
Taewoo Kim | e65e6ca | 2017-01-14 17:53:28 -0800 | [diff] [blame] | 2172 | } catch (CompilationException e){ |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2173 | throw new ParseException(e.getMessage()); |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2174 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2175 | } |
| 2176 | )? |
| 2177 | |
| 2178 | expr = ValueExpr() |
| 2179 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2180 | if(uexpr==null){ |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2181 | return expr; |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 2182 | } |
| 2183 | uexpr.setExpr(expr); |
| 2184 | return uexpr; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | Expression ValueExpr()throws ParseException: |
| 2189 | { |
| 2190 | Expression expr = null; |
| 2191 | Identifier ident = null; |
| 2192 | AbstractAccessor fa = null; |
| 2193 | Expression indexExpr = null; |
| 2194 | } |
| 2195 | { |
| 2196 | expr = PrimaryExpr() ( |
| 2197 | ident = Field() |
| 2198 | { |
| 2199 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 2200 | : new FieldAccessor(fa, ident)); |
| 2201 | } |
| 2202 | | indexExpr = Index() |
| 2203 | { |
| 2204 | fa = (fa == null ? new IndexAccessor(expr, indexExpr) |
| 2205 | : new IndexAccessor(fa, indexExpr)); |
| 2206 | } |
| 2207 | )* |
| 2208 | { |
| 2209 | return fa == null ? expr : fa; |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | Identifier Field() throws ParseException: |
| 2214 | { |
| 2215 | String ident = null; |
| 2216 | } |
| 2217 | { |
| 2218 | <DOT> ident = Identifier() |
| 2219 | { |
| 2220 | return new Identifier(ident); |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | Expression Index() throws ParseException: |
| 2225 | { |
| 2226 | Expression expr = null; |
| 2227 | } |
| 2228 | { |
| 2229 | <LEFTBRACKET> ( expr = Expression() |
| 2230 | { |
| 2231 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 2232 | { |
| 2233 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 2234 | if(lit.getLiteralType() != Literal.Type.INTEGER && |
| 2235 | lit.getLiteralType() != Literal.Type.LONG) { |
| 2236 | throw new ParseException("Index should be an INTEGER"); |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | | <QUES> // ANY |
| 2242 | |
| 2243 | ) |
| 2244 | |
| 2245 | <RIGHTBRACKET> |
| 2246 | { |
| 2247 | return expr; |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | |
| 2252 | Expression PrimaryExpr()throws ParseException: |
| 2253 | { |
| 2254 | Expression expr = null; |
| 2255 | } |
| 2256 | { |
| 2257 | ( LOOKAHEAD(4) |
| 2258 | expr = FunctionCallExpr() |
| 2259 | | expr = Literal() |
| 2260 | | expr = VariableRef() |
| 2261 | | expr = ListConstructor() |
| 2262 | | expr = RecordConstructor() |
| 2263 | | expr = ParenthesizedExpression() |
| 2264 | ) |
| 2265 | { |
| 2266 | return expr; |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | Expression Literal() throws ParseException: |
| 2271 | { |
| 2272 | LiteralExpr lit = new LiteralExpr(); |
| 2273 | String str = null; |
| 2274 | } |
| 2275 | { |
| 2276 | ( str = StringLiteral() |
| 2277 | { |
| 2278 | lit.setValue(new StringLiteral(str)); |
| 2279 | } |
| 2280 | | <INTEGER_LITERAL> |
| 2281 | { |
Till Westmann | 68c6a99 | 2016-09-30 00:19:12 -0700 | [diff] [blame] | 2282 | try { |
| 2283 | lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image))); |
| 2284 | } catch (NumberFormatException e) { |
| 2285 | throw new ParseException("Could not parse numeric literal \"" + token.image +'"'); |
| 2286 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2287 | } |
| 2288 | | <FLOAT_LITERAL> |
| 2289 | { |
Till Westmann | 68c6a99 | 2016-09-30 00:19:12 -0700 | [diff] [blame] | 2290 | try { |
| 2291 | lit.setValue(new FloatLiteral(Float.valueOf(token.image))); |
| 2292 | } catch (NumberFormatException e) { |
| 2293 | throw new ParseException("Could not parse numeric literal \"" + token.image +'"'); |
| 2294 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2295 | } |
| 2296 | | <DOUBLE_LITERAL> |
| 2297 | { |
Till Westmann | 68c6a99 | 2016-09-30 00:19:12 -0700 | [diff] [blame] | 2298 | try { |
| 2299 | lit.setValue(new DoubleLiteral(Double.valueOf(token.image))); |
| 2300 | } catch (NumberFormatException e) { |
| 2301 | throw new ParseException("Could not parse numeric literal \"" + token.image +'"'); |
| 2302 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2303 | } |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 2304 | | <MISSING> |
| 2305 | { |
| 2306 | lit.setValue(MissingLiteral.INSTANCE); |
| 2307 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2308 | | <NULL> |
| 2309 | { |
| 2310 | lit.setValue(NullLiteral.INSTANCE); |
| 2311 | } |
| 2312 | | <TRUE> |
| 2313 | { |
| 2314 | lit.setValue(TrueLiteral.INSTANCE); |
| 2315 | } |
| 2316 | | <FALSE> |
| 2317 | { |
| 2318 | lit.setValue(FalseLiteral.INSTANCE); |
| 2319 | } |
| 2320 | ) |
| 2321 | { |
| 2322 | return lit; |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | |
| 2327 | VariableExpr VariableRef() throws ParseException: |
| 2328 | { |
| 2329 | VariableExpr varExp = new VariableExpr(); |
| 2330 | VarIdentifier var = new VarIdentifier(); |
| 2331 | } |
| 2332 | { |
| 2333 | { String id = null; } |
| 2334 | (<IDENTIFIER> { id = token.image; } | id = QuotedString()) |
| 2335 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2336 | id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$" |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2337 | Identifier ident = lookupSymbol(id); |
| 2338 | if (isInForbiddenScopes(id)) { |
| 2339 | 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."); |
| 2340 | } |
| 2341 | if(ident != null) { // exist such ident |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2342 | varExp.setVar((VarIdentifier)ident); |
| 2343 | } else { |
| 2344 | varExp.setVar(var); |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2345 | varExp.setIsNewVar(false); |
| 2346 | var.setValue(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2347 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2348 | return varExp; |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | VariableExpr Variable() throws ParseException: |
| 2354 | { |
| 2355 | VariableExpr varExp = new VariableExpr(); |
| 2356 | VarIdentifier var = new VarIdentifier(); |
| 2357 | } |
| 2358 | { |
| 2359 | { String id = null; } |
| 2360 | (<IDENTIFIER> { id = token.image; } | id = QuotedString()) |
| 2361 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2362 | id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$". |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2363 | Identifier ident = lookupSymbol(id); |
| 2364 | if(ident != null) { // exist such ident |
| 2365 | varExp.setIsNewVar(false); |
| 2366 | } |
| 2367 | varExp.setVar(var); |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2368 | var.setValue(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2369 | return varExp; |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | Expression ListConstructor() throws ParseException: |
| 2374 | { |
| 2375 | Expression expr = null; |
| 2376 | } |
| 2377 | { |
| 2378 | ( |
| 2379 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 2380 | ) |
| 2381 | |
| 2382 | { |
| 2383 | return expr; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | ListConstructor OrderedListConstructor() throws ParseException: |
| 2389 | { |
| 2390 | ListConstructor expr = new ListConstructor(); |
| 2391 | List<Expression> exprList = null; |
| 2392 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 2393 | } |
| 2394 | { |
| 2395 | <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET> |
| 2396 | { |
| 2397 | expr.setExprList(exprList); |
| 2398 | return expr; |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 2403 | { |
| 2404 | ListConstructor expr = new ListConstructor(); |
| 2405 | List<Expression> exprList = null; |
| 2406 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 2407 | } |
| 2408 | { |
| 2409 | <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE> |
| 2410 | { |
| 2411 | expr.setExprList(exprList); |
| 2412 | return expr; |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | List<Expression> ExpressionList() throws ParseException: |
| 2417 | { |
| 2418 | Expression expr = null; |
| 2419 | List<Expression> list = null; |
| 2420 | List<Expression> exprList = new ArrayList<Expression>(); |
| 2421 | } |
| 2422 | { |
| 2423 | ( |
| 2424 | expr = Expression() { exprList.add(expr); } |
| 2425 | (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })? |
| 2426 | )? |
| 2427 | (LOOKAHEAD(1) Comma())? |
| 2428 | { |
| 2429 | return exprList; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | void Comma(): |
| 2434 | {} |
| 2435 | { |
| 2436 | <COMMA> |
| 2437 | } |
| 2438 | |
| 2439 | RecordConstructor RecordConstructor() throws ParseException: |
| 2440 | { |
| 2441 | RecordConstructor expr = new RecordConstructor(); |
| 2442 | FieldBinding tmp = null; |
| 2443 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 2444 | } |
| 2445 | { |
| 2446 | <LEFTBRACE> (tmp = FieldBinding() |
| 2447 | { |
| 2448 | fbList.add(tmp); |
| 2449 | } |
| 2450 | (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE> |
| 2451 | { |
| 2452 | expr.setFbList(fbList); |
| 2453 | return expr; |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | FieldBinding FieldBinding() throws ParseException: |
| 2458 | { |
| 2459 | FieldBinding fb = new FieldBinding(); |
| 2460 | Expression left, right; |
| 2461 | } |
| 2462 | { |
| 2463 | left = Expression() <COLON> right = Expression() |
| 2464 | { |
| 2465 | fb.setLeftExpr(left); |
| 2466 | fb.setRightExpr(right); |
| 2467 | return fb; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | Expression FunctionCallExpr() throws ParseException: |
| 2473 | { |
| 2474 | CallExpr callExpr; |
| 2475 | List<Expression> argList = new ArrayList<Expression>(); |
Yingyi Bu | f4d0984 | 2016-08-26 00:03:52 -0700 | [diff] [blame] | 2476 | Expression tmp = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2477 | int arity = 0; |
| 2478 | FunctionName funcName = null; |
| 2479 | String hint = null; |
Yingyi Bu | f4d0984 | 2016-08-26 00:03:52 -0700 | [diff] [blame] | 2480 | boolean star = false; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2481 | } |
| 2482 | { |
| 2483 | funcName = FunctionName() |
| 2484 | { |
| 2485 | hint = funcName.hint; |
| 2486 | } |
Yingyi Bu | f4d0984 | 2016-08-26 00:03:52 -0700 | [diff] [blame] | 2487 | <LEFTPAREN> ( ( tmp = Expression() | <MUL> { star = true; } ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2488 | { |
Yingyi Bu | f4d0984 | 2016-08-26 00:03:52 -0700 | [diff] [blame] | 2489 | if(star){ |
| 2490 | if(!funcName.function.toLowerCase().equals("count")){ |
| 2491 | throw new ParseException("The parameter * can only be used in COUNT()."); |
| 2492 | } |
| 2493 | argList.add(new LiteralExpr(new LongIntegerLiteral(1L))); |
| 2494 | } else { |
| 2495 | argList.add(tmp); |
| 2496 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2497 | arity ++; |
| 2498 | } |
| 2499 | (<COMMA> tmp = Expression() |
| 2500 | { |
| 2501 | argList.add(tmp); |
| 2502 | arity++; |
| 2503 | } |
| 2504 | )*)? <RIGHTPAREN> |
| 2505 | { |
| 2506 | // TODO use funcName.library |
| 2507 | String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function; |
| 2508 | FunctionSignature signature |
| 2509 | = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2510 | if (signature == null) { |
| 2511 | signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2512 | } |
Xikui Wang | 96fd402 | 2017-04-10 14:23:31 -0700 | [diff] [blame] | 2513 | callExpr = FunctionMapUtil.normalizedListInputFunctions(new CallExpr(signature,argList)); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2514 | if (hint != null) { |
| 2515 | if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 2516 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 2517 | } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 2518 | callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE); |
| 2519 | } |
| 2520 | } |
| 2521 | return callExpr; |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | Expression ParenthesizedExpression() throws ParseException: |
| 2526 | { |
| 2527 | Expression expr; |
| 2528 | } |
| 2529 | { |
| 2530 | ( |
| 2531 | LOOKAHEAD(2) |
| 2532 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 2533 | | |
| 2534 | expr = Subquery() |
| 2535 | ) |
| 2536 | { |
| 2537 | return expr; |
| 2538 | } |
| 2539 | } |
| 2540 | |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 2541 | |
| 2542 | Expression CaseExpr() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2543 | { |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 2544 | Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE); |
| 2545 | List<Expression> whenExprs = new ArrayList<Expression>(); |
| 2546 | List<Expression> thenExprs = new ArrayList<Expression>(); |
| 2547 | Expression elseExpr = null; |
Yingyi Bu | fdc71eb | 2016-08-24 22:41:57 -0700 | [diff] [blame] | 2548 | |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 2549 | Expression whenExpr = null; |
| 2550 | Expression thenExpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2551 | } |
| 2552 | { |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 2553 | <CASE> ( conditionExpr = Expression() )? |
| 2554 | ( |
| 2555 | <WHEN> whenExpr = Expression() |
| 2556 | { |
| 2557 | whenExprs.add(whenExpr); |
| 2558 | } |
| 2559 | <THEN> thenExpr = Expression() |
| 2560 | { |
| 2561 | thenExprs.add(thenExpr); |
| 2562 | } |
| 2563 | )* |
| 2564 | (<ELSE> elseExpr = Expression() )? |
| 2565 | <END> |
| 2566 | { |
| 2567 | return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr); |
| 2568 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2571 | SelectExpression SelectExpression(boolean subquery) throws ParseException: |
| 2572 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2573 | List<LetClause> letClauses = new ArrayList<LetClause>(); |
| 2574 | SelectSetOperation selectSetOperation; |
| 2575 | OrderbyClause orderbyClause = null; |
| 2576 | LimitClause limitClause = null; |
| 2577 | createNewScope(); |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2578 | } |
| 2579 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2580 | ( letClauses = LetClause() )? |
| 2581 | selectSetOperation = SelectSetOperation() |
| 2582 | (orderbyClause = OrderbyClause() {})? |
| 2583 | (limitClause = LimitClause() {})? |
| 2584 | { |
| 2585 | return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery); |
| 2586 | } |
| 2587 | } |
| 2588 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2589 | SelectSetOperation SelectSetOperation() throws ParseException: |
| 2590 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2591 | SetOperationInput setOperationInputLeft; |
| 2592 | List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>(); |
| 2593 | } |
| 2594 | { |
| 2595 | { |
| 2596 | SelectBlock selectBlockLeft = null; |
| 2597 | SelectExpression subqueryLeft = null; |
| 2598 | Expression expr = null; |
| 2599 | } |
| 2600 | selectBlockLeft = SelectBlock() |
| 2601 | { |
| 2602 | setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft); |
| 2603 | } |
| 2604 | ( |
| 2605 | { |
| 2606 | SetOpType opType = SetOpType.UNION; |
| 2607 | boolean setSemantics = true; |
| 2608 | SelectBlock selectBlockRight = null; |
| 2609 | SelectExpression subqueryRight = null; |
| 2610 | } |
| 2611 | (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )? |
| 2612 | (selectBlockRight = SelectBlock()| subqueryRight = Subquery()) |
| 2613 | { |
| 2614 | setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight))); |
| 2615 | } |
| 2616 | )* |
| 2617 | { |
| 2618 | return new SelectSetOperation(setOperationInputLeft, setOperationRights); |
| 2619 | } |
| 2620 | } |
| 2621 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2622 | SelectExpression Subquery() throws ParseException: |
| 2623 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2624 | SelectExpression selectExpr = null; |
| 2625 | } |
| 2626 | { |
| 2627 | <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN> |
| 2628 | { |
| 2629 | return selectExpr; |
| 2630 | } |
| 2631 | } |
| 2632 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2633 | SelectBlock SelectBlock() throws ParseException: |
| 2634 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2635 | SelectClause selectClause = null; |
| 2636 | FromClause fromClause = null; |
| 2637 | List<LetClause> fromLetClauses = null; |
| 2638 | WhereClause whereClause = null; |
| 2639 | GroupbyClause groupbyClause = null; |
| 2640 | List<LetClause> gbyLetClauses = null; |
| 2641 | HavingClause havingClause = null; |
| 2642 | } |
| 2643 | { |
| 2644 | ( |
| 2645 | selectClause = SelectClause() |
| 2646 | ( |
| 2647 | LOOKAHEAD(1) |
| 2648 | fromClause = FromClause() |
| 2649 | ( |
| 2650 | LOOKAHEAD(1) |
| 2651 | fromLetClauses = LetClause() |
| 2652 | )? |
| 2653 | )? |
| 2654 | (whereClause = WhereClause())? |
| 2655 | ( |
| 2656 | groupbyClause = GroupbyClause() |
| 2657 | ( |
| 2658 | LOOKAHEAD(1) |
| 2659 | gbyLetClauses = LetClause() |
| 2660 | )? |
| 2661 | (havingClause = HavingClause())? |
| 2662 | )? |
| 2663 | | |
| 2664 | fromClause = FromClause() |
| 2665 | ( |
| 2666 | LOOKAHEAD(1) |
| 2667 | fromLetClauses = LetClause() |
| 2668 | )? |
| 2669 | (whereClause = WhereClause())? |
| 2670 | ( |
| 2671 | groupbyClause = GroupbyClause() |
| 2672 | ( |
| 2673 | gbyLetClauses = LetClause() |
| 2674 | )? |
| 2675 | (havingClause = HavingClause())? |
| 2676 | )? |
| 2677 | selectClause = SelectClause() |
| 2678 | ) |
| 2679 | { |
| 2680 | return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause); |
| 2681 | } |
| 2682 | } |
| 2683 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2684 | SelectClause SelectClause() throws ParseException: |
| 2685 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2686 | SelectRegular selectRegular = null; |
| 2687 | SelectElement selectElement = null; |
| 2688 | boolean distinct = false; |
| 2689 | } |
| 2690 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2691 | <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2692 | ( |
| 2693 | selectRegular = SelectRegular() |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2694 | | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2695 | selectElement = SelectElement() |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2696 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2697 | { |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2698 | if(selectRegular == null && selectElement == null){ |
| 2699 | Projection projection = new Projection(null, null, true, false); |
| 2700 | List<Projection> projections = new ArrayList<Projection>(); |
| 2701 | projections.add(projection); |
| 2702 | selectRegular = new SelectRegular(projections); |
| 2703 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2704 | return new SelectClause(selectElement, selectRegular, distinct); |
| 2705 | } |
| 2706 | } |
| 2707 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2708 | SelectRegular SelectRegular() throws ParseException: |
| 2709 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2710 | List<Projection> projections = new ArrayList<Projection>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2711 | } |
| 2712 | { |
| 2713 | { |
| 2714 | Projection projection = null; |
| 2715 | } |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2716 | projection = Projection() { projections.add(projection); } |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2717 | ( LOOKAHEAD(2) <COMMA> |
| 2718 | projection = Projection() {projections.add(projection);} |
| 2719 | )* |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2720 | { |
| 2721 | return new SelectRegular(projections); |
| 2722 | } |
| 2723 | } |
| 2724 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2725 | SelectElement SelectElement() throws ParseException: |
| 2726 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2727 | Expression expr = null; |
| 2728 | String name = null; |
| 2729 | } |
| 2730 | { |
| 2731 | (<RAW>|<ELEMENT>|<VALUE>) expr = Expression() |
| 2732 | { |
| 2733 | return new SelectElement(expr); |
| 2734 | } |
| 2735 | } |
| 2736 | |
Yingyi Bu | ab81748 | 2016-08-19 21:29:31 -0700 | [diff] [blame] | 2737 | Projection Projection() throws ParseException : |
| 2738 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2739 | Expression expr = null; |
| 2740 | Identifier identifier = null; |
| 2741 | String name = null; |
| 2742 | boolean star = false; |
| 2743 | boolean exprStar = false; |
| 2744 | } |
| 2745 | { |
| 2746 | ( |
| 2747 | LOOKAHEAD(2) |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2748 | expr = Expression() ((<AS>)? name = Identifier())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2749 | | expr = Expression() <DOT> <MUL> {exprStar = true; } |
| 2750 | | <MUL> {star = true; } |
| 2751 | ) |
| 2752 | { |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2753 | if(!star && name == null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2754 | String generatedColumnIdentifier = ExpressionToVariableUtil.getGeneratedIdentifier(expr, false); |
| 2755 | if(generatedColumnIdentifier != null){ |
| 2756 | name = SqlppVariableUtil.toUserDefinedName(generatedColumnIdentifier); |
| 2757 | } |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2758 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2759 | return new Projection(expr, name, star, exprStar); |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | FromClause FromClause() throws ParseException : |
| 2764 | { |
| 2765 | List<FromTerm> fromTerms = new ArrayList<FromTerm>(); |
| 2766 | extendCurrentScope(); |
| 2767 | } |
| 2768 | { |
| 2769 | { |
| 2770 | FromTerm fromTerm = null; |
| 2771 | } |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2772 | <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2773 | (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )* |
| 2774 | { |
| 2775 | return new FromClause(fromTerms); |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | FromTerm FromTerm() throws ParseException : |
| 2780 | { |
| 2781 | Expression leftExpr = null; |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2782 | VariableExpr leftVar = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2783 | VariableExpr posVar = null; |
| 2784 | List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>(); |
| 2785 | } |
| 2786 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2787 | leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2788 | ( |
| 2789 | {JoinType joinType = JoinType.INNER; } |
| 2790 | (joinType = JoinType())? |
| 2791 | { |
| 2792 | AbstractBinaryCorrelateClause correlateClause = null; |
| 2793 | } |
| 2794 | (correlateClause = JoinClause(joinType) |
Yingyi Bu | 6d999ed | 2016-07-13 11:59:06 -0700 | [diff] [blame] | 2795 | | correlateClause = UnnestClause(joinType) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2796 | ) |
| 2797 | { |
| 2798 | correlateClauses.add(correlateClause); |
| 2799 | } |
| 2800 | )* |
| 2801 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2802 | if(leftVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2803 | leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2804 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2805 | return new FromTerm(leftExpr, leftVar, posVar, correlateClauses); |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | JoinClause JoinClause(JoinType joinType) throws ParseException : |
| 2810 | { |
| 2811 | Expression rightExpr = null; |
| 2812 | VariableExpr rightVar = null; |
| 2813 | VariableExpr posVar = null; |
| 2814 | Expression conditionExpr = null; |
| 2815 | } |
| 2816 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2817 | <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2818 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2819 | if(rightVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2820 | rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2821 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2822 | return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr); |
| 2823 | } |
| 2824 | } |
| 2825 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2826 | UnnestClause UnnestClause(JoinType joinType) throws ParseException : |
| 2827 | { |
| 2828 | Expression rightExpr; |
| 2829 | VariableExpr rightVar; |
| 2830 | VariableExpr posVar = null; |
| 2831 | } |
| 2832 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2833 | (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2834 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2835 | if(rightVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2836 | rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2837 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2838 | return new UnnestClause(joinType, rightExpr, rightVar, posVar); |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | JoinType JoinType() throws ParseException : |
| 2844 | { |
| 2845 | JoinType joinType = JoinType.INNER; |
| 2846 | } |
| 2847 | { |
| 2848 | (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; }) |
| 2849 | { |
| 2850 | return joinType; |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | List<LetClause> LetClause() throws ParseException: |
| 2855 | { |
| 2856 | List<LetClause> letList = new ArrayList<LetClause>(); |
| 2857 | LetClause letClause; |
| 2858 | } |
| 2859 | { |
| 2860 | ( |
| 2861 | (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })* |
| 2862 | | |
| 2863 | <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })* |
| 2864 | ) |
| 2865 | { |
| 2866 | return letList; |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | WhereClause WhereClause()throws ParseException : |
| 2871 | { |
| 2872 | WhereClause wc = new WhereClause(); |
| 2873 | Expression whereExpr; |
| 2874 | } |
| 2875 | { |
| 2876 | <WHERE> whereExpr = Expression() |
| 2877 | { |
| 2878 | wc.setWhereExpr(whereExpr); |
| 2879 | return wc; |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | OrderbyClause OrderbyClause()throws ParseException : |
| 2884 | { |
| 2885 | OrderbyClause oc = new OrderbyClause(); |
| 2886 | Expression orderbyExpr; |
| 2887 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 2888 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 2889 | int numOfOrderby = 0; |
| 2890 | } |
| 2891 | { |
| 2892 | <ORDER> |
| 2893 | { |
| 2894 | String hint = getHint(token); |
| 2895 | if (hint != null) { |
| 2896 | if (hint.startsWith(INMEMORY_HINT)) { |
| 2897 | String splits[] = hint.split(" +"); |
| 2898 | int numFrames = Integer.parseInt(splits[1]); |
| 2899 | int numTuples = Integer.parseInt(splits[2]); |
| 2900 | oc.setNumFrames(numFrames); |
| 2901 | oc.setNumTuples(numTuples); |
| 2902 | } |
| 2903 | } |
| 2904 | } |
| 2905 | <BY> orderbyExpr = Expression() |
| 2906 | { |
| 2907 | orderbyList.add(orderbyExpr); |
| 2908 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 2909 | } |
| 2910 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2911 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2912 | { |
| 2913 | modifierList.add(modif); |
| 2914 | } |
| 2915 | |
| 2916 | (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression() |
| 2917 | { |
| 2918 | orderbyList.add(orderbyExpr); |
| 2919 | modif = OrderbyClause.OrderModifier.ASC; |
| 2920 | } |
| 2921 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2922 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2923 | { |
| 2924 | modifierList.add(modif); |
| 2925 | } |
| 2926 | )* |
| 2927 | |
| 2928 | { |
| 2929 | oc.setModifierList(modifierList); |
| 2930 | oc.setOrderbyList(orderbyList); |
| 2931 | return oc; |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | GroupbyClause GroupbyClause()throws ParseException : |
| 2936 | { |
| 2937 | GroupbyClause gbc = new GroupbyClause(); |
| 2938 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 2939 | VariableExpr var = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2940 | Expression expr = null; |
| 2941 | VariableExpr decorVar = null; |
| 2942 | Expression decorExpr = null; |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2943 | |
| 2944 | VariableExpr groupVar = null; |
| 2945 | List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2946 | } |
| 2947 | { |
| 2948 | { |
| 2949 | Scope newScope = extendCurrentScopeNoPush(true); |
| 2950 | // extendCurrentScope(true); |
| 2951 | } |
| 2952 | <GROUP> |
| 2953 | { |
| 2954 | String hint = getHint(token); |
| 2955 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 2956 | gbc.setHashGroupByHint(true); |
| 2957 | } |
| 2958 | } |
| 2959 | <BY> ( |
| 2960 | expr = Expression() |
| 2961 | (LOOKAHEAD(1) (<AS>)? |
| 2962 | var = Variable() |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2963 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2964 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2965 | if(var==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2966 | var = ExpressionToVariableUtil.getGeneratedVariable(expr, false); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2967 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2968 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 2969 | vePairList.add(pair1); |
| 2970 | } |
| 2971 | ( LOOKAHEAD(1) <COMMA> |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2972 | { |
| 2973 | var = null; |
| 2974 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2975 | expr = Expression() |
| 2976 | (LOOKAHEAD(1) (<AS>)? |
| 2977 | var = Variable() |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2978 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2979 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2980 | if(var==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2981 | var = ExpressionToVariableUtil.getGeneratedVariable(expr, false); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2982 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2983 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 2984 | vePairList.add(pair2); |
| 2985 | } |
| 2986 | )* |
| 2987 | ) |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2988 | (<GROUP> <AS> groupVar = Variable() |
| 2989 | ( LOOKAHEAD(1) |
| 2990 | { |
| 2991 | VariableExpr fieldVarExpr = null; |
| 2992 | String fieldIdentifierStr = null; |
| 2993 | } |
| 2994 | <LEFTPAREN> |
| 2995 | fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier() |
| 2996 | { |
| 2997 | groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr))); |
| 2998 | } |
| 2999 | (<COMMA> |
| 3000 | fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier() |
| 3001 | { |
| 3002 | groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr))); |
| 3003 | } |
| 3004 | )* |
| 3005 | <RIGHTPAREN> |
| 3006 | )? |
| 3007 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3008 | { |
| 3009 | gbc.setGbyPairList(vePairList); |
| 3010 | gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>()); |
Yingyi Bu | 8671ddf | 2016-08-14 23:58:43 -0700 | [diff] [blame] | 3011 | gbc.setWithVarMap(new HashMap<Expression, VariableExpr>()); |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 3012 | gbc.setGroupVar(groupVar); |
| 3013 | gbc.setGroupFieldList(groupFieldList); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3014 | replaceCurrentScope(newScope); |
| 3015 | return gbc; |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | HavingClause HavingClause() throws ParseException: |
| 3020 | { |
| 3021 | Expression filterExpr = null; |
| 3022 | } |
| 3023 | { |
| 3024 | <HAVING> filterExpr = Expression() |
| 3025 | { |
| 3026 | return new HavingClause(filterExpr); |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | LimitClause LimitClause() throws ParseException: |
| 3031 | { |
| 3032 | LimitClause lc = new LimitClause(); |
| 3033 | Expression expr; |
| 3034 | pushForbiddenScope(getCurrentScope()); |
| 3035 | } |
| 3036 | { |
| 3037 | <LIMIT> expr = Expression() { lc.setLimitExpr(expr); } |
| 3038 | (<OFFSET> expr = Expression() { lc.setOffset(expr); })? |
| 3039 | |
| 3040 | { |
| 3041 | popForbiddenScope(); |
| 3042 | return lc; |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 3047 | { |
| 3048 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 3049 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 3050 | Expression satisfiesExpr; |
| 3051 | VariableExpr var; |
| 3052 | Expression inExpr; |
| 3053 | QuantifiedPair pair; |
| 3054 | } |
| 3055 | { |
| 3056 | { |
| 3057 | createNewScope(); |
| 3058 | } |
| 3059 | |
Yingyi Bu | 8aac724 | 2016-09-13 23:14:09 -0700 | [diff] [blame] | 3060 | ( ((<ANY>|<SOME>) { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 3061 | | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3062 | var = Variable() <IN> inExpr = Expression() |
| 3063 | { |
| 3064 | pair = new QuantifiedPair(var, inExpr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3065 | quantifiedList.add(pair); |
| 3066 | } |
| 3067 | ( |
| 3068 | <COMMA> var = Variable() <IN> inExpr = Expression() |
| 3069 | { |
| 3070 | pair = new QuantifiedPair(var, inExpr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3071 | quantifiedList.add(pair); |
| 3072 | } |
| 3073 | )* |
Yingyi Bu | 858efae | 2016-10-13 17:31:57 -0700 | [diff] [blame] | 3074 | <SATISFIES> satisfiesExpr = Expression() (<END>)? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3075 | { |
| 3076 | qc.setSatisfiesExpr(satisfiesExpr); |
| 3077 | qc.setQuantifiedList(quantifiedList); |
| 3078 | removeCurrentScope(); |
| 3079 | return qc; |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | LetClause LetElement() throws ParseException: |
| 3084 | { |
| 3085 | LetClause lc = new LetClause(); |
| 3086 | VariableExpr varExp; |
| 3087 | Expression beExp; |
| 3088 | extendCurrentScope(); |
| 3089 | } |
| 3090 | { |
| 3091 | varExp = Variable() <EQ> beExp = Expression() |
| 3092 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3093 | lc.setVarExpr(varExp); |
| 3094 | lc.setBindingExpr(beExp); |
| 3095 | return lc; |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | LetClause WithElement() throws ParseException: |
| 3100 | { |
| 3101 | LetClause lc = new LetClause(); |
| 3102 | VariableExpr varExp; |
| 3103 | Expression beExp; |
| 3104 | extendCurrentScope(); |
| 3105 | } |
| 3106 | { |
| 3107 | varExp = Variable() <AS> beExp = Expression() |
| 3108 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3109 | lc.setVarExpr(varExp); |
| 3110 | lc.setBindingExpr(beExp); |
| 3111 | return lc; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | TOKEN_MGR_DECLS: |
| 3116 | { |
| 3117 | public int commentDepth = 0; |
Till Westmann | e9b2adf | 2016-10-15 12:39:01 -0700 | [diff] [blame] | 3118 | public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3119 | |
| 3120 | public void pushState() { |
| 3121 | lexerStateStack.push( curLexState ); |
| 3122 | } |
| 3123 | |
| 3124 | public void popState(String token) { |
| 3125 | if (lexerStateStack.size() > 0) { |
| 3126 | SwitchTo( lexerStateStack.pop() ); |
| 3127 | } else { |
| 3128 | int errorLine = input_stream.getEndLine(); |
| 3129 | int errorColumn = input_stream.getEndColumn(); |
| 3130 | String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token |
| 3131 | + "\" but state stack is empty."; |
| 3132 | throw new TokenMgrError(msg, -1); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | <DEFAULT,IN_DBL_BRACE> |
| 3138 | TOKEN [IGNORE_CASE]: |
| 3139 | { |
| 3140 | <ALL : "all"> |
| 3141 | | <AND : "and"> |
Yingyi Bu | 8aac724 | 2016-09-13 23:14:09 -0700 | [diff] [blame] | 3142 | | <ANY : "any"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3143 | | <APPLY : "apply"> |
| 3144 | | <AS : "as"> |
| 3145 | | <ASC : "asc"> |
| 3146 | | <AT : "at"> |
| 3147 | | <AUTOGENERATED : "autogenerated"> |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 3148 | | <BETWEEN : "between"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3149 | | <BTREE : "btree"> |
| 3150 | | <BY : "by"> |
| 3151 | | <CASE : "case"> |
| 3152 | | <CLOSED : "closed"> |
| 3153 | | <CREATE : "create"> |
| 3154 | | <COMPACTION : "compaction"> |
| 3155 | | <COMPACT : "compact"> |
| 3156 | | <CONNECT : "connect"> |
| 3157 | | <CORRELATE : "correlate"> |
Yingyi Bu | d56ff03 | 2016-08-01 10:26:57 -0700 | [diff] [blame] | 3158 | | <DATASET : "dataset"> |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 3159 | | <COLLECTION : "collection"> |
Yingyi Bu | d56ff03 | 2016-08-01 10:26:57 -0700 | [diff] [blame] | 3160 | | <DATAVERSE : "dataverse"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3161 | | <DECLARE : "declare"> |
| 3162 | | <DEFINITION : "definition"> |
| 3163 | | <DELETE : "delete"> |
| 3164 | | <DESC : "desc"> |
| 3165 | | <DISCONNECT : "disconnect"> |
| 3166 | | <DISTINCT : "distinct"> |
| 3167 | | <DROP : "drop"> |
| 3168 | | <ELEMENT : "element"> |
Till Westmann | 516d1a8 | 2016-08-02 14:45:53 -0700 | [diff] [blame] | 3169 | | <EXPLAIN : "explain"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3170 | | <ELSE : "else"> |
| 3171 | | <ENFORCED : "enforced"> |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame] | 3172 | | <END : "end"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3173 | | <EVERY : "every"> |
| 3174 | | <EXCEPT : "except"> |
| 3175 | | <EXISTS : "exists"> |
| 3176 | | <EXTERNAL : "external"> |
| 3177 | | <FEED : "feed"> |
| 3178 | | <FILTER : "filter"> |
| 3179 | | <FLATTEN : "flatten"> |
| 3180 | | <FOR : "for"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3181 | | <FROM : "from"> |
| 3182 | | <FULL : "full"> |
Taewoo Kim | c49405a | 2017-01-04 00:30:43 -0800 | [diff] [blame] | 3183 | | <FULLTEXT : "fulltext"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3184 | | <FUNCTION : "function"> |
| 3185 | | <GROUP : "group"> |
| 3186 | | <HAVING : "having"> |
| 3187 | | <HINTS : "hints"> |
| 3188 | | <IF : "if"> |
| 3189 | | <INTO : "into"> |
| 3190 | | <IN : "in"> |
| 3191 | | <INDEX : "index"> |
| 3192 | | <INGESTION : "ingestion"> |
| 3193 | | <INNER : "inner"> |
| 3194 | | <INSERT : "insert"> |
| 3195 | | <INTERNAL : "internal"> |
| 3196 | | <INTERSECT : "intersect"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 3197 | | <IS : "is"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3198 | | <JOIN : "join"> |
| 3199 | | <KEYWORD : "keyword"> |
| 3200 | | <KEY : "key"> |
| 3201 | | <LEFT : "left"> |
| 3202 | | <LETTING : "letting"> |
| 3203 | | <LET : "let"> |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 3204 | | <LIKE : "like"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3205 | | <LIMIT : "limit"> |
| 3206 | | <LOAD : "load"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3207 | | <NODEGROUP : "nodegroup"> |
| 3208 | | <NGRAM : "ngram"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 3209 | | <NOT : "not"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3210 | | <OFFSET : "offset"> |
| 3211 | | <ON : "on"> |
| 3212 | | <OPEN : "open"> |
| 3213 | | <OR : "or"> |
| 3214 | | <ORDER : "order"> |
| 3215 | | <OUTER : "outer"> |
| 3216 | | <OUTPUT : "output"> |
| 3217 | | <PATH : "path"> |
| 3218 | | <POLICY : "policy"> |
| 3219 | | <PRESORTED : "pre-sorted"> |
| 3220 | | <PRIMARY : "primary"> |
| 3221 | | <RAW : "raw"> |
| 3222 | | <REFRESH : "refresh"> |
| 3223 | | <RETURN : "return"> |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 3224 | | <RETURNING : "returning"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3225 | | <RTREE : "rtree"> |
| 3226 | | <RUN : "run"> |
| 3227 | | <SATISFIES : "satisfies"> |
| 3228 | | <SECONDARY : "secondary"> |
| 3229 | | <SELECT : "select"> |
| 3230 | | <SET : "set"> |
| 3231 | | <SOME : "some"> |
Abdullah Alamoudi | fff200c | 2017-02-18 20:32:14 -0800 | [diff] [blame] | 3232 | | <START : "start"> |
| 3233 | | <STOP : "stop"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3234 | | <TEMPORARY : "temporary"> |
| 3235 | | <THEN : "then"> |
| 3236 | | <TYPE : "type"> |
| 3237 | | <TO : "to"> |
| 3238 | | <UNION : "union"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 3239 | | <UNKOWN : "unknown"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3240 | | <UNNEST : "unnest"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 3241 | | <UPDATE : "update"> |
Yingyi Bu | cb5bf33 | 2017-01-02 22:19:50 -0800 | [diff] [blame] | 3242 | | <UPSERT : "upsert"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 3243 | | <USE : "use"> |
| 3244 | | <USING : "using"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3245 | | <VALUE : "value"> |
| 3246 | | <WHEN : "when"> |
| 3247 | | <WHERE : "where"> |
| 3248 | | <WITH : "with"> |
| 3249 | | <WRITE : "write"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | <DEFAULT,IN_DBL_BRACE> |
| 3253 | TOKEN : |
| 3254 | { |
| 3255 | <CARET : "^"> |
Yingyi Bu | fdc71eb | 2016-08-24 22:41:57 -0700 | [diff] [blame] | 3256 | | <CONCAT : "||"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3257 | | <DIV : "/"> |
| 3258 | | <IDIV : "idiv"> |
| 3259 | | <MINUS : "-"> |
| 3260 | | <MOD : "%"> |
| 3261 | | <MUL : "*"> |
| 3262 | | <PLUS : "+"> |
| 3263 | |
| 3264 | | <LEFTPAREN : "("> |
| 3265 | | <RIGHTPAREN : ")"> |
| 3266 | | <LEFTBRACKET : "["> |
| 3267 | | <RIGHTBRACKET : "]"> |
| 3268 | |
| 3269 | | <ATT : "@"> |
| 3270 | | <COLON : ":"> |
| 3271 | | <COMMA : ","> |
| 3272 | | <DOT : "."> |
| 3273 | | <QUES : "?"> |
| 3274 | | <SEMICOLON : ";"> |
| 3275 | | <SHARP : "#"> |
| 3276 | |
| 3277 | | <LT : "<"> |
| 3278 | | <GT : ">"> |
| 3279 | | <LE : "<="> |
| 3280 | | <GE : ">="> |
| 3281 | | <EQ : "="> |
| 3282 | | <NE : "!="> |
Yingyi Bu | 4a4b896 | 2016-09-16 12:09:11 -0700 | [diff] [blame] | 3283 | | <LG : "<>"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3284 | | <SIMILAR : "~="> |
| 3285 | } |
| 3286 | |
| 3287 | <DEFAULT,IN_DBL_BRACE> |
| 3288 | TOKEN : |
| 3289 | { |
| 3290 | <LEFTBRACE : "{"> { pushState(); } : DEFAULT |
| 3291 | } |
| 3292 | |
| 3293 | <DEFAULT> |
| 3294 | TOKEN : |
| 3295 | { |
| 3296 | <RIGHTBRACE : "}"> { popState("}"); } |
| 3297 | } |
| 3298 | |
| 3299 | <DEFAULT,IN_DBL_BRACE> |
| 3300 | TOKEN : |
| 3301 | { |
| 3302 | <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE |
| 3303 | } |
| 3304 | |
| 3305 | <IN_DBL_BRACE> |
| 3306 | TOKEN : |
| 3307 | { |
| 3308 | <RIGHTDBLBRACE : "}}"> { popState("}}"); } |
| 3309 | } |
| 3310 | |
| 3311 | <DEFAULT,IN_DBL_BRACE> |
| 3312 | TOKEN : |
| 3313 | { |
| 3314 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 3315 | } |
| 3316 | |
| 3317 | <DEFAULT,IN_DBL_BRACE> |
Yingyi Bu | e311a63 | 2016-06-07 18:23:16 -0700 | [diff] [blame] | 3318 | TOKEN [IGNORE_CASE]: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3319 | { |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 3320 | <MISSING : "missing"> |
| 3321 | | <NULL : "null"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3322 | | <TRUE : "true"> |
| 3323 | | <FALSE : "false"> |
| 3324 | } |
| 3325 | |
| 3326 | <DEFAULT,IN_DBL_BRACE> |
| 3327 | TOKEN : |
| 3328 | { |
| 3329 | <#DIGIT : ["0" - "9"]> |
| 3330 | } |
| 3331 | |
| 3332 | <DEFAULT,IN_DBL_BRACE> |
| 3333 | TOKEN: |
| 3334 | { |
Yingyi Bu | e4d919e | 2016-10-30 10:47:03 -0700 | [diff] [blame] | 3335 | < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) |
| 3336 | | "." <DIGITS> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3337 | > |
Yingyi Bu | e4d919e | 2016-10-30 10:47:03 -0700 | [diff] [blame] | 3338 | | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" ) |
| 3339 | | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )? |
| 3340 | | "." <DIGITS> ( "f" | "F" ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3341 | > |
| 3342 | | <DIGITS : (<DIGIT>)+ > |
| 3343 | } |
| 3344 | |
| 3345 | <DEFAULT,IN_DBL_BRACE> |
| 3346 | TOKEN : |
| 3347 | { |
| 3348 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 3349 | | <SPECIALCHARS : ["$", "_"]> |
| 3350 | } |
| 3351 | |
| 3352 | <DEFAULT,IN_DBL_BRACE> |
| 3353 | TOKEN : |
| 3354 | { |
| 3355 | // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3356 | <QUOTED_STRING : "`" ( |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3357 | <EscapeQuot> |
| 3358 | | <EscapeBslash> |
| 3359 | | <EscapeSlash> |
| 3360 | | <EscapeBspace> |
| 3361 | | <EscapeFormf> |
| 3362 | | <EscapeNl> |
| 3363 | | <EscapeCr> |
| 3364 | | <EscapeTab> |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3365 | | ~["`","\\"])* "`"> |
| 3366 | | <STRING_LITERAL : ("\"" ( |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3367 | <EscapeQuot> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3368 | | <EscapeBslash> |
| 3369 | | <EscapeSlash> |
| 3370 | | <EscapeBspace> |
| 3371 | | <EscapeFormf> |
| 3372 | | <EscapeNl> |
| 3373 | | <EscapeCr> |
| 3374 | | <EscapeTab> |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3375 | | ~["\"","\\"])* "\"") |
| 3376 | | ("\'"( |
| 3377 | <EscapeApos> |
| 3378 | | <EscapeBslash> |
| 3379 | | <EscapeSlash> |
| 3380 | | <EscapeBspace> |
| 3381 | | <EscapeFormf> |
| 3382 | | <EscapeNl> |
| 3383 | | <EscapeCr> |
| 3384 | | <EscapeTab> |
| 3385 | | ~["\'","\\"])* "\'")> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3386 | | < #EscapeQuot: "\\\"" > |
| 3387 | | < #EscapeApos: "\\\'" > |
| 3388 | | < #EscapeBslash: "\\\\" > |
| 3389 | | < #EscapeSlash: "\\/" > |
| 3390 | | < #EscapeBspace: "\\b" > |
| 3391 | | < #EscapeFormf: "\\f" > |
| 3392 | | < #EscapeNl: "\\n" > |
| 3393 | | < #EscapeCr: "\\r" > |
| 3394 | | < #EscapeTab: "\\t" > |
| 3395 | } |
| 3396 | |
| 3397 | <DEFAULT,IN_DBL_BRACE> |
| 3398 | TOKEN : |
| 3399 | { |
| 3400 | <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 3401 | } |
| 3402 | |
| 3403 | <DEFAULT,IN_DBL_BRACE> |
| 3404 | SKIP: |
| 3405 | { |
| 3406 | " " |
| 3407 | | "\t" |
| 3408 | | "\r" |
| 3409 | | "\n" |
| 3410 | } |
| 3411 | |
| 3412 | <DEFAULT,IN_DBL_BRACE> |
| 3413 | SKIP: |
| 3414 | { |
| 3415 | <"//" (~["\n"])* "\n"> |
| 3416 | } |
| 3417 | |
| 3418 | <DEFAULT,IN_DBL_BRACE> |
| 3419 | SKIP: |
| 3420 | { |
| 3421 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 3422 | } |
| 3423 | |
| 3424 | <DEFAULT,IN_DBL_BRACE> |
| 3425 | SKIP: |
| 3426 | { |
Yingyi Bu | 93846a7 | 2016-09-13 16:30:39 -0700 | [diff] [blame] | 3427 | <"--" (~["\n"])* "\n"> |
| 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | <DEFAULT,IN_DBL_BRACE> |
| 3432 | SKIP: |
| 3433 | { |
| 3434 | <"--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 3435 | } |
| 3436 | |
| 3437 | <DEFAULT,IN_DBL_BRACE> |
| 3438 | SKIP: |
| 3439 | { |
| 3440 | <"#" (~["\n"])* "\n"> |
| 3441 | } |
| 3442 | |
| 3443 | |
| 3444 | <DEFAULT,IN_DBL_BRACE> |
| 3445 | SKIP: |
| 3446 | { |
| 3447 | <"#" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 3448 | } |
| 3449 | |
| 3450 | <DEFAULT,IN_DBL_BRACE> |
| 3451 | SKIP: |
| 3452 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3453 | <"/*"> { pushState(); } : INSIDE_COMMENT |
| 3454 | } |
| 3455 | |
| 3456 | <INSIDE_COMMENT> |
| 3457 | SPECIAL_TOKEN: |
| 3458 | { |
| 3459 | <"+"(" ")*(~["*"])*> |
| 3460 | } |
| 3461 | |
| 3462 | <INSIDE_COMMENT> |
| 3463 | SKIP: |
| 3464 | { |
| 3465 | <"/*"> { pushState(); } |
| 3466 | } |
| 3467 | |
| 3468 | <INSIDE_COMMENT> |
| 3469 | SKIP: |
| 3470 | { |
| 3471 | <"*/"> { popState("*/"); } |
| 3472 | | <~[]> |
| 3473 | } |