parser: use GetPositionalLength() on TextParser.Discard() and TextParser.Emit()

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-03 17:43:10 +00:00
parent 8cc75da138
commit baf2a97379
+6 -5
View File
@@ -39,9 +39,10 @@ func (p *TextParser) InitString(s string) {
// Discard shadows [lexer.Reader]'s, and takes in consideration
// new lines on the discarded data when moving the position
func (*TextParser) Discard() {
// TODO: consider new lines
panic("not implemented")
func (p *TextParser) Discard() {
s := p.Reader.Emit()
l := GetPositionalLength(s)
p.pos.Add(l)
}
// Emit returns the accepted text, its position, and
@@ -49,8 +50,8 @@ func (*TextParser) Discard() {
func (p *TextParser) Emit() (lexer.Position, string) {
pos := p.pos
s := p.Reader.Emit()
// TODO: consider new lines
p.pos.StepN(len(s))
l := GetPositionalLength(s)
p.pos.Add(l)
return pos, s
}