fix: correct enum value rewriting and parser quoted-string handling #16

Closed
agent-engineering wants to merge 1 commit from fix/compiler-enum-rewrite-parser-quotes into main
First-time contributor

Fixes: marcus/engineering#9

Two bugs fixed in the SpeckDL TypeScript generator:

Bug 1: Enum value rewriting uses wrong enum name

rewriteExpr and replaceStateWithEnum took a single stateEnumName parameter and replaced ALL capitalized words with it. ArtifactKind.Provenance became CompilerPhase.Provenance.

Fix: Build a value → enumName map from enumMap and pass it to rewriteExpr. Each enum value now gets its correct prefix.

Bug 2: Parser splits emit fields on commas inside quoted strings

fieldsStr.split(",") broke join(outputDir, ".prov.jsonld") into two fields.

Fix: Parse-aware splitting that respects quotes and parentheses.

Bonus: join() now generates path.join()

join(a, b) was rewritten as a.join(b) (Array.join). Now correctly generates path.join(a, b) with proper import.

Verification

  • speckl-compile.speckdl compiles cleanly
  • All enum values correctly prefixed (e.g., SpecklCompilerArtifactKind.Provenance)
  • Guard expressions use SpecklCompilerCompilerPhase.* for states
  • Emit fields use SpecklCompilerArtifactKind.* for artifact kinds
  • path.join(this.outputDir, ".prov.jsonld") instead of broken this.outputDir.join(".prov.jsonld")
  • Both example specs compile successfully
## Fixes: marcus/engineering#9 Two bugs fixed in the SpeckDL TypeScript generator: ### Bug 1: Enum value rewriting uses wrong enum name `rewriteExpr` and `replaceStateWithEnum` took a single `stateEnumName` parameter and replaced ALL capitalized words with it. `ArtifactKind.Provenance` became `CompilerPhase.Provenance`. **Fix:** Build a `value → enumName` map from `enumMap` and pass it to `rewriteExpr`. Each enum value now gets its correct prefix. ### Bug 2: Parser splits emit fields on commas inside quoted strings `fieldsStr.split(",")` broke `join(outputDir, ".prov.jsonld")` into two fields. **Fix:** Parse-aware splitting that respects quotes and parentheses. ### Bonus: `join()` now generates `path.join()` `join(a, b)` was rewritten as `a.join(b)` (Array.join). Now correctly generates `path.join(a, b)` with proper import. ### Verification - `speckl-compile.speckdl` compiles cleanly - All enum values correctly prefixed (e.g., `SpecklCompilerArtifactKind.Provenance`) - Guard expressions use `SpecklCompilerCompilerPhase.*` for states - Emit fields use `SpecklCompilerArtifactKind.*` for artifact kinds - `path.join(this.outputDir, ".prov.jsonld")` instead of broken `this.outputDir.join(".prov.jsonld")` - Both example specs compile successfully
Owner

3 bugs fixed: (1) join() -> path.join(), (2) emit field parser now parse-aware (respects quotes/parens), (3) enum rewriting uses value->enumName map from enumMap.

3 bugs fixed: (1) join() -> path.join(), (2) emit field parser now parse-aware (respects quotes/parens), (3) enum rewriting uses value->enumName map from enumMap.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sscoble/speckl#16
No description provided.