add stdlib package with readme
This commit is contained in:
parent
c40aea7326
commit
0b3bac7bca
9 changed files with 123 additions and 47 deletions
24
cmd/repl.go
24
cmd/repl.go
|
|
@ -18,8 +18,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"strings"
|
||||
"strconv"
|
||||
"git.callpipe.com/aidan/shs/ast"
|
||||
"git.callpipe.com/aidan/shs/log"
|
||||
|
|
@ -32,10 +34,10 @@ const (
|
|||
func setLogLvl() {
|
||||
loglvl := os.Getenv("SH_LOGGING")
|
||||
if loglvl != "" {
|
||||
llvl, ok := strconv.ParseInt(loglvl, 10, 8)
|
||||
if !ok {
|
||||
log.Log(log.Err,
|
||||
"couldnt parse log level",
|
||||
llvl, err := strconv.ParseInt(loglvl, 10, 8)
|
||||
if err != nil {
|
||||
log.Log(log.ERR,
|
||||
"couldnt parse log level: " + err.Error(),
|
||||
"init")
|
||||
} else {
|
||||
log.SetLogLvl(llvl)
|
||||
|
|
@ -49,18 +51,18 @@ func main() {
|
|||
prompt := os.Getenv("SHS_SH_PROMPT")
|
||||
|
||||
var vars ast.VarTable
|
||||
var funcs ast.VarTable
|
||||
var funcs ast.FuncTable
|
||||
|
||||
useHist := false
|
||||
var histFile os.File
|
||||
var histFile *os.File
|
||||
var err error
|
||||
|
||||
if hist != "" {
|
||||
useHist = true
|
||||
histFile, err = os.OpenFile(histFile, os.O_RDWR|os.O_CREATE, 0755)
|
||||
histFile, err = os.OpenFile(hist, os.O_RDWR|os.O_CREATE, 0755)
|
||||
if err != nil {
|
||||
useHist = false
|
||||
log.Log(log.ERR, "coudlnt open histfile: " + err, "init")
|
||||
log.Log(log.ERR, "coudlnt open histfile: " + err.Error(), "init")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +77,7 @@ func main() {
|
|||
fmt.Print(prompt + " ")
|
||||
text, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Log(log.ERR, "couldnt read user input: " + err, "repl")
|
||||
log.Log(log.ERR, "couldnt read user input: " + err.Error(), "repl")
|
||||
}
|
||||
|
||||
// TODO: replace with a regex
|
||||
|
|
@ -85,7 +87,7 @@ func main() {
|
|||
if useHist {
|
||||
_, err = histFile.Write([]byte(text + "\n"))
|
||||
if err != nil {
|
||||
log.Log(log.DEBUG, "couldnt write to histfile: " + err, "repl")
|
||||
log.Log(log.DEBUG, "couldnt write to histfile: " + err.Error(), "repl")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +99,7 @@ func main() {
|
|||
}
|
||||
|
||||
if debug != "" {
|
||||
log.PrintSExprsIndividually(userInput)
|
||||
ast.PrintSExprsIndividually(userInput)
|
||||
}
|
||||
|
||||
result := userInput.Eval(funcs, vars)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue