This module implements a base object of a lexer with efficient buffer handling. Only at line endings checks are necessary if the buffer needs refilling.
BaseLexer = object of RootObj bufpos*: int ## the current position within the buffer when defined(js): buf*: string else: buf*: cstring bufLen*: int ## length of buffer in characters input: Stream ## the input stream lineNumber*: int ## the current line number sentinel: int lineStart: int refillChars: set[char]
EndOfFile = '\0'
NewLines = {'\x0D', '\x0A'}
proc close(L: var BaseLexer) {.raises: [Exception], tags: [].}
proc handleCR(L: var BaseLexer; pos: int): int {.raises: [Exception], tags: [ReadIOEffect].}
proc handleLF(L: var BaseLexer; pos: int): int {.raises: [Exception], tags: [ReadIOEffect].}
proc handleRefillChar(L: var BaseLexer; pos: int): int {.raises: [Exception], tags: [ReadIOEffect].}
proc open(L: var BaseLexer; input: Stream; bufLen: int = 8192; refillChars: set[char] = NewLines) {.raises: [Exception], tags: [ReadIOEffect].}
proc getColNumber(L: BaseLexer; pos: int): int {.raises: [], tags: [].}
proc getCurrentLine(L: BaseLexer; marker: bool = true): string {.raises: [], tags: [].}
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/lexbase.html