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
|
|
@ -18,6 +18,7 @@
|
|||
package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ loop:
|
|||
constructor.WriteString(iter.FmtToken())
|
||||
}
|
||||
|
||||
println(constructor.String())
|
||||
fmt.Printf(constructor.String() + "\n")
|
||||
goto loop
|
||||
}
|
||||
|
||||
|
|
|
|||
20
cmd/shs.go
20
cmd/shs.go
|
|
@ -31,6 +31,22 @@ const (
|
|||
def_prompt string = "λ "
|
||||
)
|
||||
|
||||
|
||||
// useful for when input contains escape sequences
|
||||
// not checking delims cause thats up to the user who defines their prompts
|
||||
func parseString(in string) string {
|
||||
in = "\"" + in + "\""
|
||||
out, err := strconv.Unquote(in)
|
||||
if err != nil {
|
||||
log.Log(log.ERR,
|
||||
"Couldnt parse (pre?)prompt",
|
||||
"init")
|
||||
return ""
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func setLogLvl(vars ast.VarTable) {
|
||||
var loglvl string
|
||||
|
||||
|
|
@ -80,7 +96,7 @@ func main() {
|
|||
|
||||
prompt_t := ast.GetVar("SHS_STATIC_PROMPT", vars)
|
||||
if prompt_t != nil {
|
||||
prompt = prompt_t.Value()
|
||||
prompt = parseString(prompt_t.Value())
|
||||
} else {
|
||||
prompt = def_prompt
|
||||
}
|
||||
|
|
@ -110,7 +126,7 @@ func main() {
|
|||
if dyn_prompt != nil {
|
||||
p_tok := dyn_prompt.CallFunction(nil, vars, funcs)
|
||||
if p_tok != nil && p_tok.Tag == ast.STRING {
|
||||
prePrompt = p_tok.Value()
|
||||
prePrompt = parseString(p_tok.Value())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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