Nimony

The road to Nim 3

nimlexer

nimony/src/nifler2/nimlexer.nim

Nim's lexer for nifler2, built on std/regex's lex construct.

The token type, the token kinds and their spellings are the ones compiler/lexer.nim uses, because the two are meant to be differentially tested against each other: same input, same token sequence, or a bug. src/nifler2/deps/parsegen.nim already assumes these names -- the grammar's 'if' is tkIf and its '{.' is tkCurlyDotLe.

What the generated automata do and what is hand-written:

  • lex: keywords and identifiers, every numeric literal form --

decimal, hex, octal, binary, and floats with an exponent -- and the type suffix behind a number. Numbers are where a DFA earns its keep: getNumber in Nim's lexer is a hundred lines of hand-rolled state, most of it spelling out where _ may appear.

  • hand-written: the indentation and spacing bookkeeping, comments

(including nested #[ ]#), string and character literals, and the punctuation whose meaning depends on the character after it ((. is one token, (.. is two).

Keywords are case-sensitive, like every other identifier in Nimony: proc is the keyword, pRoC and p_roc are identifiers. This is where the lexer deliberately parts ways with Nim's, whose keywords are style-insensitive.