Skip to content

Commit 7c6f07b

Browse files
committed
block importing
1 parent b80e8c9 commit 7c6f07b

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

internal/repl/repl.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,35 +278,54 @@ func (s *Session) Eval(in string) (string, bytes.Buffer, error) {
278278
// Split the lines of the input to check for special commands.
279279
inLines := strings.Split(in, "\n")
280280
var nonImportLines []string
281-
for _, line := range inLines {
281+
for idx, line := range inLines {
282282

283283
// Extract non-special lines.
284-
if !strings.HasPrefix(line, "import") && !strings.HasPrefix(line, ":") {
284+
trimLine := strings.TrimSpace(line)
285+
if !strings.HasPrefix(line, "import") && !strings.HasPrefix(line, ":") && !strings.HasPrefix(trimLine, "\"") && !strings.HasPrefix(line, ")") {
285286
nonImportLines = append(nonImportLines, line)
286287
continue
287288
}
288289

289290
// Process special commands.
291+
var args []string
290292
for _, command := range commands {
291293

294+
// Clear the args.
295+
args = []string{}
296+
292297
// Extract any argument provided with the special command.
293298
arg := strings.TrimPrefix(line, ":"+command.name)
294299
if command.name == "import" {
295300
arg = strings.TrimPrefix(arg, "import")
296301
}
297-
if arg == line {
302+
switch {
303+
case arg == line:
298304
continue
305+
case strings.HasPrefix(strings.TrimSpace(arg), "("):
306+
advance := 1
307+
currentLine := inLines[idx+advance]
308+
for !strings.Contains(currentLine, ")") {
309+
fmt.Println(currentLine)
310+
args = append(args, currentLine)
311+
advance++
312+
currentLine = inLines[idx+advance]
313+
}
314+
default:
315+
args = append(args, arg)
299316
}
300317

301318
// Apply the action associated with the special command.
302-
if arg == "" || strings.HasPrefix(arg, " ") {
303-
arg = strings.TrimSpace(arg)
304-
_, err := command.action(s, arg)
305-
if err != nil {
306-
if err == ErrQuit {
307-
return "", bytes.Buffer{}, err
319+
for _, arg = range args {
320+
if arg == "" || strings.HasPrefix(arg, " ") {
321+
arg = strings.TrimSpace(arg)
322+
_, err := command.action(s, arg)
323+
if err != nil {
324+
if err == ErrQuit {
325+
return "", bytes.Buffer{}, err
326+
}
327+
errorf("%s: %s", command.name, err)
308328
}
309-
errorf("%s: %s", command.name, err)
310329
}
311330
}
312331
}

0 commit comments

Comments
 (0)