feat: better structured internal

This commit is contained in:
2025-12-25 17:21:16 -05:00
parent d9deee0734
commit 3351eaddfc
8 changed files with 102 additions and 31 deletions

View File

@@ -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 {