Skip to content

Commit b29aaba

Browse files
committed
Allow spaces in gdscript.Syntax.dollar path
1 parent ddc560b commit b29aaba

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

std/gdscript/Syntax.hx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,33 @@ class Syntax {
8585
```
8686
**/
8787
public static macro function dollar(identifier: Expr): Expr {
88-
final identifier = switch(identifier.expr) {
88+
var identifier = switch(identifier.expr) {
8989
case EConst(CString(s, _) | CIdent(s)): s;
9090
case _: {
9191
Context.error("Expected String or identifier expression", identifier.pos);
9292
return macro {};
9393
}
9494
}
9595

96-
final identifier = "$" + identifier;
96+
// Check if the input content contains a space.
97+
final hasSpace = {
98+
var result = false;
99+
final len = identifier.length;
100+
for(i in 0...len) {
101+
if(StringTools.isSpace(identifier, i)) {
102+
result = true;
103+
break;
104+
}
105+
}
106+
result;
107+
}
108+
109+
// Wrap with quotes if the identifier has a space.
110+
if(hasSpace) {
111+
identifier = '"${identifier}"';
112+
}
113+
114+
identifier = "$" + identifier;
97115
return macro untyped __gdscript__($v{identifier});
98116
}
99117
}

0 commit comments

Comments
 (0)