@@ -0,0 +1,51 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user