Browse Source

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

Signed-off-by: Alejandro Mery <amery@jpi.io>
Alejandro Mery 1 year ago
parent
commit
baf2a97379
  1. 11
      parser/text.go

11
parser/text.go

@ -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
}

Loading…
Cancel
Save