Skip to content

feat: Phase 3 — code-generation engine + AUX_VARS_R_VEC pre-work - #5

Merged
bakodramane merged 1 commit into
mainfrom
phase/3-codegen
Jun 3, 2026
Merged

bakodramane merged 1 commit into
mainfrom
phase/3-codegen

Conversation

@bakodramane

Copy link
Copy Markdown
Owner

Pre-work (before generateCode):

  • docs/SAE-CATALOGUE.md §1: add {{AUX_VARS_R_VEC}} token (quoted R character-vector form, for column-selection contexts)
  • src/catalogue/bhf-eblup.ts, reblup.ts, hb-unit.ts: rename non-standard {{AUX_VARS_R_QUOTED}} to {{AUX_VARS_R_VEC}} in all c(...) index positions

Code-generation engine (src/engine/codegen.ts):

  • UserInputs and GeneratedCode interfaces per PHASES.md §3a
  • buildTokenMap(): maps all {{TOKEN}} names to user-supplied values; defaults survey.csv / census.csv / 200 sims / bootstrap MSE
  • substituteTokens(): global regex replace, no unreplaced tokens escape
  • Stata v14 fallback: stataVersion < stataMinVersion and fallback non-null → use stataV14Fallback template, set usedFallback:true + fallbackNote
  • R and Stata footers appended: MSE/RMSE interpretation + next-steps note

Snapshot tests (src/engine/codegen.test.ts, 50 assertions):

  • fh-eblup: library(sae), fhsae command, all vars, no {{ tokens
  • bhf-eblup: library(sae), mixed command, all vars, AUX_VARS_R_VEC quoted form
  • ebp-censuseb (stataVersion:14): usedFallback true, Stata uses mixed
  • glmm-binary: library(lme4), meglm command, bernoulli logit family
  • Fallback boundary: v16<17 triggers fallback; v17>=17 uses full template
  • Token edge cases: single var, three vars, custom N_SIM, purity check

All 430 tests pass (380 pre-existing + 50 new).

Pre-work (before generateCode):
- docs/SAE-CATALOGUE.md §1: add {{AUX_VARS_R_VEC}} token (quoted R
  character-vector form, for column-selection contexts)
- src/catalogue/bhf-eblup.ts, reblup.ts, hb-unit.ts: rename non-standard
  {{AUX_VARS_R_QUOTED}} to {{AUX_VARS_R_VEC}} in all c(...) index positions

Code-generation engine (src/engine/codegen.ts):
- UserInputs and GeneratedCode interfaces per PHASES.md §3a
- buildTokenMap(): maps all {{TOKEN}} names to user-supplied values;
  defaults survey.csv / census.csv / 200 sims / bootstrap MSE
- substituteTokens(): global regex replace, no unreplaced tokens escape
- Stata v14 fallback: stataVersion < stataMinVersion and fallback non-null
  → use stataV14Fallback template, set usedFallback:true + fallbackNote
- R and Stata footers appended: MSE/RMSE interpretation + next-steps note

Snapshot tests (src/engine/codegen.test.ts, 50 assertions):
- fh-eblup: library(sae), fhsae command, all vars, no {{ tokens
- bhf-eblup: library(sae), mixed command, all vars, AUX_VARS_R_VEC quoted form
- ebp-censuseb (stataVersion:14): usedFallback true, Stata uses mixed
- glmm-binary: library(lme4), meglm command, bernoulli logit family
- Fallback boundary: v16<17 triggers fallback; v17>=17 uses full template
- Token edge cases: single var, three vars, custom N_SIM, purity check

All 430 tests pass (380 pre-existing + 50 new).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bakodramane
bakodramane merged commit 418f161 into main Jun 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant