Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-03 21:17:22 +00:00
parent 95f740c0e2
commit b8c438d1de
4 changed files with 262 additions and 5 deletions
+51
View File
@@ -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,
}
}