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
buf*: string ## the buffer itself
## the input stream
lineNumber*: int ## the current line number
offsetBase*: int
the base lexer. Inherit your lexer from this object. SourceEdit
proc handleCR(L: var BaseLexer; pos: int): int {....raises: [IOError, OSError],
tags: [ReadIOEffect], forbids: [].}
Call this if you scanned over '\c' in the buffer; it returns the position to continue the scanning from. pos must be the position of the '\c'. SourceEdit
proc handleLF(L: var BaseLexer; pos: int): int {....raises: [IOError, OSError],
tags: [ReadIOEffect], forbids: [].}
Call this if you scanned over '\L' in the buffer; it returns the position to continue the scanning from. pos must be the position of the '\L'. SourceEdit
proc handleRefillChar(L: var BaseLexer; pos: int): int {.
...raises: [IOError, OSError], tags: [ReadIOEffect], forbids: [].}
Call this if a terminator character other than a new line is scanned at pos; it returns the position to continue the scanning from. SourceEdit