diff --git a/.gitignore b/.gitignore index 8d738fd..af5da0b 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ go.work *.exe *.out *.app +go/bin/* diff --git a/go/makefile b/go/makefile new file mode 100644 index 0000000..39459db --- /dev/null +++ b/go/makefile @@ -0,0 +1,12 @@ +run: + @go run main.go + +build: + @mkdir -p bin + @go build -o bin/monkey main.go + @echo "Build complete" + @echo "Run ./bin/monkey to start the program" + @echo "Or add the bin directory to your PATH" + +test: + @go test -v ./... diff --git a/go/repl/repl.go b/go/repl/repl.go index 442791c..46f92a9 100644 --- a/go/repl/repl.go +++ b/go/repl/repl.go @@ -9,7 +9,12 @@ import ( "github.com/abasnfarah/monkey-interpreter/go/token" ) -const PROMPT = ">> " +const ( + PROMPT = ">> " + HELP_MESSAGE = "help - show this help message\n" + "exit - exit the repl\n" + HELP = "help" + EXIT = "exit" +) func Start(in io.Reader, out io.Writer) { scanner := bufio.NewScanner(in) @@ -22,10 +27,15 @@ func Start(in io.Reader, out io.Writer) { } line := scanner.Text() - if line == "exit" { + if line == EXIT { return } + if line == HELP || line == "h" || line == "" { + fmt.Fprint(out, HELP_MESSAGE) + continue + } + l := lexer.New(line) fmt.Fprintf(out, "%+v\n", l)