feat: read from std in
This commit is contained in:
2
Makefile
2
Makefile
@@ -5,4 +5,4 @@ it:
|
|||||||
@ chmod +x ${BINARY_NAME}
|
@ chmod +x ${BINARY_NAME}
|
||||||
|
|
||||||
ex: it
|
ex: it
|
||||||
@ ./lambda.exe -v "(\add.(add (add \f.\x.x)) \n.\f.\x.(f ((n f) x)))"
|
@ ./lambda.exe - < ./samples/simple.txt
|
||||||
@@ -20,6 +20,11 @@ func main() {
|
|||||||
logger.Info("Using program arguments.", "args", os.Args)
|
logger.Info("Using program arguments.", "args", os.Args)
|
||||||
logger.Info("Parsed CLI options.", "options", options)
|
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))
|
tokens, fails := tokenizer.GetTokens([]rune(options.Input))
|
||||||
if len(fails) > 0 {
|
if len(fails) > 0 {
|
||||||
cli.HandleError(errors.Join(fails...))
|
cli.HandleError(errors.Join(fails...))
|
||||||
|
|||||||
15
internal/cli/read.go
Normal file
15
internal/cli/read.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
1
samples/simple.txt
Normal file
1
samples/simple.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(\add.(add (add (add \f.\x.x))) \n.\f.\x.(f ((n f) x)))
|
||||||
Reference in New Issue
Block a user