minor clean-up (#4998)
This commit is contained in:
@@ -1134,58 +1134,54 @@
|
||||
}
|
||||
|
||||
function map(moztype, mytype, propmap) {
|
||||
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
||||
moz_to_me += "return new U2." + mytype.name + "({\n" +
|
||||
"start: my_start_token(M),\n" +
|
||||
"end: my_end_token(M)";
|
||||
|
||||
var me_to_moz = "function To_Moz_" + moztype + "(M){\n";
|
||||
me_to_moz += "return {\n" +
|
||||
"type: " + JSON.stringify(moztype);
|
||||
var moz_to_me = [
|
||||
"start: my_start_token(M)",
|
||||
"end: my_end_token(M)",
|
||||
];
|
||||
var me_to_moz = [
|
||||
"type: " + JSON.stringify(moztype),
|
||||
];
|
||||
|
||||
if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop) {
|
||||
var m = /([a-z0-9$_]+)(=|@|>|%)([a-z0-9$_]+)/i.exec(prop);
|
||||
if (!m) throw new Error("Can't understand property map: " + prop);
|
||||
var moz = m[1], how = m[2], my = m[3];
|
||||
moz_to_me += ",\n" + my + ": ";
|
||||
me_to_moz += ",\n" + moz + ": ";
|
||||
switch (how) {
|
||||
case "@":
|
||||
moz_to_me += "M." + moz + ".map(from_moz)";
|
||||
me_to_moz += "M." + my + ".map(to_moz)";
|
||||
moz_to_me.push(my + ": M." + moz + ".map(from_moz)");
|
||||
me_to_moz.push(moz + ": M." + my + ".map(to_moz)");
|
||||
break;
|
||||
case ">":
|
||||
moz_to_me += "from_moz(M." + moz + ")";
|
||||
me_to_moz += "to_moz(M." + my + ")";
|
||||
moz_to_me.push(my + ": from_moz(M." + moz + ")");
|
||||
me_to_moz.push(moz + ": to_moz(M." + my + ")");
|
||||
break;
|
||||
case "=":
|
||||
moz_to_me += "M." + moz;
|
||||
me_to_moz += "M." + my;
|
||||
moz_to_me.push(my + ": M." + moz);
|
||||
me_to_moz.push(moz + ": M." + my);
|
||||
break;
|
||||
case "%":
|
||||
moz_to_me += "from_moz(M." + moz + ").body";
|
||||
me_to_moz += "to_moz_block(M)";
|
||||
moz_to_me.push(my + ": from_moz(M." + moz + ").body");
|
||||
me_to_moz.push(moz + ": to_moz_block(M)");
|
||||
break;
|
||||
default:
|
||||
throw new Error("Can't understand operator in propmap: " + prop);
|
||||
}
|
||||
});
|
||||
|
||||
moz_to_me += "\n})\n}";
|
||||
me_to_moz += "\n}\n}";
|
||||
|
||||
//moz_to_me = parse(moz_to_me).print_to_string({ beautify: true });
|
||||
//me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
|
||||
//console.log(moz_to_me);
|
||||
|
||||
moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
|
||||
exports, my_start_token, my_end_token, from_moz
|
||||
);
|
||||
me_to_moz = new Function("to_moz", "to_moz_block", "to_moz_scope", "return(" + me_to_moz + ")")(
|
||||
to_moz, to_moz_block, to_moz_scope
|
||||
);
|
||||
MOZ_TO_ME[moztype] = moz_to_me;
|
||||
def_to_moz(mytype, me_to_moz);
|
||||
MOZ_TO_ME[moztype] = new Function("U2", "my_start_token", "my_end_token", "from_moz", [
|
||||
"return function From_Moz_" + moztype + "(M) {",
|
||||
" return new U2.AST_" + mytype.TYPE + "({",
|
||||
moz_to_me.join(",\n"),
|
||||
" });",
|
||||
"};",
|
||||
].join("\n"))(exports, my_start_token, my_end_token, from_moz);
|
||||
def_to_moz(mytype, new Function("to_moz", "to_moz_block", "to_moz_scope", [
|
||||
"return function To_Moz_" + moztype + "(M) {",
|
||||
" return {",
|
||||
me_to_moz.join(",\n"),
|
||||
" };",
|
||||
"};",
|
||||
].join("\n"))(to_moz, to_moz_block, to_moz_scope));
|
||||
}
|
||||
|
||||
var FROM_MOZ_STACK = null;
|
||||
|
||||
Reference in New Issue
Block a user