Skip to content

Commit

Permalink
bsjs: fix for [(a,b)]
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 23, 2012
1 parent 4313bd5 commit a42565e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
54 changes: 27 additions & 27 deletions lib/ometajs/grammars/bsjs.js
Expand Up @@ -1157,17 +1157,17 @@ BSJSTranslator.prototype["regExp"] = function $regExp() {
}; };


BSJSTranslator.prototype["arr"] = function $arr() { BSJSTranslator.prototype["arr"] = function $arr() {
var xs; var $l0, $l1, xs;
return this._any(function() { return ($l0 = this, $l1 = $l0.op, $l0.op = "[]", true) && (this._any(function() {
return this._atomic(function() { return this._atomic(function() {
return this._rule("trans", false, [], null, this["trans"]); return this._rule("trans", false, [], null, this["trans"]);
}); });
}) && (xs = this._getIntermediate(), true) && this._exec("[" + xs.join(",") + "]"); }) && (xs = this._getIntermediate(), true) && this._exec("[" + xs.join(",") + "]") && ($l0.op = $l1, true) || ($l0.op = $l1, false));
}; };


BSJSTranslator.prototype["unop"] = function $unop() { BSJSTranslator.prototype["unop"] = function $unop() {
var op, prevOp, $l0, $l1, t; var op, prevOp, $l2, $l3, t;
return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l0 = this, $l1 = $l0.op, $l0.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (t = this._getIntermediate(), true) && this._exec(function() { return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l2 = this, $l3 = $l2.op, $l2.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (t = this._getIntermediate(), true) && this._exec(function() {
var res; var res;
if (op === "typeof" || op === "void" || op === "delete") { if (op === "typeof" || op === "void" || op === "delete") {
res = op + " " + t; res = op + " " + t;
Expand All @@ -1178,18 +1178,18 @@ BSJSTranslator.prototype["unop"] = function $unop() {
res = "(" + res + ")"; res = "(" + res + ")";
} }
return res; return res;
}.call(this)) && ($l0.op = $l1, true) || ($l0.op = $l1, false)); }.call(this)) && ($l2.op = $l3, true) || ($l2.op = $l3, false));
}; };


BSJSTranslator.prototype["getp"] = function $getp() { BSJSTranslator.prototype["getp"] = function $getp() {
var $l2, $l3, fd, tfd, x; var $l4, $l5, fd, tfd, x;
return ($l2 = this, $l3 = $l2.op, $l2.op = ".", true) && (this._skip() && (fd = this._getIntermediate(), true) && this._rule("trans", false, [ fd ], null, this["trans"]) && (tfd = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() { return ($l4 = this, $l5 = $l4.op, $l4.op = ".", true) && (this._skip() && (fd = this._getIntermediate(), true) && this._rule("trans", false, [ fd ], null, this["trans"]) && (tfd = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() {
if (fd[0] === "string" && /^[$_a-z0-9][a-z0-9]*$/i.test(fd[1]) && !BSJSParser._isKeyword(fd[1])) { if (fd[0] === "string" && /^[$_a-z0-9][a-z0-9]*$/i.test(fd[1]) && !BSJSParser._isKeyword(fd[1])) {
return x + "." + fd[1]; return x + "." + fd[1];
} else { } else {
return x + "[" + tfd + "]"; return x + "[" + tfd + "]";
} }
}.call(this)) && ($l2.op = $l3, true) || ($l2.op = $l3, false)); }.call(this)) && ($l4.op = $l5, true) || ($l4.op = $l5, false));
}; };


BSJSTranslator.prototype["get"] = function $get() { BSJSTranslator.prototype["get"] = function $get() {
Expand All @@ -1198,58 +1198,58 @@ BSJSTranslator.prototype["get"] = function $get() {
}; };


BSJSTranslator.prototype["set"] = function $set() { BSJSTranslator.prototype["set"] = function $set() {
var prevOp, lhs, $l4, $l5, rhs; var prevOp, lhs, $l6, $l7, rhs;
return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (lhs = this._getIntermediate(), true) && ($l4 = this, $l5 = $l4.op, $l4.op = "=", true) && (this._rule("trans", false, [], null, this["trans"]) && (rhs = this._getIntermediate(), true) && this._exec(function() { return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (lhs = this._getIntermediate(), true) && ($l6 = this, $l7 = $l6.op, $l6.op = "=", true) && (this._rule("trans", false, [], null, this["trans"]) && (rhs = this._getIntermediate(), true) && this._exec(function() {
if (BSJSTranslator.comparePriorities(prevOp, "=")) { if (BSJSTranslator.comparePriorities(prevOp, "=")) {
return "(" + lhs + " = " + rhs + ")"; return "(" + lhs + " = " + rhs + ")";
} else { } else {
return lhs + " = " + rhs; return lhs + " = " + rhs;
} }
}.call(this)) && ($l4.op = $l5, true) || ($l4.op = $l5, false)); }.call(this)) && ($l6.op = $l7, true) || ($l6.op = $l7, false));
}; };


BSJSTranslator.prototype["mset"] = function $mset() { BSJSTranslator.prototype["mset"] = function $mset() {
var prevOp, lhs, op, $l6, $l7, rhs; var prevOp, lhs, op, $l8, $l9, rhs;
return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (lhs = this._getIntermediate(), true) && this._skip() && (op = this._getIntermediate(), true) && ($l6 = this, $l7 = $l6.op, $l6.op = op + "=", true) && (this._rule("trans", false, [], null, this["trans"]) && (rhs = this._getIntermediate(), true) && this._exec(function() { return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (lhs = this._getIntermediate(), true) && this._skip() && (op = this._getIntermediate(), true) && ($l8 = this, $l9 = $l8.op, $l8.op = op + "=", true) && (this._rule("trans", false, [], null, this["trans"]) && (rhs = this._getIntermediate(), true) && this._exec(function() {
if (BSJSTranslator.comparePriorities(prevOp, op + "=")) { if (BSJSTranslator.comparePriorities(prevOp, op + "=")) {
return "(" + lhs + " " + op + "= " + rhs + ")"; return "(" + lhs + " " + op + "= " + rhs + ")";
} else { } else {
return lhs + " " + op + "= " + rhs; return lhs + " " + op + "= " + rhs;
} }
}.call(this)) && ($l6.op = $l7, true) || ($l6.op = $l7, false)); }.call(this)) && ($l8.op = $l9, true) || ($l8.op = $l9, false));
}; };


BSJSTranslator.prototype["binop"] = function $binop() { BSJSTranslator.prototype["binop"] = function $binop() {
var op, prevOp, $l8, $l9, x, y; var op, prevOp, $l10, $l11, x, y;
return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l8 = this, $l9 = $l8.op, $l8.op = op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (y = this._getIntermediate(), true) && this._exec(function() { return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l10 = this, $l11 = $l10.op, $l10.op = op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (y = this._getIntermediate(), true) && this._exec(function() {
var res = x + " " + op + " " + y; var res = x + " " + op + " " + y;
if (BSJSTranslator.comparePriorities(prevOp, op)) { if (BSJSTranslator.comparePriorities(prevOp, op)) {
res = "(" + res + ")"; res = "(" + res + ")";
} }
return res; return res;
}.call(this)) && ($l8.op = $l9, true) || ($l8.op = $l9, false)); }.call(this)) && ($l10.op = $l11, true) || ($l10.op = $l11, false));
}; };


BSJSTranslator.prototype["preop"] = function $preop() { BSJSTranslator.prototype["preop"] = function $preop() {
var op, prevOp, $l10, $l11, x; var op, prevOp, $l12, $l13, x;
return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l10 = this, $l11 = $l10.op, $l10.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() { return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l12 = this, $l13 = $l12.op, $l12.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() {
var res = op + x; var res = op + x;
if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) { if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) {
res = "(" + res + ")"; res = "(" + res + ")";
} }
return res; return res;
}.call(this)) && ($l10.op = $l11, true) || ($l10.op = $l11, false)); }.call(this)) && ($l12.op = $l13, true) || ($l12.op = $l13, false));
}; };


BSJSTranslator.prototype["postop"] = function $postop() { BSJSTranslator.prototype["postop"] = function $postop() {
var op, prevOp, $l12, $l13, x; var op, prevOp, $l14, $l15, x;
return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l12 = this, $l13 = $l12.op, $l12.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() { return this._skip() && (op = this._getIntermediate(), true) && this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l14 = this, $l15 = $l14.op, $l14.op = "u" + op, true) && (this._rule("trans", false, [], null, this["trans"]) && (x = this._getIntermediate(), true) && this._exec(function() {
var res = x + op; var res = x + op;
if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) { if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) {
res = "(" + res + ")"; res = "(" + res + ")";
} }
return res; return res;
}.call(this)) && ($l12.op = $l13, true) || ($l12.op = $l13, false)); }.call(this)) && ($l14.op = $l15, true) || ($l14.op = $l15, false));
}; };


BSJSTranslator.prototype["return"] = function $return() { BSJSTranslator.prototype["return"] = function $return() {
Expand All @@ -1273,14 +1273,14 @@ BSJSTranslator.prototype["if"] = function $if() {
}; };


BSJSTranslator.prototype["condExpr"] = function $condExpr() { BSJSTranslator.prototype["condExpr"] = function $condExpr() {
var prevOp, $l14, $l15, cond, t, e; var prevOp, $l16, $l17, cond, t, e;
return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l14 = this, $l15 = $l14.op, $l14.op = "?:", true) && (this._rule("trans", false, [], null, this["trans"]) && (cond = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (t = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (e = this._getIntermediate(), true) && this._exec(function() { return this._exec(this.op) && (prevOp = this._getIntermediate(), true) && ($l16 = this, $l17 = $l16.op, $l16.op = "?:", true) && (this._rule("trans", false, [], null, this["trans"]) && (cond = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (t = this._getIntermediate(), true) && this._rule("trans", false, [], null, this["trans"]) && (e = this._getIntermediate(), true) && this._exec(function() {
var res = cond + "?" + t + ":" + e; var res = cond + "?" + t + ":" + e;
if (BSJSTranslator.comparePriorities(prevOp, "?:")) { if (BSJSTranslator.comparePriorities(prevOp, "?:")) {
res = "(" + res + ")"; res = "(" + res + ")";
} }
return res; return res;
}.call(this)) && ($l14.op = $l15, true) || ($l14.op = $l15, false)); }.call(this)) && ($l16.op = $l17, true) || ($l16.op = $l17, false));
}; };


BSJSTranslator.prototype["while"] = function $while() { BSJSTranslator.prototype["while"] = function $while() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ometajs/grammars/bsjs.ometajs
Expand Up @@ -259,7 +259,7 @@ ometa BSJSTranslator {
number :n -> n, number :n -> n,
string :s -> JSON.stringify(s), string :s -> JSON.stringify(s),
regExp :x -> x, regExp :x -> x,
arr trans*:xs -> ('[' + xs.join(',') + ']'), arr %(this.op = '[]') trans*:xs -> ('[' + xs.join(',') + ']'),
unop :op {this.op}:prevOp %(this.op = 'u' + op) trans:t -> { unop :op {this.op}:prevOp %(this.op = 'u' + op) trans:t -> {
var res; var res;
if (op === 'typeof' || op === 'void' || op === 'delete') { if (op === 'typeof' || op === 'void' || op === 'delete') {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/functional-test.js
Expand Up @@ -213,6 +213,11 @@ suite('Ometajs module', function() {
], ],
'a && (b || c) && d' 'a && (b || c) && d'
); );
unit(
'array and ,',
['arr', ['binop', ',', ['get', 'a'], ['get', 'b']]],
'[(a , b)]'
);
}); });
}); });


Expand Down

0 comments on commit a42565e

Please sign in to comment.