Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2b6603537 | |||
| aca41c263d | |||
| 90579c1a54 | |||
| fdc7dc0ad5 |
+3
-12
@@ -4,28 +4,19 @@ 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 newError(t.pos, t.value, "", errInvalidToken)
|
||||
return parser.NewError(t.pos, t.value, "", errInvalidToken)
|
||||
}
|
||||
|
||||
func (dec *decoder) OnError(pos lexer.Position, content string, err error) error {
|
||||
err = newError(pos, content, "", err)
|
||||
err = parser.NewError(pos, content, "", err)
|
||||
dec.executeFinal()
|
||||
return err
|
||||
}
|
||||
|
||||
+13
-14
@@ -6,6 +6,17 @@ 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 {
|
||||
@@ -14,13 +25,7 @@ func ErrPlusPosition(pos lexer.Position, e *lexer.Error) *lexer.Error {
|
||||
Column: e.Column,
|
||||
})
|
||||
|
||||
return &lexer.Error{
|
||||
Line: pos.Line,
|
||||
Column: pos.Column,
|
||||
Content: e.Content,
|
||||
Hint: e.Hint,
|
||||
Err: e.Err,
|
||||
}
|
||||
return NewError(pos, e.Content, e.Hint, e.Err)
|
||||
}
|
||||
|
||||
// NewErrIncompleteQuotedString returns a [lexer.Error]
|
||||
@@ -41,11 +46,5 @@ func newErrIncomplete(p *TextParser, hint string) *lexer.Error {
|
||||
pos, s := p.Emit()
|
||||
pos.Add(GetPositionalLength(s))
|
||||
|
||||
return &lexer.Error{
|
||||
Line: pos.Line,
|
||||
Column: pos.Column,
|
||||
Content: s,
|
||||
Hint: hint,
|
||||
Err: fs.ErrInvalid,
|
||||
}
|
||||
return NewError(pos, s, hint, fs.ErrInvalid)
|
||||
}
|
||||
|
||||
+1
-7
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user