Files
ini/parser/error.go
T
amery 397e06c02a WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-04 13:43:28 +00:00

52 lines
1.2 KiB
Go

package parser
import (
"io/fs"
"asciigoat.org/core/lexer"
)
// ErrPlusPosition returns a copy of the given [lexer.Error]
// offsetting the Line/Column information.
func ErrPlusPosition(pos lexer.Position, e *lexer.Error) *lexer.Error {
pos.Add(lexer.Position{
Line: e.Line,
Column: e.Column,
})
return &lexer.Error{
Line: pos.Line,
Column: pos.Column,
Content: e.Content,
Hint: e.Hint,
Err: e.Err,
}
}
// NewErrIncompleteQuotedString returns a [lexer.Error]
// indicating the quoted string being parsed wasn't correctly
// terminated
func NewErrIncompleteQuotedString(p *TextParser) *lexer.Error {
return newErrIncomplete(p, "incomplete quoted string")
}
// NewErrIncompleteEscaped returns a [lexer.Error]
// indicating the text being parsed wasn't correctly
// terminated
func NewErrIncompleteEscaped(p *TextParser) *lexer.Error {
return newErrIncomplete(p, "incomplete escaped string")
}
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,
}
}