parser: Unquoted(), AcceptQuotedString()

TODO: reduce quoted strings with escaped characters

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-04 15:33:46 +00:00
parent d8af7821e4
commit b16aa02140
3 changed files with 129 additions and 5 deletions
+23
View File
@@ -1,6 +1,8 @@
package parser
import (
"io/fs"
"asciigoat.org/core/lexer"
)
@@ -25,3 +27,24 @@ func ErrPlusPosition(pos lexer.Position, e *lexer.Error) *lexer.Error {
return NewError(pos, e.Content, e.Hint, 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 NewError(pos, s, hint, fs.ErrInvalid)
}