Ian Maxon | 032a178 | 2015-06-30 17:10:51 -0700 | [diff] [blame] | 1 | /* |
Ian Maxon | 928bbd1 | 2015-09-14 17:12:48 -0700 | [diff] [blame] | 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 |
Ian Maxon | 032a178 | 2015-06-30 17:10:51 -0700 | [diff] [blame] | 9 | * |
Ian Maxon | 928bbd1 | 2015-09-14 17:12:48 -0700 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Ian Maxon | 032a178 | 2015-06-30 17:10:51 -0700 | [diff] [blame] | 11 | * |
Ian Maxon | 928bbd1 | 2015-09-14 17:12:48 -0700 | [diff] [blame] | 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. |
Ian Maxon | 032a178 | 2015-06-30 17:10:51 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
genia.likes.science@gmail.com | b91b577a | 2013-06-13 14:36:06 -0700 | [diff] [blame] | 20 | function AsterixDBConnection(configuration) { |
| 21 | this._properties = {}; |
| 22 | this._properties["dataverse"] = ""; |
| 23 | this._properties["mode"] = "synchronous"; |
| 24 | |
| 25 | var configuration = arguments || {}; |
| 26 | |
| 27 | for (var key in configuration) { |
| 28 | this._properties[key] = configuration[key]; |
| 29 | } |
| 30 | |
| 31 | return this; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | AsterixDBConnection.prototype.dataverse = function(dataverseName) { |
| 36 | this._properties["dataverse"] = dataverseName; |
| 37 | |
| 38 | return this; |
| 39 | }; |
| 40 | |
| 41 | |
genia.likes.science@gmail.com | 4a5dfe1 | 2013-07-05 07:10:00 -0700 | [diff] [blame] | 42 | AsterixDBConnection.prototype.query = function(statements, successFn, mode) { |
genia.likes.science@gmail.com | 3395d5b | 2013-07-05 00:47:11 -0700 | [diff] [blame] | 43 | |
genia.likes.science@gmail.com | b91b577a | 2013-06-13 14:36:06 -0700 | [diff] [blame] | 44 | if ( typeof statements === 'string') { |
| 45 | statements = [ statements ]; |
| 46 | } |
| 47 | |
genia.likes.science@gmail.com | 212a644 | 2013-07-13 20:40:11 -0700 | [diff] [blame] | 48 | var m = typeof mode ? mode : "synchronous"; |
| 49 | |
genia.likes.science@gmail.com | 78593d7 | 2013-07-02 06:33:39 -0700 | [diff] [blame] | 50 | var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n"); |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 51 | |
genia.likes.science@gmail.com | 3395d5b | 2013-07-05 00:47:11 -0700 | [diff] [blame] | 52 | this._api( |
| 53 | { |
genia.likes.science@gmail.com | b91b577a | 2013-06-13 14:36:06 -0700 | [diff] [blame] | 54 | "query" : query, |
genia.likes.science@gmail.com | 4a5dfe1 | 2013-07-05 07:10:00 -0700 | [diff] [blame] | 55 | "mode" : m |
genia.likes.science@gmail.com | b91b577a | 2013-06-13 14:36:06 -0700 | [diff] [blame] | 56 | }, |
genia.likes.science@gmail.com | 3395d5b | 2013-07-05 00:47:11 -0700 | [diff] [blame] | 57 | successFn, |
| 58 | "http://localhost:19002/query" |
| 59 | ); |
genia.likes.science@gmail.com | b91b577a | 2013-06-13 14:36:06 -0700 | [diff] [blame] | 60 | |
| 61 | return this; |
| 62 | }; |
| 63 | |
| 64 | |
genia.likes.science@gmail.com | 4a5dfe1 | 2013-07-05 07:10:00 -0700 | [diff] [blame] | 65 | AsterixDBConnection.prototype.query_status = function(data, successFn) { |
| 66 | |
| 67 | this._api( |
| 68 | data, |
| 69 | successFn, |
| 70 | "http://localhost:19002/query/status" |
| 71 | ); |
| 72 | |
| 73 | return this; |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | AsterixDBConnection.prototype.query_result = function(data, successFn) { |
| 78 | this._api( |
| 79 | data, |
| 80 | successFn, |
| 81 | "http://localhost:19002/query/result" |
| 82 | ); |
| 83 | |
| 84 | return this; |
| 85 | }; |
| 86 | |
genia.likes.science@gmail.com | 6686c45 | 2013-07-05 08:39:35 -0700 | [diff] [blame] | 87 | |
| 88 | AsterixDBConnection.prototype.ddl = function(statements, successFn) { |
| 89 | if ( typeof statements === 'string') { |
| 90 | statements = [ statements ]; |
| 91 | } |
| 92 | |
| 93 | this._api( |
| 94 | { |
| 95 | "ddl" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n") |
| 96 | }, |
| 97 | successFn, |
| 98 | "http://localhost:19002/ddl" |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | AsterixDBConnection.prototype.update = function(statements, successFn) { |
| 104 | if ( typeof statements === 'string') { |
| 105 | statements = [ statements ]; |
| 106 | } |
| 107 | |
| 108 | this._api( |
| 109 | { |
| 110 | "statements" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n") |
| 111 | }, |
| 112 | successFn, |
| 113 | "http://localhost:19002/update" |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | |
genia.likes.science@gmail.com | 3395d5b | 2013-07-05 00:47:11 -0700 | [diff] [blame] | 118 | AsterixDBConnection.prototype._api = function(json, onSuccess, endpoint) { |
| 119 | var success_fn = onSuccess; |
| 120 | |
| 121 | $.ajax({ |
| 122 | type: 'GET', |
| 123 | url: endpoint, |
| 124 | data : json, |
| 125 | dataType: "json", |
| 126 | success: function(data) { |
| 127 | success_fn(data); |
| 128 | } |
| 129 | // TODO error: |
| 130 | }); |
| 131 | |
| 132 | return this; |
| 133 | }; |
| 134 | |
| 135 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 136 | function AExpression () { |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 137 | |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 138 | this._properties = {}; |
| 139 | this._success = function() {}; |
| 140 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 141 | if (typeof arguments[0] == 'string') { |
| 142 | this._properties["value"] = arguments[0]; |
| 143 | } |
| 144 | |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 145 | return this; |
| 146 | } |
| 147 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 148 | |
| 149 | AExpression.prototype.bind = function(options) { |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 150 | var options = options || {}; |
| 151 | |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 152 | if (options.hasOwnProperty("success")) { |
| 153 | this._success = options["success"]; |
| 154 | } |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 155 | |
| 156 | if (options.hasOwnProperty("return")) { |
| 157 | this._properties["return"] = " return " + options["return"].val(); |
| 158 | } |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 161 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 162 | AExpression.prototype.run = function(successFn) { |
genia.likes.science@gmail.com | 512454d | 2013-05-28 03:32:20 -0700 | [diff] [blame] | 163 | return this; |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | |
| 167 | AExpression.prototype.val = function() { |
| 168 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 169 | var value = ""; |
| 170 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 171 | // If there is a dataverse defined, provide it. |
| 172 | if (this._properties.hasOwnProperty("dataverse")) { |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 173 | value += "use dataverse " + this._properties["dataverse"] + ";\n"; |
| 174 | }; |
| 175 | |
| 176 | if (this._properties.hasOwnProperty("value")) { |
| 177 | value += this._properties["value"]; |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 178 | } |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 179 | |
| 180 | return value; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 183 | // @param expressionValue [String] |
| 184 | AExpression.prototype.set = function(expressionValue) { |
| 185 | this._properties["value"] = expressionValue; |
| 186 | return this; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 189 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 190 | // FunctionExpression |
| 191 | // Parent: AsterixExpression |
| 192 | // |
| 193 | // @param options [Various], |
| 194 | // @key function [String], a function to be applid to the expression |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 195 | // @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied |
| 196 | function FunctionExpression() { |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 197 | |
| 198 | // Initialize superclass |
| 199 | AExpression.call(this); |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 200 | |
| 201 | this._properties["function"] = ""; |
| 202 | this._properties["expression"] = new AExpression().set(""); |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 203 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 204 | // Check for fn/expression input |
| 205 | if (arguments.length == 2 && typeof arguments[0] == "string" && |
| 206 | (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) { |
| 207 | |
| 208 | this._properties["function"] = arguments[0]; |
| 209 | this._properties["expression"] = arguments[1]; |
| 210 | |
| 211 | } |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 212 | |
| 213 | // Return object |
| 214 | return this; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | FunctionExpression.prototype = Object.create(AExpression.prototype); |
| 219 | FunctionExpression.prototype.constructor = FunctionExpression; |
| 220 | |
| 221 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 222 | FunctionExpression.prototype.fn = function(fnName) { |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 223 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 224 | if (typeof fnName == "string") { |
| 225 | this._properties["function"] = fnName; |
| 226 | } |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 227 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 228 | return this; |
| 229 | }; |
| 230 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 231 | |
| 232 | FunctionExpression.prototype.expression = function(expression) { |
| 233 | if (expression instanceof AExpression || expression instanceof AQLClause) { |
| 234 | this._properties["expression"] = expression; |
| 235 | } |
| 236 | |
| 237 | return this; |
| 238 | }; |
| 239 | |
| 240 | |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 241 | FunctionExpression.prototype.val = function () { |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 242 | return this._properties["function"] + "(" + this._properties["expression"].val() + ")"; |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 245 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 246 | // FLWOGRExpression |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 247 | // |
| 248 | // FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 249 | function FLWOGRExpression (options) { |
| 250 | // Initialize superclass |
| 251 | AExpression.call(this); |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 252 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 253 | this._properties["clauses"] = []; |
genia.likes.science@gmail.com | 79e603a | 2013-05-31 10:03:23 -0700 | [diff] [blame] | 254 | this._properties["minSize"] = 0; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 255 | |
| 256 | // Bind options and return |
| 257 | this.bind(options); |
| 258 | return this; |
genia.likes.science@gmail.com | 90d0872 | 2013-05-28 04:40:12 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 262 | FLWOGRExpression.prototype = Object.create(AExpression.prototype); |
| 263 | FLWOGRExpression.prototype.constructor = FLWOGRExpression; |
| 264 | |
| 265 | |
| 266 | FLWOGRExpression.prototype.bind = function(options) { |
| 267 | AExpression.prototype.bind.call(this, options); |
| 268 | |
| 269 | var options = options || {}; |
| 270 | |
genia.likes.science@gmail.com | 79e603a | 2013-05-31 10:03:23 -0700 | [diff] [blame] | 271 | if (options instanceof SetStatement) { |
| 272 | this._properties["clauses"].push(options); |
| 273 | this._properties["minSize"] += 1; |
| 274 | } |
| 275 | |
| 276 | if (this._properties["clauses"].length <= this._properties["minSize"]) { |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 277 | // Needs to start with for or let clause |
| 278 | if (options instanceof ForClause || options instanceof LetClause) { |
| 279 | this._properties["clauses"].push(options); |
| 280 | } |
| 281 | } else { |
| 282 | if (options instanceof AQLClause) { |
| 283 | this._properties["clauses"].push(options); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | return this; |
| 288 | }; |
| 289 | |
| 290 | |
| 291 | FLWOGRExpression.prototype.val = function() { |
| 292 | var value = AExpression.prototype.val.call(this); |
| 293 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 294 | var clauseValues = []; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 295 | for (var c in this._properties["clauses"]) { |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 296 | clauseValues.push(this._properties["clauses"][c].val()); |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 297 | } |
| 298 | |
genia.likes.science@gmail.com | 79e603a | 2013-05-31 10:03:23 -0700 | [diff] [blame] | 299 | return value + clauseValues.join("\n");// + ";"; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 302 | // Pretty Expression Shorthand |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 303 | |
genia.likes.science@gmail.com | 5f42534 | 2013-06-13 13:51:26 -0700 | [diff] [blame] | 304 | FLWOGRExpression.prototype.ReturnClause = function(expression) { |
| 305 | return this.bind(new ReturnClause(expression)); |
| 306 | }; |
| 307 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 308 | FLWOGRExpression.prototype.ForClause = function() { |
| 309 | return this.bind(new ForClause(Array.prototype.slice.call(arguments))); |
| 310 | }; |
| 311 | |
| 312 | FLWOGRExpression.prototype.LetClause = function() { |
| 313 | return this.bind(new LetClause(Array.prototype.slice.call(arguments))); |
| 314 | }; |
| 315 | |
| 316 | FLWOGRExpression.prototype.WhereClause = function() { |
| 317 | return this.bind(new WhereClause(Array.prototype.slice.call(arguments))); |
| 318 | }; |
| 319 | |
| 320 | FLWOGRExpression.prototype.and = function() { |
| 321 | var args = Array.prototype.slice.call(arguments); |
| 322 | args.push(true); |
| 323 | return this.bind(new WhereClause().and(args)); |
| 324 | }; |
| 325 | |
| 326 | FLWOGRExpression.prototype.or = function() { |
| 327 | var args = Array.prototype.slice.call(arguments); |
| 328 | args.push(true); |
| 329 | return this.bind(new WhereClause().or(args)); |
| 330 | }; |
| 331 | |
| 332 | FLWOGRExpression.prototype.OrderbyClause = function() { |
| 333 | return this.bind(new OrderbyClause(Array.prototype.slice.call(arguments))); |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | FLWOGRExpression.prototype.GroupClause = function() { |
| 338 | return this.bind(new GroupClause(Array.prototype.slice.call(arguments))); |
| 339 | }; |
| 340 | |
| 341 | FLWOGRExpression.prototype.LimitClause = function() { |
| 342 | return this.bind(new LimitClause(Array.prototype.slice.call(arguments))); |
| 343 | }; |
| 344 | |
| 345 | FLWOGRExpression.prototype.DistinctClause = function() { |
| 346 | return this.bind(new DistinctClause(Array.prototype.slice.call(arguments))); |
| 347 | }; |
| 348 | |
| 349 | FLWOGRExpression.prototype.AQLClause = function() { |
| 350 | return this.bind(new AQLClause(Array.prototype.slice.call(arguments))); |
| 351 | }; |
| 352 | |
| 353 | |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 354 | // AQLClause |
| 355 | // |
| 356 | // Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause |
| 357 | function AQLClause() { |
| 358 | this._properties = {}; |
| 359 | this._properties["clause"] = ""; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 360 | this._properties["stack"] = []; |
| 361 | if (typeof arguments[0] == 'string') { |
| 362 | this._properties["clause"] = arguments[0]; |
| 363 | } |
| 364 | return this; |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | AQLClause.prototype.val = function() { |
| 368 | var value = this._properties["clause"]; |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 369 | |
| 370 | return value; |
| 371 | }; |
| 372 | |
| 373 | AQLClause.prototype.bind = function(options) { |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 374 | |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 375 | if (options instanceof AQLClause) { |
| 376 | this._properties["clause"] += " " + options.val(); |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | return this; |
| 380 | }; |
| 381 | |
genia.likes.science@gmail.com | 3957830 | 2013-05-31 04:42:26 -0700 | [diff] [blame] | 382 | AQLClause.prototype.set = function(value) { |
| 383 | this._properties["clause"] = value; |
| 384 | return this; |
| 385 | }; |
| 386 | |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 387 | |
| 388 | // ForClause |
| 389 | // |
| 390 | // Grammar: |
| 391 | // "for" Variable ( "at" Variable )? "in" ( Expression ) |
| 392 | // |
| 393 | // @param for_variable [String], REQUIRED, first variable in clause |
| 394 | // @param at_variable [String], NOT REQUIRED, first variable in clause |
| 395 | // @param expression [AsterixExpression], REQUIRED, expression to evaluate |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 396 | function ForClause(for_variable, at_variable, expression) { |
| 397 | AQLClause.call(this); |
| 398 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 399 | var parameters = []; |
| 400 | if (arguments[0] instanceof Array) { |
| 401 | parameters = arguments[0]; |
| 402 | } else { |
| 403 | parameters = arguments; |
| 404 | } |
| 405 | |
| 406 | this._properties["clause"] = "for " + parameters[0]; |
genia.likes.science@gmail.com | f8cca19 | 2013-06-13 15:45:53 -0700 | [diff] [blame] | 407 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 408 | if (parameters.length == 3) { |
| 409 | this._properties["clause"] += " at " + parameters[1]; |
| 410 | this._properties["clause"] += " in " + parameters[2].val(); |
| 411 | } else if (parameters.length == 2) { |
| 412 | this._properties["clause"] += " in " + parameters[1].val(); |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 413 | } |
genia.likes.science@gmail.com | f8cca19 | 2013-06-13 15:45:53 -0700 | [diff] [blame] | 414 | |
genia.likes.science@gmail.com | 73dcc70 | 2013-05-28 04:21:28 -0700 | [diff] [blame] | 415 | return this; |
| 416 | } |
| 417 | |
| 418 | ForClause.prototype = Object.create(AQLClause.prototype); |
| 419 | ForClause.prototype.constructor = ForClause; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 420 | |
| 421 | |
| 422 | // LetClause |
| 423 | // |
| 424 | // Grammar: |
| 425 | // LetClause ::= "let" Variable ":=" Expression |
| 426 | // |
| 427 | // @param let_variable [String] |
| 428 | // @param expression [AExpression] |
| 429 | // |
| 430 | // TODO Vigorous error checking |
| 431 | function LetClause(let_variable, expression) { |
| 432 | AQLClause.call(this); |
| 433 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 434 | var parameters = []; |
| 435 | if (arguments[0] instanceof Array) { |
| 436 | parameters = arguments[0]; |
| 437 | } else { |
| 438 | parameters = arguments; |
| 439 | } |
| 440 | |
| 441 | this._properties["clause"] = "let " + parameters[0] + " := "; |
| 442 | this._properties["clause"] += parameters[1].val(); |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 443 | |
| 444 | return this; |
| 445 | } |
| 446 | |
| 447 | LetClause.prototype = Object.create(AQLClause.prototype); |
| 448 | LetClause.prototype.constructor = LetClause; |
| 449 | |
| 450 | |
genia.likes.science@gmail.com | 5ca104c | 2013-05-29 05:39:26 -0700 | [diff] [blame] | 451 | // ReturnClause |
| 452 | // |
| 453 | // Grammar: |
| 454 | // return [AQLExpression] |
| 455 | function ReturnClause(expression) { |
| 456 | AQLClause.call(this); |
| 457 | |
| 458 | this._properties["clause"] = "return "; |
genia.likes.science@gmail.com | 5749ef9 | 2013-06-12 07:59:25 -0700 | [diff] [blame] | 459 | |
genia.likes.science@gmail.com | 79e603a | 2013-05-31 10:03:23 -0700 | [diff] [blame] | 460 | if (expression instanceof AExpression || expression instanceof AQLClause) { |
genia.likes.science@gmail.com | 5ca104c | 2013-05-29 05:39:26 -0700 | [diff] [blame] | 461 | this._properties["clause"] += expression.val(); |
genia.likes.science@gmail.com | 5749ef9 | 2013-06-12 07:59:25 -0700 | [diff] [blame] | 462 | |
| 463 | } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) { |
| 464 | |
| 465 | // TODO Null object check |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 466 | |
| 467 | this._properties["clause"] += "{"; |
| 468 | var returnStatements = []; |
| 469 | for (returnValue in expression) { |
| 470 | |
| 471 | if (expression[returnValue] instanceof AExpression) { |
genia.likes.science@gmail.com | fba7cc8 | 2013-05-31 04:04:08 -0700 | [diff] [blame] | 472 | returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val()); |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 473 | } else if (typeof expression[returnValue] == "string") { |
genia.likes.science@gmail.com | fba7cc8 | 2013-05-31 04:04:08 -0700 | [diff] [blame] | 474 | returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]); |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | this._properties["clause"] += returnStatements.join(",\n"); |
genia.likes.science@gmail.com | f7929d8 | 2013-06-12 11:30:01 -0700 | [diff] [blame] | 478 | this._properties["clause"] += "\n}"; |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 479 | |
genia.likes.science@gmail.com | 5ca104c | 2013-05-29 05:39:26 -0700 | [diff] [blame] | 480 | } else { |
genia.likes.science@gmail.com | 5749ef9 | 2013-06-12 07:59:25 -0700 | [diff] [blame] | 481 | this._properties["clause"] += new AQLClause().set(expression).val(); |
genia.likes.science@gmail.com | 5ca104c | 2013-05-29 05:39:26 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | return this; |
| 485 | } |
| 486 | |
genia.likes.science@gmail.com | 5749ef9 | 2013-06-12 07:59:25 -0700 | [diff] [blame] | 487 | |
genia.likes.science@gmail.com | 5ca104c | 2013-05-29 05:39:26 -0700 | [diff] [blame] | 488 | ReturnClause.prototype = Object.create(AQLClause.prototype); |
| 489 | ReturnClause.prototype.constructor = ReturnClause; |
| 490 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 491 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 492 | // WhereClause |
| 493 | // |
| 494 | // Grammar: |
| 495 | // ::= "where" Expression |
| 496 | // |
| 497 | // @param expression [BooleanExpression], pushes this expression onto the stack |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 498 | function WhereClause(expression) { |
| 499 | AQLClause.call(this); |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 500 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 501 | this._properties["stack"] = []; |
| 502 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 503 | if (expression instanceof Array) { |
| 504 | this.bind(expression[0]); |
| 505 | } else { |
| 506 | this.bind(expression); |
| 507 | } |
| 508 | |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 509 | return this; |
| 510 | } |
| 511 | |
| 512 | |
| 513 | WhereClause.prototype = Object.create(AQLClause.prototype); |
| 514 | WhereClause.prototype.constructor = WhereClause; |
| 515 | |
| 516 | |
| 517 | WhereClause.prototype.bind = function(expression) { |
genia.likes.science@gmail.com | 64ca88e | 2013-05-31 10:40:39 -0700 | [diff] [blame] | 518 | if (expression instanceof AExpression) { |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 519 | this._properties["stack"].push(expression); |
| 520 | } |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 521 | return this; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | |
| 525 | WhereClause.prototype.val = function() { |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 526 | var value = ""; |
| 527 | |
| 528 | if (this._properties["stack"].length == 0) { |
| 529 | return value; |
| 530 | } |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 531 | |
| 532 | var count = this._properties["stack"].length - 1; |
| 533 | while (count >= 0) { |
| 534 | value += this._properties["stack"][count].val() + " "; |
| 535 | count -= 1; |
| 536 | } |
| 537 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 538 | return "where " + value; |
genia.likes.science@gmail.com | 64ca88e | 2013-05-31 10:40:39 -0700 | [diff] [blame] | 539 | }; |
genia.likes.science@gmail.com | 3861263 | 2013-05-28 13:11:52 -0700 | [diff] [blame] | 540 | |
| 541 | |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 542 | WhereClause.prototype.and = function() { |
| 543 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 544 | var parameters = []; |
| 545 | if (arguments[0] instanceof Array) { |
| 546 | parameters = arguments[0]; |
| 547 | } else { |
| 548 | parameters = arguments; |
| 549 | } |
| 550 | |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 551 | var andClauses = []; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 552 | for (var expression in parameters) { |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 553 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 554 | if (parameters[expression] instanceof AExpression) { |
| 555 | andClauses.push(parameters[expression].val()); |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
| 559 | if (andClauses.length > 0) { |
| 560 | this._properties["stack"].push(new AExpression().set(andClauses.join(" and "))); |
| 561 | } |
| 562 | |
| 563 | return this; |
| 564 | }; |
| 565 | |
| 566 | |
| 567 | WhereClause.prototype.or = function() { |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 568 | |
| 569 | var parameters = []; |
| 570 | if (arguments[0] instanceof Array) { |
| 571 | parameters = arguments[0]; |
| 572 | } else { |
| 573 | parameters = arguments; |
| 574 | } |
| 575 | |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 576 | var orClauses = []; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 577 | for (var expression in parameters) { |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 578 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 579 | if (parameters[expression] instanceof AExpression) { |
| 580 | orClauses.push(parameters[expression].val()); |
genia.likes.science@gmail.com | d2f753e | 2013-06-12 13:51:03 -0700 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
| 584 | if (andClauses.length > 0) { |
| 585 | this._properties["stack"].push(new AExpression().set(orClauses.join(" and "))); |
| 586 | } |
| 587 | |
| 588 | return this; |
| 589 | }; |
| 590 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 591 | // LimitClause |
| 592 | // Grammar: |
| 593 | // LimitClause ::= "limit" Expression ( "offset" Expression )? |
| 594 | // |
| 595 | // @param limitExpression [REQUIRED, AQLExpression] |
| 596 | // @param offsetExpression [OPTIONAL, AQLExpression] |
| 597 | function LimitClause(limitExpression, offsetExpression) { |
| 598 | |
| 599 | AQLClause.call(this); |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 600 | |
| 601 | var parameters = []; |
| 602 | if (arguments[0] instanceof Array) { |
| 603 | parameters = arguments[0]; |
| 604 | } else { |
| 605 | parameters = arguments; |
| 606 | } |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 607 | |
| 608 | // limitExpression required |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 609 | this._properties["clause"] = "limit " + parameters[0].val(); |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 610 | |
| 611 | // Optional: Offset |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 612 | if (parameters.length == 2) { |
| 613 | this._properties["clause"] += " offset " + parameters[1].val(); |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | return this; |
| 617 | } |
| 618 | |
| 619 | LimitClause.prototype = Object.create(AQLClause.prototype); |
| 620 | LimitClause.prototype.constructor = LimitClause; |
| 621 | |
| 622 | |
| 623 | // OrderbyClause |
| 624 | // |
| 625 | // Grammar: |
| 626 | // OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )* |
| 627 | // |
| 628 | // @params AQLExpressions and asc/desc strings, in any quantity. At least one required. |
| 629 | function OrderbyClause() { |
| 630 | |
| 631 | AQLClause.call(this); |
| 632 | |
| 633 | // At least one argument expression is required, and first should be expression |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 634 | if (arguments.length == 0) { |
genia.likes.science@gmail.com | 18f3bf2 | 2013-06-12 07:45:02 -0700 | [diff] [blame] | 635 | |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 636 | alert("Order By Error"); |
| 637 | this._properties["clause"] = null; |
| 638 | return this; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | var parameters = []; |
| 642 | if (arguments[0] instanceof Array) { |
| 643 | parameters = arguments[0]; |
| 644 | } else { |
| 645 | parameters = arguments; |
| 646 | } |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 647 | |
| 648 | var expc = 0; |
| 649 | var expressions = []; |
| 650 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 651 | while (expc < parameters.length) { |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 652 | |
| 653 | var expression = ""; |
| 654 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 655 | if (parameters[expc] instanceof AExpression) { |
| 656 | expression += parameters[expc].val(); |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | var next = expc + 1; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 660 | if (next < parameters.length && (parameters[next] == "asc" || parameters[next] == "desc")) { |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 661 | expc++; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 662 | expression += " " + parameters[expc]; |
genia.likes.science@gmail.com | 2ba3224 | 2013-05-31 03:10:48 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | expressions.push(expression); |
| 666 | |
| 667 | expc++; |
| 668 | } |
| 669 | |
| 670 | this._properties["clause"] = "order by " + expressions.join(", "); |
| 671 | return this; |
| 672 | } |
| 673 | |
| 674 | OrderbyClause.prototype = Object.create(AQLClause.prototype); |
| 675 | OrderbyClause.prototype.constructor = OrderbyClause; |
| 676 | |
| 677 | |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 678 | // GroupClause |
| 679 | // |
| 680 | // Grammar: |
| 681 | // GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )* |
| 682 | function GroupClause() { |
| 683 | AQLClause.call(this); |
| 684 | |
| 685 | if (arguments.length == 0) { |
| 686 | // TODO Not sure which error to throw for an empty GroupBy but this should fail. |
| 687 | alert("Group Error"); |
| 688 | this._properties["clause"] = null; |
| 689 | return this; |
| 690 | } |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 691 | |
| 692 | var parameters = []; |
| 693 | if (arguments[0] instanceof Array) { |
| 694 | parameters = arguments[0]; |
| 695 | } else { |
| 696 | parameters = arguments; |
| 697 | } |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 698 | |
| 699 | var expc = 0; |
| 700 | var expressions = []; |
| 701 | var variableRefs = []; |
| 702 | var isDecor = false; |
genia.likes.science@gmail.com | 5f42534 | 2013-06-13 13:51:26 -0700 | [diff] [blame] | 703 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 704 | while (expc < parameters.length) { |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 705 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 706 | if (parameters[expc] instanceof AExpression) { |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 707 | |
| 708 | isDecor = false; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 709 | expressions.push(parameters[expc].val()); |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 710 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 711 | } else if (typeof parameters[expc] == "string") { |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 712 | |
| 713 | // Special keywords, decor & with |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 714 | if (parameters[expc] == "decor") { |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 715 | isDecor = true; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 716 | } else if (parameters[expc] == "with") { |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 717 | isDecor = false; |
| 718 | expc++; |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 719 | while (expc < parameters.length) { |
| 720 | variableRefs.push(parameters[expc]); |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 721 | expc++; |
| 722 | } |
| 723 | |
| 724 | // Variables and variable refs |
| 725 | } else { |
| 726 | |
| 727 | var nextc = expc + 1; |
| 728 | var expression = ""; |
| 729 | |
| 730 | if (isDecor) { |
| 731 | expression += "decor "; |
| 732 | isDecor = false; |
| 733 | } |
| 734 | |
genia.likes.science@gmail.com | d2795fb | 2013-07-14 15:48:04 -0700 | [diff] [blame] | 735 | expression += parameters[expc] + " := " + parameters[nextc].val(); |
genia.likes.science@gmail.com | 6e39291 | 2013-05-31 03:46:59 -0700 | [diff] [blame] | 736 | expressions.push(expression); |
| 737 | expc++; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | expc++; |
| 742 | } |
| 743 | |
| 744 | this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", "); |
| 745 | return this; |
| 746 | } |
| 747 | |
| 748 | GroupClause.prototype = Object.create(AQLClause.prototype); |
| 749 | GroupClause.prototype.constructor = GroupClause; |
| 750 | |
genia.likes.science@gmail.com | 79e603a | 2013-05-31 10:03:23 -0700 | [diff] [blame] | 751 | |
| 752 | // SetStatement |
| 753 | // |
| 754 | // Grammar |
| 755 | // "set" Identifier StringLiteral |
| 756 | function SetStatement (identifier, stringLiteral) { |
| 757 | AExpression.call(this); |
| 758 | |
| 759 | var statement = "set " + identifier + ' "' + stringLiteral + '";'; |
| 760 | |
| 761 | AExpression.prototype.set.call(this, statement); |
| 762 | |
| 763 | return this; |
| 764 | } |
| 765 | |
| 766 | SetStatement.prototype = Object.create(AExpression.prototype); |
| 767 | SetStatement.prototype.constructor = SetStatement; |
genia.likes.science@gmail.com | e34c57b | 2013-05-31 10:15:49 -0700 | [diff] [blame] | 768 | |
| 769 | |
| 770 | // Quantified Expression |
| 771 | // |
| 772 | // Grammar |
| 773 | // QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression |
| 774 | // |
| 775 | // @param String some/every |
| 776 | // @param [AExpression] |
| 777 | // @param [Aexpression] satisfiesExpression |
| 778 | function QuantifiedExpression (keyword, expressions, satisfiesExpression) { |
| 779 | AExpression.call(this); |
| 780 | |
| 781 | var expression = keyword + " "; |
| 782 | var varsInExpressions = []; |
| 783 | |
| 784 | for (var varInExpression in expressions) { |
| 785 | varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val()); |
| 786 | } |
| 787 | expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val(); |
| 788 | |
| 789 | AExpression.prototype.set.call(this, expression); |
| 790 | |
| 791 | return this; |
| 792 | } |
| 793 | |
| 794 | QuantifiedExpression.prototype = Object.create(AExpression.prototype); |
| 795 | QuantifiedExpression.prototype.constructor = QuantifiedExpression; |
genia.likes.science@gmail.com | 64ca88e | 2013-05-31 10:40:39 -0700 | [diff] [blame] | 796 | |
| 797 | QuantifiedExpression.prototype.val = function() { |
| 798 | var value = AExpression.prototype.val.call(this); |
| 799 | return "(" + value + ")"; |
| 800 | }; |