Preprocessor: variables, defines and -E #6

Closed
opened 2026-10-14 01:26:52 -05:00 by jeff · 1 comment
Owner

Parent

Part of #1

What to build

Preprocessing becomes real: <?define?>, <?undef?>, $(var.NAME), $(env.NAME), $(sys.CURRENTDIR), $(sys.SOURCEFILEDIR), $(sys.SOURCEFILEPATH), -D NAME[=VALUE] on the command line, and <?warning?> and <?error?>. zixl -E prints the preprocessed source and stops. An undefined variable is an error naming it and where it was used.

Acceptance criteria

  • Seam 2 tests (zig build test): text in, preprocessed text or diagnostics out, for each directive and variable kind.
  • Seam 2 tests: an undefined variable, a malformed directive and <?error?> each give a diagnostic with file, line and column; <?warning?> gives a warning and continues.
  • -D on the command line overrides nothing defined later in the source, and is visible to it, as WiX documents.
  • VM or devshell test: zixl -E output matches wixl -E for a fixture using every feature above, after normalizing whitespace if the two differ only there.
## Parent Part of #1 ## What to build Preprocessing becomes real: `<?define?>`, `<?undef?>`, `$(var.NAME)`, `$(env.NAME)`, `$(sys.CURRENTDIR)`, `$(sys.SOURCEFILEDIR)`, `$(sys.SOURCEFILEPATH)`, `-D NAME[=VALUE]` on the command line, and `<?warning?>` and `<?error?>`. `zixl -E` prints the preprocessed source and stops. An undefined variable is an error naming it and where it was used. ## Acceptance criteria - [ ] Seam 2 tests (`zig build test`): text in, preprocessed text or diagnostics out, for each directive and variable kind. - [ ] Seam 2 tests: an undefined variable, a malformed directive and `<?error?>` each give a diagnostic with file, line and column; `<?warning?>` gives a warning and continues. - [ ] `-D` on the command line overrides nothing defined later in the source, and is visible to it, as WiX documents. - [ ] VM or devshell test: `zixl -E` output matches `wixl -E` for a fixture using every feature above, after normalizing whitespace if the two differ only there.
jeff self-assigned this 2026-10-14 03:26:45 -05:00
Author
Owner

Done in a660e3a; CI run 6 is green.

  • The preprocessor rewrites text and keeps a source map. It doesn't re-serialize XML. Compiling locates every diagnostic through the map, so errors keep their original line and column.
  • Seam 2: tests/preprocess.zig covers every directive and variable kind, escaping in each quoting context, $$(, command-line versus later definitions, and the diagnostics with file, line and column.
  • zixl -E vs wixl -E: tests/e2e/preprocess.sh compares the two in canonical XML (C14N 2.0).

Where zixl follows WiX's documentation over the reference implementation:

  • wixl writes $$(var.X) as $ plus the value.
  • wixl gives $(sys.SOURCEFILEDIR) as the file name.
  • wixl doesn't expand variables in a define's value.
  • In #7, zixl also accepts <?define NAME?> (which wixl rejects) and ends $(sys.CURRENTDIR) and $(sys.SOURCEFILEDIR) with a separator, both as WiX documents.
Done in a660e3a; CI run 6 is green. - **The preprocessor rewrites text and keeps a source map.** It doesn't re-serialize XML. Compiling locates every diagnostic through the map, so errors keep their original line and column. - **Seam 2:** `tests/preprocess.zig` covers every directive and variable kind, escaping in each quoting context, `$$(`, command-line versus later definitions, and the diagnostics with file, line and column. - **`zixl -E` vs `wixl -E`:** `tests/e2e/preprocess.sh` compares the two in canonical XML (C14N 2.0). Where zixl follows WiX's documentation over the reference implementation: - wixl writes `$$(var.X)` as `$` plus the value. - wixl gives `$(sys.SOURCEFILEDIR)` as the file name. - wixl doesn't expand variables in a define's value. - In #7, zixl also accepts `<?define NAME?>` (which wixl rejects) and ends `$(sys.CURRENTDIR)` and `$(sys.SOURCEFILEDIR)` with a separator, both as WiX documents.
jeff closed this issue 2026-10-14 03:54:01 -05:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
jeff/zixl#6
No description provided.