blob: dd03e9c369e91b4f6acf0ba1353a29898adf98d6 [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
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070023AsterixDBConnection.prototype.query = function(statements, successFn, mode) {
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070024
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070025 if ( typeof statements === 'string') {
26 statements = [ statements ];
27 }
28
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070029 var m = mode;
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -070030 var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n");
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070031
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070032 this._api(
33 {
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070034 "query" : query,
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070035 "mode" : m
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070036 },
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070037 successFn,
38 "http://localhost:19002/query"
39 );
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070040
41 return this;
42};
43
44
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070045AsterixDBConnection.prototype.query_status = function(data, successFn) {
46
47 this._api(
48 data,
49 successFn,
50 "http://localhost:19002/query/status"
51 );
52
53 return this;
54};
55
56
57AsterixDBConnection.prototype.query_result = function(data, successFn) {
58 this._api(
59 data,
60 successFn,
61 "http://localhost:19002/query/result"
62 );
63
64 return this;
65};
66
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070067AsterixDBConnection.prototype._api = function(json, onSuccess, endpoint) {
68 var success_fn = onSuccess;
69
70 $.ajax({
71 type: 'GET',
72 url: endpoint,
73 data : json,
74 dataType: "json",
75 success: function(data) {
76 success_fn(data);
77 }
78 // TODO error:
79 });
80
81 return this;
82};
83
84
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070085// Asterix Expressions
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070086function AExpression () {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070087 this._properties = {};
88 this._success = function() {};
89
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070090 return this;
91}
92
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070093
94AExpression.prototype.bind = function(options) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070095 var options = options || {};
96
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070097 if (options.hasOwnProperty("success")) {
98 this._success = options["success"];
99 }
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700100
101 if (options.hasOwnProperty("return")) {
102 this._properties["return"] = " return " + options["return"].val();
103 }
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700104};
105
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700106
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700107AExpression.prototype.run = function(successFn) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700108 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700109};
110
111
112AExpression.prototype.val = function() {
113
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700114 var value = "";
115
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700116 // If there is a dataverse defined, provide it.
117 if (this._properties.hasOwnProperty("dataverse")) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700118 value += "use dataverse " + this._properties["dataverse"] + ";\n";
119 };
120
121 if (this._properties.hasOwnProperty("value")) {
122 value += this._properties["value"];
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700123 }
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700124
125 return value;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700126};
127
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700128// @param expressionValue [String]
129AExpression.prototype.set = function(expressionValue) {
130 this._properties["value"] = expressionValue;
131 return this;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700132};
133
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700134
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700135// FunctionExpression
136// Parent: AsterixExpression
137//
138// @param options [Various],
139// @key function [String], a function to be applid to the expression
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700140// @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied
141function FunctionExpression() {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700142
143 // Initialize superclass
144 AExpression.call(this);
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700145
146 this._properties["function"] = "";
147 this._properties["expression"] = new AExpression().set("");
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700148
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700149 // Check for fn/expression input
150 if (arguments.length == 2 && typeof arguments[0] == "string" &&
151 (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) {
152
153 this._properties["function"] = arguments[0];
154 this._properties["expression"] = arguments[1];
155
156 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700157
158 // Return object
159 return this;
160}
161
162
163FunctionExpression.prototype = Object.create(AExpression.prototype);
164FunctionExpression.prototype.constructor = FunctionExpression;
165
166
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700167FunctionExpression.prototype.fn = function(fnName) {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700168
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700169 if (typeof fnName == "string") {
170 this._properties["function"] = fnName;
171 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700172
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700173 return this;
174};
175
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700176
177FunctionExpression.prototype.expression = function(expression) {
178 if (expression instanceof AExpression || expression instanceof AQLClause) {
179 this._properties["expression"] = expression;
180 }
181
182 return this;
183};
184
185
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700186FunctionExpression.prototype.val = function () {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700187 return this._properties["function"] + "(" + this._properties["expression"].val() + ")";
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700188};
189
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700190
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700191// FLWOGRExpression
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700192//
193// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700194function FLWOGRExpression (options) {
195 // Initialize superclass
196 AExpression.call(this);
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700197
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700198 this._properties["clauses"] = [];
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700199 this._properties["minSize"] = 0;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700200
201 // Bind options and return
202 this.bind(options);
203 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700204}
205
206
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700207FLWOGRExpression.prototype = Object.create(AExpression.prototype);
208FLWOGRExpression.prototype.constructor = FLWOGRExpression;
209
210
211FLWOGRExpression.prototype.bind = function(options) {
212 AExpression.prototype.bind.call(this, options);
213
214 var options = options || {};
215
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700216 if (options instanceof SetStatement) {
217 this._properties["clauses"].push(options);
218 this._properties["minSize"] += 1;
219 }
220
221 if (this._properties["clauses"].length <= this._properties["minSize"]) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700222 // Needs to start with for or let clause
223 if (options instanceof ForClause || options instanceof LetClause) {
224 this._properties["clauses"].push(options);
225 }
226 } else {
227 if (options instanceof AQLClause) {
228 this._properties["clauses"].push(options);
229 }
230 }
231
232 return this;
233};
234
235
236FLWOGRExpression.prototype.val = function() {
237 var value = AExpression.prototype.val.call(this);
238
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700239 var clauseValues = [];
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700240 for (var c in this._properties["clauses"]) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700241 clauseValues.push(this._properties["clauses"][c].val());
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700242 }
243
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700244 return value + clauseValues.join("\n");// + ";";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700245};
246
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700247
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700248FLWOGRExpression.prototype.ReturnClause = function(expression) {
249 return this.bind(new ReturnClause(expression));
250};
251
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700252// AQLClause
253//
254// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
255function AQLClause() {
256 this._properties = {};
257 this._properties["clause"] = "";
258}
259
260AQLClause.prototype.val = function() {
261 var value = this._properties["clause"];
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700262
263 return value;
264};
265
266AQLClause.prototype.bind = function(options) {
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700267
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700268 if (options instanceof AQLClause) {
269 this._properties["clause"] += " " + options.val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700270 }
271
272 return this;
273};
274
genia.likes.science@gmail.com39578302013-05-31 04:42:26 -0700275AQLClause.prototype.set = function(value) {
276 this._properties["clause"] = value;
277 return this;
278};
279
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700280
281// ForClause
282//
283// Grammar:
284// "for" Variable ( "at" Variable )? "in" ( Expression )
285//
286// @param for_variable [String], REQUIRED, first variable in clause
287// @param at_variable [String], NOT REQUIRED, first variable in clause
288// @param expression [AsterixExpression], REQUIRED, expression to evaluate
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700289function ForClause(for_variable, at_variable, expression) {
290 AQLClause.call(this);
291
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700292 this._properties["clause"] = "for " + arguments[0];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700293
294 if (arguments.length == 3) {
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700295 this._properties["clause"] += " at " + arguments[1];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700296 this._properties["clause"] += " in " + arguments[2].val();
297 } else if (arguments.length == 2) {
298 this._properties["clause"] += " in " + arguments[1].val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700299 }
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700300
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700301 return this;
302}
303
304ForClause.prototype = Object.create(AQLClause.prototype);
305ForClause.prototype.constructor = ForClause;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700306
307
308// LetClause
309//
310// Grammar:
311// LetClause ::= "let" Variable ":=" Expression
312//
313// @param let_variable [String]
314// @param expression [AExpression]
315//
316// TODO Vigorous error checking
317function LetClause(let_variable, expression) {
318 AQLClause.call(this);
319
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700320 this._properties["clause"] = "let " + let_variable + " := ";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700321 this._properties["clause"] += expression.val();
322
323 return this;
324}
325
326LetClause.prototype = Object.create(AQLClause.prototype);
327LetClause.prototype.constructor = LetClause;
328
329
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700330// ReturnClause
331//
332// Grammar:
333// return [AQLExpression]
334function ReturnClause(expression) {
335 AQLClause.call(this);
336
337 this._properties["clause"] = "return ";
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700338
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700339 if (expression instanceof AExpression || expression instanceof AQLClause) {
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700340 this._properties["clause"] += expression.val();
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700341
342 } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) {
343
344 // TODO Null object check
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700345
346 this._properties["clause"] += "{";
347 var returnStatements = [];
348 for (returnValue in expression) {
349
350 if (expression[returnValue] instanceof AExpression) {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700351 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val());
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700352 } else if (typeof expression[returnValue] == "string") {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700353 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]);
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700354 }
355 }
356 this._properties["clause"] += returnStatements.join(",\n");
genia.likes.science@gmail.comf7929d82013-06-12 11:30:01 -0700357 this._properties["clause"] += "\n}";
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700358
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700359 } else {
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700360 this._properties["clause"] += new AQLClause().set(expression).val();
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700361 }
362
363 return this;
364}
365
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700366
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700367ReturnClause.prototype = Object.create(AQLClause.prototype);
368ReturnClause.prototype.constructor = ReturnClause;
369
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700370
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700371// WhereClause
372//
373// Grammar:
374// ::= "where" Expression
375//
376// @param expression [BooleanExpression], pushes this expression onto the stack
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700377function WhereClause(expression) {
378 AQLClause.call(this);
379
380 this._properties["stack"] = [];
381
382 this.bind(expression);
383
384 return this;
385}
386
387
388WhereClause.prototype = Object.create(AQLClause.prototype);
389WhereClause.prototype.constructor = WhereClause;
390
391
392WhereClause.prototype.bind = function(expression) {
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700393 if (expression instanceof AExpression) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700394 this._properties["stack"].push(expression);
395 }
396};
397
398
399WhereClause.prototype.val = function() {
400 var value = "where ";
401
402 var count = this._properties["stack"].length - 1;
403 while (count >= 0) {
404 value += this._properties["stack"][count].val() + " ";
405 count -= 1;
406 }
407
408 return value;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700409};
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700410
411
genia.likes.science@gmail.comd2f753e2013-06-12 13:51:03 -0700412WhereClause.prototype.and = function() {
413
414 var andClauses = [];
415 for (var expression in arguments) {
416
417 if (arguments[expression] instanceof AExpression) {
418 andClauses.push(arguments[expression].val());
419 }
420 }
421
422 if (andClauses.length > 0) {
423 this._properties["stack"].push(new AExpression().set(andClauses.join(" and ")));
424 }
425
426 return this;
427};
428
429
430WhereClause.prototype.or = function() {
431 var orClauses = [];
432 for (var expression in arguments) {
433
434 if (arguments[expression] instanceof AExpression) {
435 orClauses.push(arguments[expression].val());
436 }
437 }
438
439 if (andClauses.length > 0) {
440 this._properties["stack"].push(new AExpression().set(orClauses.join(" and ")));
441 }
442
443 return this;
444};
445
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700446// LimitClause
447// Grammar:
448// LimitClause ::= "limit" Expression ( "offset" Expression )?
449//
450// @param limitExpression [REQUIRED, AQLExpression]
451// @param offsetExpression [OPTIONAL, AQLExpression]
452function LimitClause(limitExpression, offsetExpression) {
453
454 AQLClause.call(this);
455
456 // limitExpression required
457 this._properties["clause"] = "limit " + limitExpression.val();
458
459 // Optional: Offset
460 var offset = typeof offsetExpression ? offsetExpression : null;
461 if (offset != null) {
462 this._properties["clause"] += " offset " + offsetExpression.val();
463 }
464
465 return this;
466}
467
468LimitClause.prototype = Object.create(AQLClause.prototype);
469LimitClause.prototype.constructor = LimitClause;
470
471
472// OrderbyClause
473//
474// Grammar:
475// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
476//
477// @params AQLExpressions and asc/desc strings, in any quantity. At least one required.
478function OrderbyClause() {
479
480 AQLClause.call(this);
481
482 // At least one argument expression is required, and first should be expression
483 if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700484
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700485 // TODO Not sure which error to throw for an empty OrderBy but this should fail.
486 alert("Order By Error");
487 this._properties["clause"] = null;
488 return this;
489 }
490
491 var expc = 0;
492 var expressions = [];
493
494 while (expc < arguments.length) {
495
496 var expression = "";
497
498 if (arguments[expc] instanceof AExpression) {
499 expression += arguments[expc].val();
500 }
501
502 var next = expc + 1;
503 if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
504 expc++;
505 expression += " " + arguments[expc];
506 }
507
508 expressions.push(expression);
509
510 expc++;
511 }
512
513 this._properties["clause"] = "order by " + expressions.join(", ");
514 return this;
515}
516
517OrderbyClause.prototype = Object.create(AQLClause.prototype);
518OrderbyClause.prototype.constructor = OrderbyClause;
519
520
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700521// GroupClause
522//
523// Grammar:
524// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
525function GroupClause() {
526 AQLClause.call(this);
527
528 if (arguments.length == 0) {
529 // TODO Not sure which error to throw for an empty GroupBy but this should fail.
530 alert("Group Error");
531 this._properties["clause"] = null;
532 return this;
533 }
534
535 var expc = 0;
536 var expressions = [];
537 var variableRefs = [];
538 var isDecor = false;
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700539
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700540 while (expc < arguments.length) {
541
542 if (arguments[expc] instanceof AExpression) {
543
544 isDecor = false;
545 expressions.push(arguments[expc].val());
546
547 } else if (typeof arguments[expc] == "string") {
548
549 // Special keywords, decor & with
550 if (arguments[expc] == "decor") {
551 isDecor = true;
552 } else if (arguments[expc] == "with") {
553 isDecor = false;
554 expc++;
555 while (expc < arguments.length) {
556 variableRefs.push("$" + arguments[expc]);
557 expc++;
558 }
559
560 // Variables and variable refs
561 } else {
562
563 var nextc = expc + 1;
564 var expression = "";
565
566 if (isDecor) {
567 expression += "decor ";
568 isDecor = false;
569 }
570
571 expression += "$" + arguments[expc] + " := " + arguments[nextc].val();
572 expressions.push(expression);
573 expc++;
574 }
575 }
576
577 expc++;
578 }
579
580 this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", ");
581 return this;
582}
583
584GroupClause.prototype = Object.create(AQLClause.prototype);
585GroupClause.prototype.constructor = GroupClause;
586
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700587
588// SetStatement
589//
590// Grammar
591// "set" Identifier StringLiteral
592function SetStatement (identifier, stringLiteral) {
593 AExpression.call(this);
594
595 var statement = "set " + identifier + ' "' + stringLiteral + '";';
596
597 AExpression.prototype.set.call(this, statement);
598
599 return this;
600}
601
602SetStatement.prototype = Object.create(AExpression.prototype);
603SetStatement.prototype.constructor = SetStatement;
genia.likes.science@gmail.come34c57b2013-05-31 10:15:49 -0700604
605
606// Quantified Expression
607//
608// Grammar
609// QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
610//
611// @param String some/every
612// @param [AExpression]
613// @param [Aexpression] satisfiesExpression
614function QuantifiedExpression (keyword, expressions, satisfiesExpression) {
615 AExpression.call(this);
616
617 var expression = keyword + " ";
618 var varsInExpressions = [];
619
620 for (var varInExpression in expressions) {
621 varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val());
622 }
623 expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val();
624
625 AExpression.prototype.set.call(this, expression);
626
627 return this;
628}
629
630QuantifiedExpression.prototype = Object.create(AExpression.prototype);
631QuantifiedExpression.prototype.constructor = QuantifiedExpression;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700632
633QuantifiedExpression.prototype.val = function() {
634 var value = AExpression.prototype.val.call(this);
635 return "(" + value + ")";
636};