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