Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix for decimal in tojson, seconds, minutes, hours functions #345

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
small fixes, liveobj if null, some spreadsheet
  • Loading branch information
refaktor committed Sep 12, 2024
commit 0e7715e07708f825cc56328a80fec37078a3a8ec
3 changes: 2 additions & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,10 @@ type LiveEnv struct {
func NewLiveEnv() *LiveEnv {
watcher, err := fsnotify.NewWatcher()
if err != nil {
// fmt.Println("Error creating watcher:", err)
fmt.Println("Error creating watcher:", err) // TODO -- if this fails show error in red, but make it so that rye runs anyway (check if null at repl for starters)
return nil
}

// defer watcher.Close()

// Watch current directory for changes in any Go source file (*.go)
Expand Down
16 changes: 16 additions & 0 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ func getFrom(ps *env.ProgramState, data any, key any, posMode bool) env.Object {
return env.NewError1(5) // NOT_FOUND
}
}
case env.Spreadsheet:
switch s2 := key.(type) {
case env.Integer:
idx := s2.Value
if posMode {
idx--
}
v := s1.Rows[idx]
ok := true
if ok {
return v
} else {
ps.FailureFlag = true
return env.NewError1(5) // NOT_FOUND
}
}
case env.SpreadsheetRow:
switch s2 := key.(type) {
case env.String:
Expand Down
16 changes: 9 additions & 7 deletions evaldo/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,16 @@ func (r *Repl) recieveLine(line string) string {
}

func (r *Repl) evalLine(es *env.ProgramState, code string) string {
es.LiveObj.PsMutex.Lock()
for _, update := range es.LiveObj.Updates {
fmt.Println("\033[35m((Reloading " + update + "))\033[0m")
block_, script_ := LoadScriptLocalFile(es, *env.NewUri1(es.Idx, "file://"+update))
es.Res = EvaluateLoadedValue(es, block_, script_, true)
if es.LiveObj != nil {
es.LiveObj.PsMutex.Lock()
for _, update := range es.LiveObj.Updates {
fmt.Println("\033[35m((Reloading " + update + "))\033[0m")
block_, script_ := LoadScriptLocalFile(es, *env.NewUri1(es.Idx, "file://"+update))
es.Res = EvaluateLoadedValue(es, block_, script_, true)
}
es.LiveObj.ClearUpdates()
es.LiveObj.PsMutex.Unlock()
}
es.LiveObj.ClearUpdates()
es.LiveObj.PsMutex.Unlock()

multiline := len(code) > 1 && code[len(code)-1:] == " "

Expand Down
60 changes: 0 additions & 60 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,66 +397,6 @@ func main_rye_file(file string, sig bool, subc bool, interactive bool, code stri
}
}

func main_rye_file_OLD(file string, sig bool, subc bool, interactive bool, code string) {
info := true
//util.PrintHeader()
//defer profile.Start(profile.CPUProfile).Stop()

var content string

if file[len(file)-4:] == ".enc" {
fmt.Print("Enter Password: ")
bytePassword, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
password := string(bytePassword)

content = util.ReadSecure(file, password)
} else {
bcontent, err := os.ReadFile(file)
if err != nil {
log.Fatal(err)
}
content = string(bcontent)
}

if info {
pattern := regexp.MustCompile(`^; (#[^\n]*)`)

lines := pattern.FindAllStringSubmatch(content, -1)

for _, line := range lines {
if line[1] != "" {
fmt.Println(line[1])
}
}
}

block, genv := loader.LoadString(content+"\n"+code, sig)
switch val := block.(type) {
case env.Block:
es := env.NewProgramState(block.(env.Block).Series, genv)
evaldo.RegisterBuiltins(es)
contrib.RegisterBuiltins(es, &evaldo.BuiltinNames)

if subc {
ctx := es.Ctx
es.Ctx = env.NewEnv(ctx)
}

evaldo.EvalBlock(es)
evaldo.MaybeDisplayFailureOrError(es, genv)

if interactive {
evaldo.DoRyeRepl(es, "rye", evaldo.ShowResults)
}

case env.Error:
fmt.Println(val.Message)
}
}

func main_cgi_file(file string, sig bool) {
if err := cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//util.PrintHeader()
Expand Down