Skip to content

jaw export --transpile: translate marker semantics to real code #52

Description

@dishmint

Background

#42 shipped jaw export in comment-only mode — every jaw line becomes a comment in the target language. That's V1; transpilation was explicitly deferred during the design discussion.

Proposal

Add a --transpile flag (initially) that instead of emitting comments translates jaw constructs into roughly-equivalent target-language code. Once stable, the behavior could become the default and --comments-only would be the opt-out.

Rough mapping (target-lang dependent):

jaw python rust
[!] — message print("message") println!("message");
[>] expr return expr return expr;
[1] — [X] += 1 X += 1 X += 1;
/foo [A]: an int def foo(A): fn foo(A: i32) {
[~] — [P] in [V] for P in V: for P in V {
[~] — [P] < [L] while P < L: while P < L {
[+] / [-] if cond: / else: if cond { / } else {
[V]@[P] V[P] V[P]
[*] / [^] comments (still comments) (still comments)

Open questions before implementation

  • Type inference: jaw is descriptive; types are usually in the description text (e.g., [A]: an integer). Do we parse description text for type hints, or default to a // TODO: type placeholder? Latter is simpler.
  • Function dispatch: /Add[ [X], [T] ] — is Add always a free function, or sometimes a method? Without context, free-function is the safe default.
  • Strings vs identifiers in logs: [!] — current value: [X] — how should [X] be inlined? Python f-string (f"current value: {X}")? Concatenation? Keep simple with print("current value:", X)?
  • Idiomatic vs literal: [1] — [R] << [A] (append) — translate to R.append(A) (Python idiom) or R << A (literal << operator)? Idiom is more useful but more language-knowledge baked in.
  • Statement terminators: rust/c need ;; python doesn't. Per-language config.

Requires

  • Real AST traversal (V1 export does line-by-line text munging; transpilation needs the parse tree to reason about expressions, control flow, args).
  • Per-language code generators with shared expression-translation logic.
  • Probably a LangSpec extension to carry codegen rules alongside the comment syntax already present.

Refs

  • Spec / glossary: docs/glossary.md, jaw-grammar.md
  • V1 implementation: jaw-cli/src/export.rs, jaw-cli/src/lang.rs
  • Original feature discussion: Export as lang #42

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions