Skip to content

Commit

Permalink
fix: function call; refactor internals
Browse files Browse the repository at this point in the history
  • Loading branch information
Houcine EL ADDALI committed Jan 10, 2024
1 parent f4fa634 commit 27dc73e
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 272 deletions.
15 changes: 4 additions & 11 deletions cmd/REPL/repel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import (
)

// REPL
// the repl used to interact with users to read from it console
// send to interpreter to evaluate then prints back the result

/*
* Function as the start method of the repl
* To interact with the user via terminal
*/

const PROMPT = "🟢>"
const PROMPT = "🟢>_"

var ctx = types.NewContext()

func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
Expand Down Expand Up @@ -55,8 +52,6 @@ func Start(in io.Reader, out io.Writer) {
pr := repParser.Parse()
errs := repParser.Errors()

fmt.Println(pr.ToString())

if len(errs) != 0 {
io.WriteString(out, fmt.Sprintf("%d errors ❌ occurred while parsing your input \n", len(errs)))
for idx, e := range errs {
Expand All @@ -65,14 +60,12 @@ func Start(in io.Reader, out io.Writer) {
continue
}

var GLOBAL_CONTEXT = types.NewContext()

evaluated ,err:= runtime.Eval(pr,GLOBAL_CONTEXT)
evaluated, err := runtime.Eval(pr, ctx)
if err != debug.NOERROR {
io.WriteString(out, fmt.Sprintf("error while evaluating your input: %s \n", err.Error()))
continue
}

if evaluated != nil {
io.WriteString(out, evaluated.ToString())
io.WriteString(out, "\n")
Expand Down
Loading

0 comments on commit 27dc73e

Please sign in to comment.