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.
TBaseLexer* = object of TObject
bufpos*: int
buf*: cstring
bufLen*: int
input: PStream
LineNumber*: int
sentinel: int
lineStart: int
fileOpened: bool
-
the base lexer. Inherit your lexer from this object.
EndOfFile* = '\0'
-
end of file marker
NewLines* = {'\x0D', '\x0A'}
-
proc open*(L: var TBaseLexer; input: PStream; bufLen: int = 8192)
-
inits the TBaseLexer with a stream to read from
proc close*(L: var TBaseLexer)
-
closes the base lexer. This closes L's associated stream too.
proc getCurrentLine*(L: TBaseLexer; marker: bool = true): string
-
retrieves the current line.
proc getColNumber*(L: TBaseLexer; pos: int): int
-
retrieves the current column.
proc HandleCR*(L: var TBaseLexer; pos: int): int
-
Call this if you scanned over 'c' in the buffer; it returns the the position to continue the scanning from. pos must be the position of the 'c'.
proc HandleLF*(L: var TBaseLexer; pos: int): int
-
Call this if you scanned over 'L' in the buffer; it returns the the position to continue the scanning from. pos must be the position of the 'L'.