refactor how repl works
Some checks failed
Build / build (push) Failing after 5m26s
Publish Image / publish (push) Failing after 45s
Test / build (push) Failing after 5m54s

This commit is contained in:
Chuck Smith
2024-03-28 16:51:54 -04:00
parent fc6ceee02c
commit 244b71d245
32 changed files with 612 additions and 476 deletions

View File

@@ -61,6 +61,7 @@ type (
)
type Parser struct {
fn string
l *lexer.Lexer
errors []string
@@ -71,8 +72,9 @@ type Parser struct {
infixParseFns map[token.TokenType]infixParseFn
}
func New(l *lexer.Lexer) *Parser {
func New(fn string, l *lexer.Lexer) *Parser {
p := &Parser{
fn: fn,
l: l,
errors: []string{},
}
@@ -619,3 +621,11 @@ func (p *Parser) parseImportExpression() ast.Expression {
return expression
}
// Parse parses the input source into a top-level AST for either evaluation
// or compilation to bytecode. The parameter fn denotes the filename the source
// originated from.
func Parse(fn, input string) (prog ast.Node, errors []string) {
p := New(fn, lexer.New(input))
return p.ParseProgram(), p.Errors()
}