Browse Source

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

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/7/head
Alejandro Mery 1 year ago
parent
commit
30a86e170b
  1. 2
      go.mod
  2. 4
      go.sum
  3. 11
      parser/text.go

2
go.mod

@ -3,7 +3,7 @@ module asciigoat.org/ini
go 1.19 go 1.19
require ( require (
asciigoat.org/core v0.3.7 asciigoat.org/core v0.3.9
github.com/mgechev/revive v1.3.3 github.com/mgechev/revive v1.3.3
golang.org/x/tools v0.12.0 golang.org/x/tools v0.12.0
) )

4
go.sum

@ -1,5 +1,5 @@
asciigoat.org/core v0.3.7 h1:tMasdvZgsMJJMVsZVfXXB5lqq82pFiCsyEmOEmcmAfI= asciigoat.org/core v0.3.9 h1:hgDDz4ecm3ZvehX++m8A/IzAt+B5oDPiRtxatzfUHPQ=
asciigoat.org/core v0.3.7/go.mod h1:tXj+JUutxRbcO40ZQRuUVaZ4rnYz1kAZ0nblisV8u74= asciigoat.org/core v0.3.9/go.mod h1:CAaHwyw8MpAq4a1MYtN2dxJrsK+hmIdW50OndaQZYPI=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc= github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc=

11
parser/text.go

@ -39,9 +39,10 @@ func (p *TextParser) InitString(s string) {
// Discard shadows [lexer.Reader]'s, and takes in consideration // Discard shadows [lexer.Reader]'s, and takes in consideration
// new lines on the discarded data when moving the position // new lines on the discarded data when moving the position
func (*TextParser) Discard() { func (p *TextParser) Discard() {
// TODO: consider new lines s := p.Reader.Emit()
panic("not implemented") l := GetPositionalLength(s)
p.pos.Add(l)
} }
// Emit returns the accepted text, its position, and // Emit returns the accepted text, its position, and
@ -49,8 +50,8 @@ func (*TextParser) Discard() {
func (p *TextParser) Emit() (lexer.Position, string) { func (p *TextParser) Emit() (lexer.Position, string) {
pos := p.pos pos := p.pos
s := p.Reader.Emit() s := p.Reader.Emit()
// TODO: consider new lines l := GetPositionalLength(s)
p.pos.StepN(len(s)) p.pos.Add(l)
return pos, s return pos, s
} }

Loading…
Cancel
Save