1 Commits

Author SHA1 Message Date
amery 397e06c02a WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-04 13:43:28 +00:00
3 changed files with 33 additions and 17 deletions
+12 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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() {