Browse Source

parser: introduce NewError() to create lexer.Error using lexer.Position

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/8/head
Alejandro Mery 1 year ago
parent
commit
c3883cbb0d
  1. 16
      parser/error.go
  2. 8
      parser/parser.go

16
parser/error.go

@ -0,0 +1,16 @@
package parser
import (
"asciigoat.org/core/lexer"
)
// NewError creates a lexer.Error using a lexer.Position
func NewError(pos lexer.Position, content, hint string, err error) *lexer.Error {
return &lexer.Error{
Line: pos.Line,
Column: pos.Column,
Content: content,
Hint: hint,
Err: err,
}
}

8
parser/parser.go

@ -31,13 +31,7 @@ func defaultOnToken(pos lexer.Position, typ TokenType, value string) error {
func defaultOnError(pos lexer.Position, content string, err error) error {
log.Printf("%s:%v:%v: %q: %s", "error", pos.Line, pos.Column, content, err)
return lexer.Error{
Line: pos.Line,
Column: pos.Column,
Content: content,
Err: err,
}
return NewError(pos, content, "", err)
}
func (p *Parser) setDefaults() {

Loading…
Cancel
Save