refactor how repl works
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user