Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 397e06c02a |
+12
-3
@@ -4,19 +4,28 @@ import (
|
||||
"errors"
|
||||
|
||||
"asciigoat.org/core/lexer"
|
||||
"asciigoat.org/ini/parser"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidToken = errors.New("invalid token")
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func newErrInvalidToken(t *token) *lexer.Error {
|
||||
return parser.NewError(t.pos, t.value, "", errInvalidToken)
|
||||
return newError(t.pos, t.value, "", errInvalidToken)
|
||||
}
|
||||
|
||||
func (dec *decoder) OnError(pos lexer.Position, content string, err error) error {
|
||||
err = parser.NewError(pos, content, "", err)
|
||||
err = newError(pos, content, "", err)
|
||||
dec.executeFinal()
|
||||
return err
|
||||
}
|
||||
|
||||
+14
-13
@@ -6,17 +6,6 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
// ErrPlusPosition returns a copy of the given [lexer.Error]
|
||||
// offsetting the Line/Column information.
|
||||
func ErrPlusPosition(pos lexer.Position, e *lexer.Error) *lexer.Error {
|
||||
@@ -25,7 +14,13 @@ func ErrPlusPosition(pos lexer.Position, e *lexer.Error) *lexer.Error {
|
||||
Column: e.Column,
|
||||
})
|
||||
|
||||
return NewError(pos, e.Content, e.Hint, e.Err)
|
||||
return &lexer.Error{
|
||||
Line: pos.Line,
|
||||
Column: pos.Column,
|
||||
Content: e.Content,
|
||||
Hint: e.Hint,
|
||||
Err: e.Err,
|
||||
}
|
||||
}
|
||||
|
||||
// NewErrIncompleteQuotedString returns a [lexer.Error]
|
||||
@@ -46,5 +41,11 @@ func newErrIncomplete(p *TextParser, hint string) *lexer.Error {
|
||||
pos, s := p.Emit()
|
||||
pos.Add(GetPositionalLength(s))
|
||||
|
||||
return NewError(pos, s, hint, fs.ErrInvalid)
|
||||
return &lexer.Error{
|
||||
Line: pos.Line,
|
||||
Column: pos.Column,
|
||||
Content: s,
|
||||
Hint: hint,
|
||||
Err: fs.ErrInvalid,
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -31,7 +31,13 @@ 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 NewError(pos, content, "", err)
|
||||
return lexer.Error{
|
||||
Line: pos.Line,
|
||||
Column: pos.Column,
|
||||
|
||||
Content: content,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) setDefaults() {
|
||||
|
||||
Reference in New Issue
Block a user