Skip to content

Commit

Permalink
add note about haxe.macro.Printer regarding invalid syntax
Browse files Browse the repository at this point in the history
closes #11806
  • Loading branch information
Simn committed Nov 19, 2024
1 parent d23d383 commit 2a2061b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions std/haxe/macro/Printer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2a2061b

Please sign in to comment.