feat: better structured internal
This commit is contained in:
@@ -7,35 +7,37 @@ import (
|
||||
"time"
|
||||
|
||||
"git.maximhutz.com/max/lambda/internal/cli"
|
||||
"git.maximhutz.com/max/lambda/internal/config"
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
"git.maximhutz.com/max/lambda/pkg/parser"
|
||||
"git.maximhutz.com/max/lambda/pkg/tokenizer"
|
||||
)
|
||||
|
||||
// Run main application.
|
||||
func main() {
|
||||
|
||||
options, err := cli.ParseOptions(os.Args[1:])
|
||||
options, err := config.FromArgs()
|
||||
cli.HandleError(err)
|
||||
|
||||
logger := cli.GetLogger(*options)
|
||||
logger := options.GetLogger()
|
||||
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)
|
||||
}
|
||||
input, err := options.Source.Pull()
|
||||
cli.HandleError(err)
|
||||
|
||||
tokens, fails := tokenizer.GetTokens([]rune(options.Input))
|
||||
// Parse tokens.
|
||||
tokens, fails := tokenizer.GetTokens([]rune(input))
|
||||
if len(fails) > 0 {
|
||||
cli.HandleError(errors.Join(fails...))
|
||||
}
|
||||
logger.Info("Parsed tokens.", "tokens", tokens)
|
||||
|
||||
// Turn tokens into syntax tree.
|
||||
expression, err := parser.GetTree(tokens)
|
||||
cli.HandleError(err)
|
||||
logger.Info("Parsed syntax tree.", "tree", lambda.Stringify(expression))
|
||||
|
||||
// Reduce expression.
|
||||
start := time.Now()
|
||||
|
||||
if options.Explanation {
|
||||
|
||||
Reference in New Issue
Block a user