Skip to content

block importing #41

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
Aug 17, 2016
Merged
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
39 changes: 29 additions & 10 deletions internal/repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,35 +278,54 @@ func (s *Session) Eval(in string) (string, bytes.Buffer, error) {
// Split the lines of the input to check for special commands.
inLines := strings.Split(in, "\n")
var nonImportLines []string
for _, line := range inLines {
for idx, line := range inLines {

// Extract non-special lines.
if !strings.HasPrefix(line, "import") && !strings.HasPrefix(line, ":") {
trimLine := strings.TrimSpace(line)
if !strings.HasPrefix(line, "import") && !strings.HasPrefix(line, ":") && !strings.HasPrefix(trimLine, "\"") && !strings.HasPrefix(line, ")") {
nonImportLines = append(nonImportLines, line)
continue
}

// Process special commands.
var args []string
for _, command := range commands {

// Clear the args.
args = []string{}

// Extract any argument provided with the special command.
arg := strings.TrimPrefix(line, ":"+command.name)
if command.name == "import" {
arg = strings.TrimPrefix(arg, "import")
}
if arg == line {
switch {
case arg == line:
continue
case strings.HasPrefix(strings.TrimSpace(arg), "("):
advance := 1
currentLine := inLines[idx+advance]
for !strings.Contains(currentLine, ")") {
fmt.Println(currentLine)
args = append(args, currentLine)
advance++
currentLine = inLines[idx+advance]
}
default:
args = append(args, arg)
}

// Apply the action associated with the special command.
if arg == "" || strings.HasPrefix(arg, " ") {
arg = strings.TrimSpace(arg)
_, err := command.action(s, arg)
if err != nil {
if err == ErrQuit {
return "", bytes.Buffer{}, err
for _, arg = range args {
if arg == "" || strings.HasPrefix(arg, " ") {
arg = strings.TrimSpace(arg)
_, err := command.action(s, arg)
if err != nil {
if err == ErrQuit {
return "", bytes.Buffer{}, err
}
errorf("%s: %s", command.name, err)
}
errorf("%s: %s", command.name, err)
}
}
}
Expand Down