Nimony

The road to Nim 3

lexbase

nimony/lib/std/lexbase.nim

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.

The design keeps a '\0' sentinel at buf[sentinel], so the scanning hot loop can read buf[pos] without a bounds check and only has to test for the sentinel; refills happen lazily when a line ending is reached. That makes it a good streaming lexer base for memory-constrained / embedded use: the buffer stays a fixed size (it only grows for pathologically long lines) instead of slurping the whole input.

This is a port of Nim's std/lexbase to Nimony. The JS/VM-only refill branches are dropped (Nimony has a single native target).