2023-09-26 10:23:04 -07:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.Debug.Transpiler;
|
|
|
|
|
|
|
|
public class LiteralExpression : Expression
|
|
|
|
{
|
|
|
|
public Token Literal { get; set; }
|
|
|
|
|
|
|
|
public LiteralExpression(Token literal, int line, int col)
|
|
|
|
: base(line, col)
|
|
|
|
{
|
|
|
|
Literal = literal;
|
|
|
|
}
|
|
|
|
|
2023-09-29 11:32:15 -07:00
|
|
|
public string EscapedLiteral()
|
|
|
|
{
|
|
|
|
return Literal.Value.Replace("\"", "\\\"")
|
|
|
|
.Replace("'", "\\'")
|
|
|
|
.Replace("\n", "\\n")
|
|
|
|
.Replace("\t", "\\t");
|
|
|
|
}
|
|
|
|
|
2023-09-26 10:23:04 -07:00
|
|
|
public override string Transpile()
|
|
|
|
{
|
2023-09-29 11:32:15 -07:00
|
|
|
var val = EscapedLiteral();
|
2023-09-26 10:23:04 -07:00
|
|
|
if (Literal.Type == TokenType.NodePath)
|
|
|
|
{
|
2023-09-26 10:25:55 -07:00
|
|
|
return $"from.call(\"{val}\")";
|
2023-09-26 10:23:04 -07:00
|
|
|
}
|
|
|
|
else if (Literal.Type == TokenType.String)
|
|
|
|
{
|
2023-09-29 11:32:15 -07:00
|
|
|
return $"\"{val}\"";
|
2023-09-26 10:23:04 -07:00
|
|
|
}
|
|
|
|
return Literal.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string TranspileNodePath()
|
|
|
|
{
|
2023-09-29 11:32:15 -07:00
|
|
|
var val = EscapedLiteral();
|
2023-09-26 10:23:04 -07:00
|
|
|
return $"to_node_path.call(\"{val}\")";
|
|
|
|
}
|
|
|
|
}
|