You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
488 B
Go
41 lines
488 B
Go
package lox
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func RunFile(path string) {
|
|
bytes, err := os.ReadFile(path)
|
|
if err != nil {
|
|
fmt.Println("Error reading file", path)
|
|
os.Exit(74)
|
|
}
|
|
run(string(bytes))
|
|
}
|
|
|
|
func RunPrompt() {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
for {
|
|
fmt.Print("> ")
|
|
|
|
line, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(74)
|
|
}
|
|
|
|
if line == "\n" {
|
|
break
|
|
}
|
|
|
|
run(line)
|
|
}
|
|
}
|
|
|
|
func run(source string) {
|
|
fmt.Println(source)
|
|
}
|