allow escaping things inside strings
This commit is contained in:
parent
2c354c4a96
commit
e2a1e5ff8d
1 changed files with 28 additions and 0 deletions
|
|
@ -195,6 +195,34 @@ func (c *Compiler) compile(tree Node) error {
|
||||||
|
|
||||||
switch tree.Type() {
|
switch tree.Type() {
|
||||||
case StringNodeType:
|
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.add(InstructionConstant)
|
||||||
c.addConstant(&StringValue{
|
c.addConstant(&StringValue{
|
||||||
tree.(*StringNode).value,
|
tree.(*StringNode).value,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue