Nimony

The road to Nim 3

parserrt

nimony/src/nifler2/parserrt.nim

The runtime the generated parsers are written against.

Two halves, and the generator knows nothing about either beyond the names:

  • The token stream. nimlexer produces it; everything the grammar's

semantic predicates ask about a token (noSpaceBefore, isUnary, dotLikeOps, ...) is answered here, from p.tok. The indentation class is the second half of the LL(1) decision domain, so indClass, checkInd, pushInd and popInd are as much a part of the interface as expect is.

  • The output buffer. A nifcore.TokenBuf, built out of order: a

mark records a position, and wrap retroactively inserts the opening tag there. That is what lets the generator left-factor freely and still build the tree the unfactored grammar describes -- and it is why the output cannot be a streaming nifbuilder.

wrap is the whole trick, so it is worth saying how it avoids duplicating nifcore's jump arithmetic: a wrapped node always ends at the current end of the buffer (marks nest, they never interleave), so after splicing the head token in at the mark, reopenLastTree + addParRi is exactly the situation nifcore's own closeTag is written for -- including the ExtendedSuffix it splices in when a body overflows the 19-bit jump field.