aboutsummaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/parser.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/parser/parser.go b/parser/parser.go
index 725b0c6..b8c27d9 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -40,7 +40,7 @@ type (
type Parser struct {
l *lexer.Lexer
- errors []string
+ errors []error
curToken token.Token
peekToken token.Token
@@ -111,18 +111,18 @@ func (p *Parser) expectPeek(t token.TokenType) bool {
}
}
-func (p *Parser) Errors() []string {
+func (p *Parser) Errors() []error {
return p.errors
}
func (p *Parser) peekError(t token.TokenType) {
- msg := fmt.Sprintf("expected next token to be %s, got %s instead", t, p.peekToken.Type)
- p.errors = append(p.errors, msg)
+ err := fmt.Errorf("expected next token to be %s, got %s instead", t, p.peekToken.Type)
+ p.errors = append(p.errors, err)
}
func (p *Parser) noPrefixParseFnError(t token.TokenType) {
- msg := fmt.Sprintf("no prefix parse function for %s found", t)
- p.errors = append(p.errors, msg)
+ err := fmt.Errorf("no prefix parse function for %s found", t)
+ p.errors = append(p.errors, err)
}
func (p *Parser) ParseProgram() *ast.Program {
@@ -247,8 +247,8 @@ func (p *Parser) parseIntegerLiteral() ast.Expression {
value, err := strconv.ParseInt(p.curToken.Literal, 0, 64)
if err != nil {
- msg := fmt.Sprintf("could not parse %q as integer", p.curToken.Literal)
- p.errors = append(p.errors, msg)
+ err = fmt.Errorf("could not parse %q as integer: %w", p.curToken.Literal, err)
+ p.errors = append(p.errors, err)
return nil
}