Module parse

Module parse 

Source
Expand description

S-expression reader and name-resolution lowering to Exp.

Source text passes through up to three stages here:

  1. Reading (parse_one / parse_all): text to Sexp trees. Comments (; to end of line) are dropped; the quote-family reader macros (', `, ,, ,@) become quote / quasiquote / unquote list heads.
  2. Surface desugaring, applied only at source boundaries: sug rewrites the cadr family into car/cdr chains everywhere, including inside quoted data (Pink source is quoted data); expand_qq turns quasiquote in loaded files into plain cons/quote source.
  3. Lowering (lower): Sexp to Exp, resolving each name to an environment index against a compile-time name stack. Special forms are matched by head symbol and shape here; a list that matches nothing becomes a (curried) application.

Values entered at a REPL prompt follow 1–3; data read by the read primitive stops after 1 and is converted directly to a value with sexp_to_val.

Enums§

Sexp
A read s-expression — the concrete syntax tree, before lowering.

Functions§

expand_qq
Expand quasiquote in loaded .naj source into plain cons/quote source.
lower
Lower a read s-expression to an Exp, resolving names against names — the compile-time stack of binders in scope, which mirrors the runtime environment slot-for-slot. Innermost binding wins (rposition), so shadowing works; an unresolved name is an error at lowering time, not runtime.
parse_all
Parse every top-level form in src. String-error twin of repl::parse_all, callable from the evaluator (read-file) without a layering inversion.
parse_one
Read the first complete form from src, ignoring anything after it.
sexp_to_val
Convert a read s-expression directly into a runtime value — lists become Tup chains, no lowering, no name resolution. This is how the read and read-file primitives hand parsed input to the evaluator as data.
sug
pink.scm’s sug pre-pass (pink.scm:11): desugar cadr/caddr/cadddr into car/cdr chains over the whole surface tree — including quoted data, since Pink source is itself a quoted list. Oracle under Chez: (sug '(quote (cadr x))) => (quote (car (cdr x))).