allow escaping things inside strings

This commit is contained in:
Neemek 2026-07-11 10:52:20 +02:00
parent 2c354c4a96
commit e2a1e5ff8d
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E

View file

@ -195,6 +195,34 @@ func (c *Compiler) compile(tree Node) error {
switch tree.Type() {
case StringNodeType:
n := tree.(*StringNode)
s := ""
escaped := false
for _, ch := range n.value {
if escaped {
switch ch {
case 'n':
s += "\n"
case 't':
s += "\t"
case 'r':
s += "\r"
default:
s += string(ch)
}
escaped = false
continue
}
switch ch {
case '\\':
escaped = true
default:
s += string(ch)
}
}
c.add(InstructionConstant)
c.addConstant(&StringValue{
tree.(*StringNode).value,