Parsing content as string
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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},
|
||||
)"""
|
||||
|
||||
Reference in New Issue
Block a user