Преглед изворни кода

add note about haxe.macro.Printer regarding invalid syntax

closes #11806
Simon Krajewski пре 9 месеци
родитељ
комит
2a2061beeb
1 измењених фајлова са 16 додато и 14 уклоњено
  1. 16 14
      std/haxe/macro/Printer.hx

+ 16 - 14
std/haxe/macro/Printer.hx

@@ -30,6 +30,9 @@ using StringTools;
 /**
 	This class provides some utility methods to convert elements from the
 	macro context to a human-readable String representation.
+
+	This is only guaranteed to work with data that corresponds to valid Haxe
+	syntax.
  */
 class Printer {
 	var tabs:String;
@@ -87,7 +90,8 @@ class Printer {
 				.replace("\t", "\\t")
 				.replace("\r", "\\r")
 				.replace("'", "\\'")
-				.replace('"', "\\\"") #if sys .replace("\x00", "\\x00") #end + delim;
+				.replace('"', "\\\"")
+				#if sys .replace("\x00", "\\x00") #end + delim;
 	}
 
 	public function printFormatString(s:String) {
@@ -401,18 +405,15 @@ class Printer {
 					}
 
 					(isEnum ? "enum " : "")
-					+ "abstract "
-					+ t.name
-					+ ((t.params != null && t.params.length > 0) ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "")
-					+ (tthis == null ? "" : "(" + printComplexType(tthis) + ")")
-					+ [for (f in from) " from " + printComplexType(f)].join("")
-					+ [for (f in to) " to " + printComplexType(f)].join("")
-					+ " {\n"
-					+ [
-						for (f in t.fields) {
-							tabs + printFieldWithDelimiter(f);
-						}
-					].join("\n") + "\n}";
+						+ "abstract "
+						+ t.name
+						+ ((t.params != null && t.params.length > 0) ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "")
+						+ (tthis == null ? "" : "(" + printComplexType(tthis) + ")")
+						+ [for (f in from) " from " + printComplexType(f)].join("") + [for (f in to) " to " + printComplexType(f)].join("") + " {\n" + [
+							for (f in t.fields) {
+								tabs + printFieldWithDelimiter(f);
+							}
+						].join("\n") + "\n}";
 				case TDField(kind, access):
 					tabs = old;
 					(access != null && access.length > 0 ? access.map(printAccess).join(" ") + " " : "") + switch (kind) {
@@ -473,7 +474,8 @@ class Printer {
 					loopI(e1);
 					loopI(e2);
 				case EField(e, field, kind):
-					if (kind == null) kind = Normal;
+					if (kind == null)
+						kind = Normal;
 					add('EField $field (${kind.getName()})');
 					loopI(e);
 				case EParenthesis(e):