print statement should allow for escaping stuff
This commit is contained in:
parent
d0e3946aff
commit
77ce00970f
3 changed files with 35 additions and 4 deletions
|
|
@ -19,6 +19,7 @@ package stdlib
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
"gitlab.com/whom/shs/log"
|
||||
)
|
||||
|
|
@ -43,6 +44,19 @@ func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
}
|
||||
|
||||
func print_str(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
fmt.Println(in.Eval(ft, vt, false))
|
||||
body := in.Eval(ft, vt, false).String()
|
||||
if body[0] != body[len(body)-1] && body[0] != '"' {
|
||||
body = "`" + body + "`"
|
||||
}
|
||||
|
||||
text, err := strconv.Unquote(body)
|
||||
if err != nil {
|
||||
log.Log(log.ERR,
|
||||
"error unquoting string",
|
||||
"print")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf(text + "\n")
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue