blob: 889995330f890b03ef006f06b9dcdf09ec4688df [file] [log] [blame]
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -07001function 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
16AsterixDBConnection.prototype.dataverse = function(dataverseName) {
17 this._properties["dataverse"] = dataverseName;
18
19 return this;
20};
21
22
23AsterixDBConnection.prototype.run = function(statements, successFn) {
24
25 var success_fn = successFn;
26
27 if ( typeof statements === 'string') {
28 statements = [ statements ];
29 }
30
31 var query = "use dataverse " + this._properties["dataverse"] + "\n;" + statements.join("\n");
32 var mode = this._properties["mode"];
33
34 $.ajax({
35 type : 'GET',
36 url : "http://localhost:19002/query",
37 data : {
38 "query" : query,
39 "mode" : mode
40 },
41 dataType : "json",
42 success : function(data) {
43 success_fn(data);
44 },
45 error: function(r) {
46 alert("AsterixSDK ERROR\n" + JSON.stringify(r));
47 }
48 });
49
50 return this;
51};
52
53
54// Asterix Expressions
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070055function AExpression () {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070056 this._properties = {};
57 this._success = function() {};
58
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070059 return this;
60}
61
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070062
63AExpression.prototype.bind = function(options) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070064 var options = options || {};
65
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070066 if (options.hasOwnProperty("success")) {
67 this._success = options["success"];
68 }
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -070069
70 if (options.hasOwnProperty("return")) {
71 this._properties["return"] = " return " + options["return"].val();
72 }
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070073};
74
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070075
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -070076AExpression.prototype.run = function(successFn) {
77 var success_fn = successFn;
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070078
79 $.ajax({
80 type : 'GET',
genia.likes.science@gmail.comfc5f5092013-06-12 00:49:46 -070081 url : "http://localhost:19002/query",
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -070082 data : {"query" : "use dataverse TinySocial;\n" + this.val()},
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070083 dataType : "json",
84 success : function(data) {
85 success_fn(data);
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -070086 },
87 error: function(r) {
88 //alert(JSON.stringify(r));
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070089 }
90 });
91
92 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070093};
94
95
96AExpression.prototype.val = function() {
97
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -070098 var value = "";
99
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700100 // If there is a dataverse defined, provide it.
101 if (this._properties.hasOwnProperty("dataverse")) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700102 value += "use dataverse " + this._properties["dataverse"] + ";\n";
103 };
104
105 if (this._properties.hasOwnProperty("value")) {
106 value += this._properties["value"];
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700107 }
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700108
109 return value;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700110};
111
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700112// @param expressionValue [String]
113AExpression.prototype.set = function(expressionValue) {
114 this._properties["value"] = expressionValue;
115 return this;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700116};
117
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700118
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700119// FunctionExpression
120// Parent: AsterixExpression
121//
122// @param options [Various],
123// @key function [String], a function to be applid to the expression
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700124// @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied
125function FunctionExpression() {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700126
127 // Initialize superclass
128 AExpression.call(this);
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700129
130 this._properties["function"] = "";
131 this._properties["expression"] = new AExpression().set("");
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700132
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700133 // Check for fn/expression input
134 if (arguments.length == 2 && typeof arguments[0] == "string" &&
135 (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) {
136
137 this._properties["function"] = arguments[0];
138 this._properties["expression"] = arguments[1];
139
140 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700141
142 // Return object
143 return this;
144}
145
146
147FunctionExpression.prototype = Object.create(AExpression.prototype);
148FunctionExpression.prototype.constructor = FunctionExpression;
149
150
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700151FunctionExpression.prototype.fn = function(fnName) {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700152
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700153 if (typeof fnName == "string") {
154 this._properties["function"] = fnName;
155 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700156
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700157 return this;
158};
159
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700160
161FunctionExpression.prototype.expression = function(expression) {
162 if (expression instanceof AExpression || expression instanceof AQLClause) {
163 this._properties["expression"] = expression;
164 }
165
166 return this;
167};
168
169
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700170FunctionExpression.prototype.val = function () {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700171 return this._properties["function"] + "(" + this._properties["expression"].val() + ")";
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700172};
173
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700174
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700175// FLWOGR ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
176// Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700177//
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700178// WhereClause ::= "where" Expression
179// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
genia.likes.science@gmail.comb4cb6b32013-05-29 04:30:38 -0700180//
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700181// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
182// LimitClause ::= "limit" Expression ( "offset" Expression )?
183// DistinctClause ::= "distinct" "by" Expression ( "," Expression )*
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700184
185
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700186// FLWOGRExpression
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700187//
188// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700189function FLWOGRExpression (options) {
190 // Initialize superclass
191 AExpression.call(this);
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700192
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700193 this._properties["clauses"] = [];
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700194 this._properties["minSize"] = 0;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700195
196 // Bind options and return
197 this.bind(options);
198 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700199}
200
201
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700202FLWOGRExpression.prototype = Object.create(AExpression.prototype);
203FLWOGRExpression.prototype.constructor = FLWOGRExpression;
204
205
206FLWOGRExpression.prototype.bind = function(options) {
207 AExpression.prototype.bind.call(this, options);
208
209 var options = options || {};
210
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700211 if (options instanceof SetStatement) {
212 this._properties["clauses"].push(options);
213 this._properties["minSize"] += 1;
214 }
215
216 if (this._properties["clauses"].length <= this._properties["minSize"]) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700217 // Needs to start with for or let clause
218 if (options instanceof ForClause || options instanceof LetClause) {
219 this._properties["clauses"].push(options);
220 }
221 } else {
222 if (options instanceof AQLClause) {
223 this._properties["clauses"].push(options);
224 }
225 }
226
227 return this;
228};
229
230
231FLWOGRExpression.prototype.val = function() {
232 var value = AExpression.prototype.val.call(this);
233
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700234 var clauseValues = [];
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700235 for (var c in this._properties["clauses"]) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700236 clauseValues.push(this._properties["clauses"][c].val());
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700237 }
238
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700239 return value + clauseValues.join("\n");// + ";";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700240};
241
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700242
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700243FLWOGRExpression.prototype.ReturnClause = function(expression) {
244 return this.bind(new ReturnClause(expression));
245};
246
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700247// AQLClause
248//
249// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
250function AQLClause() {
251 this._properties = {};
252 this._properties["clause"] = "";
253}
254
255AQLClause.prototype.val = function() {
256 var value = this._properties["clause"];
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700257
258 return value;
259};
260
261AQLClause.prototype.bind = function(options) {
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700262
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700263 if (options instanceof AQLClause) {
264 this._properties["clause"] += " " + options.val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700265 }
266
267 return this;
268};
269
genia.likes.science@gmail.com39578302013-05-31 04:42:26 -0700270AQLClause.prototype.set = function(value) {
271 this._properties["clause"] = value;
272 return this;
273};
274
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700275
276// ForClause
277//
278// Grammar:
279// "for" Variable ( "at" Variable )? "in" ( Expression )
280//
281// @param for_variable [String], REQUIRED, first variable in clause
282// @param at_variable [String], NOT REQUIRED, first variable in clause
283// @param expression [AsterixExpression], REQUIRED, expression to evaluate
284//
285// TODO Error Checking
286function ForClause(for_variable, at_variable, expression) {
287 AQLClause.call(this);
288
289 // at_variable is optional, check if defined
290 var at = typeof at_variable ? at_variable : null;
291
292 // Prepare clause
293 this._properties["clause"] = "for $" + for_variable;
294 if (at != null) {
295 this._properties["clause"] += " at $" + at_variable;
296 }
297 this._properties["clause"] += " in " + expression.val();
298 return this;
299}
300
301ForClause.prototype = Object.create(AQLClause.prototype);
302ForClause.prototype.constructor = ForClause;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700303
304
305// LetClause
306//
307// Grammar:
308// LetClause ::= "let" Variable ":=" Expression
309//
310// @param let_variable [String]
311// @param expression [AExpression]
312//
313// TODO Vigorous error checking
314function LetClause(let_variable, expression) {
315 AQLClause.call(this);
316
317 this._properties["clause"] = "let $" + let_variable + " := ";
318 this._properties["clause"] += expression.val();
319
320 return this;
321}
322
323LetClause.prototype = Object.create(AQLClause.prototype);
324LetClause.prototype.constructor = LetClause;
325
326
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700327// ReturnClause
328//
329// Grammar:
330// return [AQLExpression]
331function ReturnClause(expression) {
332 AQLClause.call(this);
333
334 this._properties["clause"] = "return ";
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700335
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700336 if (expression instanceof AExpression || expression instanceof AQLClause) {
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700337 this._properties["clause"] += expression.val();
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700338
339 } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) {
340
341 // TODO Null object check
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700342
343 this._properties["clause"] += "{";
344 var returnStatements = [];
345 for (returnValue in expression) {
346
347 if (expression[returnValue] instanceof AExpression) {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700348 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val());
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700349 } else if (typeof expression[returnValue] == "string") {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700350 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]);
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700351 }
352 }
353 this._properties["clause"] += returnStatements.join(",\n");
genia.likes.science@gmail.comf7929d82013-06-12 11:30:01 -0700354 this._properties["clause"] += "\n}";
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700355
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700356 } else {
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700357 this._properties["clause"] += new AQLClause().set(expression).val();
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700358 }
359
360 return this;
361}
362
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700363
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700364ReturnClause.prototype = Object.create(AQLClause.prototype);
365ReturnClause.prototype.constructor = ReturnClause;
366
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700367
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700368// WhereClause
369//
370// Grammar:
371// ::= "where" Expression
372//
373// @param expression [BooleanExpression], pushes this expression onto the stack
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700374function WhereClause(expression) {
375 AQLClause.call(this);
376
377 this._properties["stack"] = [];
378
379 this.bind(expression);
380
381 return this;
382}
383
384
385WhereClause.prototype = Object.create(AQLClause.prototype);
386WhereClause.prototype.constructor = WhereClause;
387
388
389WhereClause.prototype.bind = function(expression) {
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700390 if (expression instanceof AExpression) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700391 this._properties["stack"].push(expression);
392 }
393};
394
395
396WhereClause.prototype.val = function() {
397 var value = "where ";
398
399 var count = this._properties["stack"].length - 1;
400 while (count >= 0) {
401 value += this._properties["stack"][count].val() + " ";
402 count -= 1;
403 }
404
405 return value;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700406};
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700407
408
genia.likes.science@gmail.comd2f753e2013-06-12 13:51:03 -0700409WhereClause.prototype.and = function() {
410
411 var andClauses = [];
412 for (var expression in arguments) {
413
414 if (arguments[expression] instanceof AExpression) {
415 andClauses.push(arguments[expression].val());
416 }
417 }
418
419 if (andClauses.length > 0) {
420 this._properties["stack"].push(new AExpression().set(andClauses.join(" and ")));
421 }
422
423 return this;
424};
425
426
427WhereClause.prototype.or = function() {
428 var orClauses = [];
429 for (var expression in arguments) {
430
431 if (arguments[expression] instanceof AExpression) {
432 orClauses.push(arguments[expression].val());
433 }
434 }
435
436 if (andClauses.length > 0) {
437 this._properties["stack"].push(new AExpression().set(orClauses.join(" and ")));
438 }
439
440 return this;
441};
442
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700443// LimitClause
444// Grammar:
445// LimitClause ::= "limit" Expression ( "offset" Expression )?
446//
447// @param limitExpression [REQUIRED, AQLExpression]
448// @param offsetExpression [OPTIONAL, AQLExpression]
449function LimitClause(limitExpression, offsetExpression) {
450
451 AQLClause.call(this);
452
453 // limitExpression required
454 this._properties["clause"] = "limit " + limitExpression.val();
455
456 // Optional: Offset
457 var offset = typeof offsetExpression ? offsetExpression : null;
458 if (offset != null) {
459 this._properties["clause"] += " offset " + offsetExpression.val();
460 }
461
462 return this;
463}
464
465LimitClause.prototype = Object.create(AQLClause.prototype);
466LimitClause.prototype.constructor = LimitClause;
467
468
469// OrderbyClause
470//
471// Grammar:
472// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
473//
474// @params AQLExpressions and asc/desc strings, in any quantity. At least one required.
475function OrderbyClause() {
476
477 AQLClause.call(this);
478
479 // At least one argument expression is required, and first should be expression
480 if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700481
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700482 // TODO Not sure which error to throw for an empty OrderBy but this should fail.
483 alert("Order By Error");
484 this._properties["clause"] = null;
485 return this;
486 }
487
488 var expc = 0;
489 var expressions = [];
490
491 while (expc < arguments.length) {
492
493 var expression = "";
494
495 if (arguments[expc] instanceof AExpression) {
496 expression += arguments[expc].val();
497 }
498
499 var next = expc + 1;
500 if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
501 expc++;
502 expression += " " + arguments[expc];
503 }
504
505 expressions.push(expression);
506
507 expc++;
508 }
509
510 this._properties["clause"] = "order by " + expressions.join(", ");
511 return this;
512}
513
514OrderbyClause.prototype = Object.create(AQLClause.prototype);
515OrderbyClause.prototype.constructor = OrderbyClause;
516
517
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700518// GroupClause
519//
520// Grammar:
521// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
522function GroupClause() {
523 AQLClause.call(this);
524
525 if (arguments.length == 0) {
526 // TODO Not sure which error to throw for an empty GroupBy but this should fail.
527 alert("Group Error");
528 this._properties["clause"] = null;
529 return this;
530 }
531
532 var expc = 0;
533 var expressions = [];
534 var variableRefs = [];
535 var isDecor = false;
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700536
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700537 while (expc < arguments.length) {
538
539 if (arguments[expc] instanceof AExpression) {
540
541 isDecor = false;
542 expressions.push(arguments[expc].val());
543
544 } else if (typeof arguments[expc] == "string") {
545
546 // Special keywords, decor & with
547 if (arguments[expc] == "decor") {
548 isDecor = true;
549 } else if (arguments[expc] == "with") {
550 isDecor = false;
551 expc++;
552 while (expc < arguments.length) {
553 variableRefs.push("$" + arguments[expc]);
554 expc++;
555 }
556
557 // Variables and variable refs
558 } else {
559
560 var nextc = expc + 1;
561 var expression = "";
562
563 if (isDecor) {
564 expression += "decor ";
565 isDecor = false;
566 }
567
568 expression += "$" + arguments[expc] + " := " + arguments[nextc].val();
569 expressions.push(expression);
570 expc++;
571 }
572 }
573
574 expc++;
575 }
576
577 this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", ");
578 return this;
579}
580
581GroupClause.prototype = Object.create(AQLClause.prototype);
582GroupClause.prototype.constructor = GroupClause;
583
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700584
585// SetStatement
586//
587// Grammar
588// "set" Identifier StringLiteral
589function SetStatement (identifier, stringLiteral) {
590 AExpression.call(this);
591
592 var statement = "set " + identifier + ' "' + stringLiteral + '";';
593
594 AExpression.prototype.set.call(this, statement);
595
596 return this;
597}
598
599SetStatement.prototype = Object.create(AExpression.prototype);
600SetStatement.prototype.constructor = SetStatement;
genia.likes.science@gmail.come34c57b2013-05-31 10:15:49 -0700601
602
603// Quantified Expression
604//
605// Grammar
606// QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
607//
608// @param String some/every
609// @param [AExpression]
610// @param [Aexpression] satisfiesExpression
611function QuantifiedExpression (keyword, expressions, satisfiesExpression) {
612 AExpression.call(this);
613
614 var expression = keyword + " ";
615 var varsInExpressions = [];
616
617 for (var varInExpression in expressions) {
618 varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val());
619 }
620 expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val();
621
622 AExpression.prototype.set.call(this, expression);
623
624 return this;
625}
626
627QuantifiedExpression.prototype = Object.create(AExpression.prototype);
628QuantifiedExpression.prototype.constructor = QuantifiedExpression;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700629
630QuantifiedExpression.prototype.val = function() {
631 var value = AExpression.prototype.val.call(this);
632 return "(" + value + ")";
633};