Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5227a467a5 | |||
| 6a66f589c6 | |||
| d18b4f0be8 | |||
| 23a6bd090c | |||
| f8fa9d678a | |||
| 7e2797607d |
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"asciigoat",
|
||||
"Subname",
|
||||
"unescapes"
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,7 @@ replace (
|
||||
)
|
||||
|
||||
require (
|
||||
asciigoat.org/core v0.3.9
|
||||
asciigoat.org/core v0.3.7
|
||||
github.com/mgechev/revive v1.3.3
|
||||
golang.org/x/tools v0.12.0
|
||||
)
|
||||
|
||||
@@ -43,11 +43,6 @@ var (
|
||||
IsCommentStart = lexer.NewIsIn(RunesComment)
|
||||
)
|
||||
|
||||
// IsAny accepts any rune
|
||||
func IsAny(_ rune) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsSpaceNotNewLine indicates a rune is whitespace but not a new line
|
||||
func IsSpaceNotNewLine(r rune) bool {
|
||||
return IsSpace(r) && !IsNewLine(r)
|
||||
|
||||
+5
-6
@@ -39,10 +39,9 @@ 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 (p *TextParser) Discard() {
|
||||
s := p.Reader.Emit()
|
||||
l := GetPositionalLength(s)
|
||||
p.pos.Add(l)
|
||||
func (*TextParser) Discard() {
|
||||
// TODO: consider new lines
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Emit returns the accepted text, its position, and
|
||||
@@ -50,8 +49,8 @@ func (p *TextParser) Discard() {
|
||||
func (p *TextParser) Emit() (lexer.Position, string) {
|
||||
pos := p.pos
|
||||
s := p.Reader.Emit()
|
||||
l := GetPositionalLength(s)
|
||||
p.pos.Add(l)
|
||||
// TODO: consider new lines
|
||||
p.pos.StepN(len(s))
|
||||
|
||||
return pos, s
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"asciigoat.org/core/lexer"
|
||||
)
|
||||
|
||||
type positionLengthParser struct {
|
||||
TextParser
|
||||
|
||||
lexer.Position
|
||||
}
|
||||
|
||||
func (p *positionLengthParser) lexStart() (lexer.StateFn, error) {
|
||||
for {
|
||||
switch {
|
||||
case p.AcceptNewLine():
|
||||
p.Position.StepLine()
|
||||
case p.Accept(IsAny):
|
||||
p.Position.StepN(1)
|
||||
default:
|
||||
return nil, io.EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetPositionalLength calculates the [lexer.Position] at
|
||||
// the end of a text.
|
||||
func GetPositionalLength(s string) lexer.Position {
|
||||
var p positionLengthParser
|
||||
if s == "" {
|
||||
p.InitString(s)
|
||||
|
||||
_ = lexer.Run(p.lexStart)
|
||||
}
|
||||
return p.Position
|
||||
}
|
||||
Reference in New Issue
Block a user