Parsing content as string

This commit is contained in:
Florian Schroedl
2022-06-10 19:22:15 +02:00
parent 3ed85815d6
commit d0b9c0e8b4
4 changed files with 43 additions and 11 deletions

View File

@@ -14,6 +14,20 @@ import ../utils/str
# -- Parsing Functions
func lookBack*(count: int): (Parser -> ParserResult) =
return func(parser: Parser): ParserResult =
let state = parser.state
let newIndex = state.position - 1
Parser(
state: ParserState(
stream: state.stream,
position: newIndex,
lastPosition: parser.state.position,
),
tokens: parser.tokens,
).ok()
func ch*(expectedChars: set[char]): (Parser -> ParserResult) {.inline.} =
return func(parser: Parser): ParserResult =
let state = parser.state

View File

@@ -288,7 +288,7 @@ func highlightStreamPosition(stream: string, position: int): string =
proc `$`*(x: ParserState): string =
&"""ParserState(
stream: "{x.stream}",
stream: "{x.stream.highlightStreamPosition(x.position)}",
position: {x.position},
lastPosition: {x.lastPosition},
)"""