diff --git a/repl/repl.go b/repl/repl.go index a9e50862..d7fd9600 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -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 } } diff --git a/repl/repl_test.go b/repl/repl_test.go index e5324519..a98ce9a9 100644 --- a/repl/repl_test.go +++ b/repl/repl_test.go @@ -67,6 +67,14 @@ func TestREPL(t *testing.T) { r.Run("if") rt.assert(t, "compileError", NormalPrompt, "Compile error: \n File \"\", 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) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy