Permalink
Browse files

bsjs: fix for [(a,b)]

  • Loading branch information...
indutny committed Jul 23, 2012
1 parent 4313bd5 commit a42565e5098c6e52daa035b6f5f1ba537a069811
Showing with 33 additions and 28 deletions.
  1. +27 −27 lib/ometajs/grammars/bsjs.js
  2. +1 −1 lib/ometajs/grammars/bsjs.ometajs
  3. +5 −0 test/unit/functional-test.js
@@ -1157,17 +1157,17 @@ BSJSTranslator.prototype["regExp"] = function $regExp() {
};
BSJSTranslator.prototype["arr"] = function $arr() {
- var xs;
- return this._any(function() {
+ var $l0, $l1, xs;
+ return ($l0 = this, $l1 = $l0.op, $l0.op = "[]", true) && (this._any(function() {
return this._atomic(function() {
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() {
- var op, prevOp, $l0, $l1, 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() {
+ var op, prevOp, $l2, $l3, t;
+ 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;
if (op === "typeof" || op === "void" || op === "delete") {
res = op + " " + t;
@@ -1178,18 +1178,18 @@ BSJSTranslator.prototype["unop"] = function $unop() {
res = "(" + 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() {
- var $l2, $l3, 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() {
+ var $l4, $l5, fd, tfd, x;
+ 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])) {
return x + "." + fd[1];
} else {
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() {
@@ -1198,58 +1198,58 @@ BSJSTranslator.prototype["get"] = function $get() {
};
BSJSTranslator.prototype["set"] = function $set() {
- var prevOp, lhs, $l4, $l5, 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() {
+ 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) && ($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, "=")) {
return "(" + lhs + " = " + rhs + ")";
} else {
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() {
- var prevOp, lhs, op, $l6, $l7, 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() {
+ 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) && ($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 + "=")) {
return "(" + lhs + " " + op + "= " + rhs + ")";
} else {
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() {
- var op, prevOp, $l8, $l9, 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() {
+ var op, prevOp, $l10, $l11, x, y;
+ 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;
if (BSJSTranslator.comparePriorities(prevOp, op)) {
res = "(" + 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() {
- var op, prevOp, $l10, $l11, 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() {
+ var op, prevOp, $l12, $l13, 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() {
var res = op + x;
if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) {
res = "(" + 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() {
- var op, prevOp, $l12, $l13, 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() {
+ var op, prevOp, $l14, $l15, x;
+ 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;
if (BSJSTranslator.comparePriorities(prevOp, "u" + op)) {
res = "(" + 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() {
@@ -1273,14 +1273,14 @@ BSJSTranslator.prototype["if"] = function $if() {
};
BSJSTranslator.prototype["condExpr"] = function $condExpr() {
- var prevOp, $l14, $l15, 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() {
+ var prevOp, $l16, $l17, cond, t, e;
+ 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;
if (BSJSTranslator.comparePriorities(prevOp, "?:")) {
res = "(" + 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() {
@@ -259,7 +259,7 @@ ometa BSJSTranslator {
number :n -> n,
string :s -> JSON.stringify(s),
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 -> {
var res;
if (op === 'typeof' || op === 'void' || op === 'delete') {
@@ -213,6 +213,11 @@ suite('Ometajs module', function() {
],
'a && (b || c) && d'
);
+ unit(
+ 'array and ,',
+ ['arr', ['binop', ',', ['get', 'a'], ['get', 'b']]],
+ '[(a , b)]'
+ );
});
});

0 comments on commit a42565e

Please sign in to comment.