Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix comments in REPL - fixes #78 #79

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

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ func (r *REPL) Run(line string) {
// FIXME detect EOF properly!
errText := err.Error()
if strings.Contains(errText, "unexpected EOF while parsing") || strings.Contains(errText, "EOF while scanning triple-quoted string literal") {
r.continuation = true
r.previous += string(line) + "\n"
r.term.SetPrompt(ContinuationPrompt)
stripped := strings.TrimSpace(toCompile)
isComment := len(stripped) > 0 && stripped[0] == '#'
if !isComment {
r.continuation = true
r.previous += string(line) + "\n"
r.term.SetPrompt(ContinuationPrompt)
}
return
}
}
Expand Down
8 changes: 8 additions & 0 deletions repl/repl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func TestREPL(t *testing.T) {

r.Run("if")
rt.assert(t, "compileError", NormalPrompt, "Compile error: \n File \"<string>\", line 1, offset 2\n if\n\n\nSyntaxError: 'invalid syntax'")

// test comments in the REPL work properly
r.Run("# this is a comment")
rt.assert(t, "comment", NormalPrompt, "")
r.Run("a = 42")
rt.assert(t, "comment continuation", NormalPrompt, "")
r.Run("a")
rt.assert(t, "comment check", NormalPrompt, "42")
}

func TestCompleter(t *testing.T) {
Expand Down