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