Alejandro Mery
1 year ago
2 changed files with 43 additions and 0 deletions
@ -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 |
||||
} |
Loading…
Reference in new issue