|
@@ -88,21 +88,21 @@ class Printer {
|
|
|
(tp.pack.length > 0 ? tp.pack.join(".") + "." : "")
|
|
|
+ tp.name
|
|
|
+ (tp.sub != null ? '.${tp.sub}' : "")
|
|
|
- + (tp.params.length > 0 ? "<" + tp.params.map(printTypeParam).join(",") + ">" : "");
|
|
|
+ + (tp.params.length > 0 ? "<" + tp.params.map(printTypeParam).join(", ") + ">" : "");
|
|
|
|
|
|
// TODO: check if this can cause loops
|
|
|
public function printComplexType(ct:ComplexType) return switch(ct) {
|
|
|
case TPath(tp): printTypePath(tp);
|
|
|
- case TFunction(args, ret): args.map(printComplexType).join("->") + "->" + printComplexType(ret);
|
|
|
- case TAnonymous(fields): "{" + [for (f in fields) printField(f) + ";"].join("") + "}";
|
|
|
+ case TFunction(args, ret): args.map(printComplexType).join(" -> ") + " -> " + printComplexType(ret);
|
|
|
+ case TAnonymous(fields): "{ " + [for (f in fields) printField(f) + "; "].join("") + "}";
|
|
|
case TParent(ct): "(" + printComplexType(ct) + ")";
|
|
|
case TOptional(ct): "?" + printComplexType(ct);
|
|
|
- case TExtend(tp, fields): '{${printTypePath(tp)} >, ${fields.map(printField).join(",")}}';
|
|
|
+ case TExtend(tp, fields): '{${printTypePath(tp)} >, ${fields.map(printField).join(", ")} }';
|
|
|
}
|
|
|
|
|
|
public function printMetadata(meta:MetadataEntry) return
|
|
|
'@${meta.name}'
|
|
|
- + (meta.params.length > 0 ? '(${printExprs(meta.params,",")})' : "");
|
|
|
+ + (meta.params.length > 0 ? '(${printExprs(meta.params,", ")})' : "");
|
|
|
|
|
|
public function printAccess(access:Access) return switch(access) {
|
|
|
case AStatic: "static";
|
|
@@ -119,50 +119,50 @@ class Printer {
|
|
|
+ (field.meta != null && field.meta.length > 0 ? field.meta.map(printMetadata).join(" ") + " " : "")
|
|
|
+ (field.access != null && field.access.length > 0 ? field.access.map(printAccess).join(" ") + " " : "")
|
|
|
+ switch(field.kind) {
|
|
|
- case FVar(t, eo): 'var ${field.name}' + opt(t, printComplexType, ":") + opt(eo, printExpr, "=");
|
|
|
- case FProp(get, set, t, eo): 'var ${field.name}($get,$set)' + opt(t, printComplexType, ":") + opt(eo, printExpr, "=");
|
|
|
+ case FVar(t, eo): 'var ${field.name}' + opt(t, printComplexType, " : ") + opt(eo, printExpr, " = ");
|
|
|
+ case FProp(get, set, t, eo): 'var ${field.name}($get, $set)' + opt(t, printComplexType, " : ") + opt(eo, printExpr, " = ");
|
|
|
case FFun(func): 'function ${field.name}' + printFunction(func);
|
|
|
}
|
|
|
|
|
|
public function printTypeParamDecl(tpd:TypeParamDecl) return
|
|
|
tpd.name
|
|
|
- + (tpd.params != null && tpd.params.length > 0 ? "<" + tpd.params.map(printTypeParamDecl).join(",") + ">" : "")
|
|
|
- + (tpd.constraints != null && tpd.constraints.length > 0 ? ":(" + tpd.constraints.map(printComplexType).join(",") + ")" : "");
|
|
|
+ + (tpd.params != null && tpd.params.length > 0 ? "<" + tpd.params.map(printTypeParamDecl).join(", ") + ">" : "")
|
|
|
+ + (tpd.constraints != null && tpd.constraints.length > 0 ? ":(" + tpd.constraints.map(printComplexType).join(", ") + ")" : "");
|
|
|
|
|
|
public function printFunctionArg(arg:FunctionArg) return
|
|
|
(arg.opt ? "?" : "")
|
|
|
+ arg.name
|
|
|
- + opt(arg.type, printComplexType, ":")
|
|
|
- + opt(arg.value, printExpr, "=");
|
|
|
+ + opt(arg.type, printComplexType, " : ")
|
|
|
+ + opt(arg.value, printExpr, " = ");
|
|
|
|
|
|
public function printFunction(func:Function) return
|
|
|
- (func.params.length > 0 ? "<" + func.params.map(printTypeParamDecl).join(",") + ">" : "")
|
|
|
- + "(" + func.args.map(printFunctionArg).join(",") + ")"
|
|
|
- + opt(func.ret, printComplexType, ":")
|
|
|
+ (func.params.length > 0 ? "<" + func.params.map(printTypeParamDecl).join(", ") + ">" : "")
|
|
|
+ + "( " + func.args.map(printFunctionArg).join(", ") + " )"
|
|
|
+ + opt(func.ret, printComplexType, " : ")
|
|
|
+ opt(func.expr, printExpr, " ");
|
|
|
|
|
|
public function printVar(v:Var) return
|
|
|
v.name
|
|
|
- + opt(v.type, printComplexType, ":")
|
|
|
- + opt(v.expr, printExpr, "=");
|
|
|
+ + opt(v.type, printComplexType, " : ")
|
|
|
+ + opt(v.expr, printExpr, " = ");
|
|
|
|
|
|
|
|
|
public function printExpr(e:Expr) return e == null ? "#NULL" : switch(e.expr) {
|
|
|
case EConst(c): printConstant(c);
|
|
|
case EArray(e1, e2): '${printExpr(e1)}[${printExpr(e2)}]';
|
|
|
- case EBinop(op, e1, e2): '${printExpr(e1)}${printBinop(op)}${printExpr(e2)}';
|
|
|
+ case EBinop(op, e1, e2): '${printExpr(e1)} ${printBinop(op)} ${printExpr(e2)}';
|
|
|
case EField(e1, n): '${printExpr(e1)}.$n';
|
|
|
case EParenthesis(e1): '(${printExpr(e1)})';
|
|
|
case EObjectDecl(fl):
|
|
|
- "{" + fl.map(function(fld) return '${fld.field}:${printExpr(fld.expr)}').join(",") + "}";
|
|
|
- case EArrayDecl(el): '[${printExprs(el, ",")}]';
|
|
|
- case ECall(e1, el): '${printExpr(e1)}(${printExprs(el,",")})';
|
|
|
- case ENew(tp, el): 'new ${printTypePath(tp)}(${printExprs(el,",")})';
|
|
|
+ "{ " + fl.map(function(fld) return '${fld.field} : ${printExpr(fld.expr)} ').join(",") + "}";
|
|
|
+ case EArrayDecl(el): '[${printExprs(el, ", ")}]';
|
|
|
+ case ECall(e1, el): '${printExpr(e1)}(${printExprs(el,", ")})';
|
|
|
+ case ENew(tp, el): 'new ${printTypePath(tp)}(${printExprs(el,", ")})';
|
|
|
case EUnop(op, true, e1): printExpr(e1) + printUnop(op);
|
|
|
case EUnop(op, false, e1): printUnop(op) + printExpr(e1);
|
|
|
case EFunction(no, func) if (no != null): 'function $no' + printFunction(func);
|
|
|
case EFunction(_, func): "function " +printFunction(func);
|
|
|
- case EVars(vl): "var " +vl.map(printVar).join(",");
|
|
|
+ case EVars(vl): "var " +vl.map(printVar).join(", ");
|
|
|
case EBlock([]): '{\n$tabs}';
|
|
|
case EBlock(el):
|
|
|
var old = tabs;
|
|
@@ -180,17 +180,17 @@ class Printer {
|
|
|
tabs += tabString;
|
|
|
var s = 'switch ${printExpr(e1)} {\n$tabs' +
|
|
|
cl.map(function(c)
|
|
|
- return 'case ${printExprs(c.values, ",")}'
|
|
|
- + (c.guard != null ? 'if(${printExpr(c.guard)}):' : ":")
|
|
|
- + (opt(c.expr, printExpr)) + ";")
|
|
|
+ return 'case ${printExprs(c.values, ", ")}'
|
|
|
+ + (c.guard != null ? ' if(${printExpr(c.guard)}): ' : ":")
|
|
|
+ + (c.expr != null ? (opt(c.expr, printExpr)) + ";" : ""))
|
|
|
.join('\n$tabs');
|
|
|
if (edef != null)
|
|
|
- s += '\n${tabs}default:' + (edef.expr == null ? "" : printExpr(edef)) + ";";
|
|
|
+ s += '\n${tabs}default: ' + (edef.expr == null ? "" : printExpr(edef)) + ";";
|
|
|
tabs = old;
|
|
|
s + '\n$tabs}';
|
|
|
case ETry(e1, cl):
|
|
|
'try ${printExpr(e1)}'
|
|
|
- + cl.map(function(c) return ' catch(${c.name}:${printComplexType(c.type)}) ${printExpr(c.expr)}').join("");
|
|
|
+ + cl.map(function(c) return ' catch(${c.name} : ${printComplexType(c.type)}) ${printExpr(c.expr)}').join("");
|
|
|
case EReturn(eo): "return" + opt(eo, printExpr, " ");
|
|
|
case EBreak: "break";
|
|
|
case EContinue: "continue";
|
|
@@ -200,7 +200,7 @@ class Printer {
|
|
|
case ECast(e1, _): "cast " +printExpr(e1);
|
|
|
case EDisplay(e1, _): '#DISPLAY(${printExpr(e1)})';
|
|
|
case EDisplayNew(tp): '#DISPLAY(${printTypePath(tp)})';
|
|
|
- case ETernary(econd, eif, eelse): '${printExpr(econd)} ? ${printExpr(eif)} : ${printExpr(eelse) }';
|
|
|
+ case ETernary(econd, eif, eelse): '${printExpr(econd)} ? ${printExpr(eif)} : ${printExpr(eelse)}';
|
|
|
case ECheckType(e1, ct): '#CHECK_TYPE(${printExpr(e1)}, ${printComplexType(ct)})';
|
|
|
case EMeta(meta, e1): printMetadata(meta) + " " +printExpr(e1);
|
|
|
}
|
|
@@ -217,7 +217,7 @@ class Printer {
|
|
|
(printPackage && t.pack.length > 0 && t.pack[0] != "" ? "package " + t.pack.join(".") + ";\n" : "") +
|
|
|
(t.meta != null && t.meta.length > 0 ? t.meta.map(printMetadata).join(" ") + " " : "") + (t.isExtern ? "extern " : "") + switch (t.kind) {
|
|
|
case TDEnum:
|
|
|
- "enum " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(",") + ">" : "") + " {\n"
|
|
|
+ "enum " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "") + " {\n"
|
|
|
+ [for (field in t.fields)
|
|
|
tabs + (field.doc != null && field.doc != "" ? "/**\n" + tabs + tabString + StringTools.replace(field.doc, "\n", "\n" + tabs + tabString) + "\n" + tabs + "**/\n" + tabs : "")
|
|
|
+ (field.meta != null && field.meta.length > 0 ? field.meta.map(printMetadata).join(" ") + " " : "")
|
|
@@ -229,13 +229,13 @@ class Printer {
|
|
|
].join("\n")
|
|
|
+ "\n}";
|
|
|
case TDStructure:
|
|
|
- "typedef " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(",") + ">" : "") + " = {\n"
|
|
|
+ "typedef " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "") + " = {\n"
|
|
|
+ [for (f in t.fields) {
|
|
|
tabs + printField(f) + ";";
|
|
|
}].join("\n")
|
|
|
+ "\n}";
|
|
|
case TDClass(superClass, interfaces, isInterface):
|
|
|
- (isInterface ? "interface " : "class ") + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(",") + ">" : "")
|
|
|
+ (isInterface ? "interface " : "class ") + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "")
|
|
|
+ (superClass != null ? " extends " + printTypePath(superClass) : "")
|
|
|
+ (interfaces != null ? (isInterface ? [for (tp in interfaces) " extends " + printTypePath(tp)] : [for (tp in interfaces) " implements " + printTypePath(tp)]).join("") : "")
|
|
|
+ " {\n"
|
|
@@ -249,13 +249,13 @@ class Printer {
|
|
|
}].join("\n")
|
|
|
+ "\n}";
|
|
|
case TDAlias(ct):
|
|
|
- "typedef " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(",") + ">" : "") + " = "
|
|
|
+ "typedef " + t.name + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "") + " = "
|
|
|
+ printComplexType(ct)
|
|
|
+ ";";
|
|
|
case TDAbstract(tthis, from, to):
|
|
|
"abstract " + t.name
|
|
|
+ (tthis == null ? "" : "(" + printComplexType(tthis) + ")")
|
|
|
- + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(",") + ">" : "")
|
|
|
+ + (t.params.length > 0 ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "")
|
|
|
+ (from == null ? "" : [for (f in from) " from " + printComplexType(f)].join(""))
|
|
|
+ (to == null ? "" : [for (t in to) " to " + printComplexType(t)].join(""))
|
|
|
+ " {\n"
|