You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#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.
Background
#42 shipped
jaw exportin 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
--transpileflag (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-onlywould be the opt-out.Rough mapping (target-lang dependent):
[!] — messageprint("message")println!("message");[>] exprreturn exprreturn expr;[1] — [X] += 1X += 1X += 1;/foo [A]: an intdef 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][*] / [^]commentsOpen questions before implementation
[A]: an integer). Do we parse description text for type hints, or default to a// TODO: typeplaceholder? Latter is simpler./Add[ [X], [T] ]— isAddalways a free function, or sometimes a method? Without context, free-function is the safe default.[!] — current value: [X]— how should[X]be inlined? Python f-string (f"current value: {X}")? Concatenation? Keep simple withprint("current value:", X)?[1] — [R] << [A](append) — translate toR.append(A)(Python idiom) orR << A(literal<<operator)? Idiom is more useful but more language-knowledge baked in.;; python doesn't. Per-language config.Requires
LangSpecextension to carry codegen rules alongside the comment syntax already present.Refs
docs/glossary.md,jaw-grammar.mdjaw-cli/src/export.rs,jaw-cli/src/lang.rs