diff --git a/Makefile b/Makefile index 5874839..ea3bfed 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ it: @ chmod +x ${BINARY_NAME} ex: it - @ ./lambda.exe -v "(\add.(add (add \f.\x.x)) \n.\f.\x.(f ((n f) x)))" \ No newline at end of file + @ ./lambda.exe - < ./samples/simple.txt \ No newline at end of file diff --git a/cmd/lambda/lambda.go b/cmd/lambda/lambda.go index b94c046..1f35c85 100644 --- a/cmd/lambda/lambda.go +++ b/cmd/lambda/lambda.go @@ -20,6 +20,11 @@ func main() { logger.Info("Using program arguments.", "args", os.Args) logger.Info("Parsed CLI options.", "options", options) + if options.Input == "-" { + options.Input, err = cli.ReadInput() + cli.HandleError(err) + } + tokens, fails := tokenizer.GetTokens([]rune(options.Input)) if len(fails) > 0 { cli.HandleError(errors.Join(fails...)) diff --git a/internal/cli/read.go b/internal/cli/read.go new file mode 100644 index 0000000..93b762c --- /dev/null +++ b/internal/cli/read.go @@ -0,0 +1,15 @@ +package cli + +import ( + "io" + "os" +) + +func ReadInput() (string, error) { + data, err := io.ReadAll(os.Stdin) + if err != nil { + return "", err + } + + return string(data), nil +} diff --git a/samples/simple.txt b/samples/simple.txt new file mode 100644 index 0000000..be9d8a3 --- /dev/null +++ b/samples/simple.txt @@ -0,0 +1 @@ +(\add.(add (add (add \f.\x.x))) \n.\f.\x.(f ((n f) x))) \ No newline at end of file