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 offsetBase*: int refillChars: set[char]
EndOfFile = '\x00'
NewLines = {'\c', '\n'}
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–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/lexbase.html