asciigoat's INI parser
https://asciigoat.org/ini
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
601 B
38 lines
601 B
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 |
|
}
|
|
|