Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbd3f705f5 | |||
| c9f206c9aa | |||
| 9912146d21 | |||
| 71ab4a58c1 | |||
| 8e838c3566 | |||
| ff0c7d1b9f | |||
| fabd192e3d | |||
| 37f3efebfb | |||
| 506fff8725 | |||
| 30a86e170b | |||
| 8cc75da138 |
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"asciigoat",
|
||||
"Subname",
|
||||
"unescapes"
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,7 @@ replace (
|
||||
)
|
||||
|
||||
require (
|
||||
asciigoat.org/core v0.3.7
|
||||
asciigoat.org/core v0.3.9
|
||||
github.com/mgechev/revive v1.3.3
|
||||
golang.org/x/tools v0.12.0
|
||||
)
|
||||
|
||||
@@ -43,6 +43,11 @@ 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)
|
||||
|
||||
+6
-5
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
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