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
emit-portable: typescript.ts emits too — both real grammars in the gate (issue #6)
The second real full language now goes through the agnostic emitter end-to-end. Two
type-grammar constructs were the wall:
- A LED with a leading `sameLine` guard (`$ sameLine '<' …`) — TS's generic-args /
array / non-null type tails that must not cross a newline. The guard is hoisted into
the led-arm condition (skip, don't break, so the connector can rebind).
- `notLeftLeaf`: a led skipped when the LEFT node's head-leaf text is in a word set
(`void`/`null`/`this` can't be `.`-qualified as a type). Each target gains a
`headLeafText` (the leftmost leaf's source text) and the led arm checks it.
typescript.ts (the most complex grammar) emits, compiles and runs in ts/go/rust, and
is gate-maintained alongside javascript.ts (13/13 accept, 4/4 reject ×3, ASCII corpus;
83.5% on the broad curated TS corpus in TS). Full suite 42/42. The agnostic emitter now
covers both full real languages — the issue-#6 goal, proven in three target languages.
let offset = if !kids.is_empty() { kids[0].offset } else if save < self.toks.len() { self.toks[save].off } else { 0 };
360
366
let end = if !kids.is_empty() { kids[kids.len() - 1].end } else { offset };
@@ -409,15 +415,15 @@ fn main() {
409
415
// Self-bench: a numeric arg N times the lex+parse loop and prints ms/iteration.
410
416
if let Some(iters) = std::env::args().nth(1).and_then(|a| a.parse::<u64>().ok()) {
411
417
// black_box on the input + result so the optimizer can't elide the lex/parse.
412
-
for _ in 0..3 { let toks = lex(std::hint::black_box(&src)); let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new() }; std::hint::black_box(p.parse_${ir.entry}()); }
418
+
for _ in 0..3 { let toks = lex(std::hint::black_box(&src)); let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new(), src: &src }; std::hint::black_box(p.parse_${ir.entry}()); }
413
419
let t = std::time::Instant::now();
414
-
for _ in 0..iters { let toks = lex(std::hint::black_box(&src)); let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new() }; std::hint::black_box(p.parse_${ir.entry}()); }
420
+
for _ in 0..iters { let toks = lex(std::hint::black_box(&src)); let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new(), src: &src }; std::hint::black_box(p.parse_${ir.entry}()); }
415
421
println!("{:.4}", t.elapsed().as_secs_f64() * 1000.0 / iters as f64);
416
422
return;
417
423
}
418
424
let toks = lex(&src);
419
425
let n = toks.len();
420
-
let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new() };
426
+
let mut p = Parser { toks, pos: 0, capped: false, suppress_next: Vec::new(), src: &src };
421
427
match p.parse_${ir.entry}() {
422
428
Some(root) if p.pos == n => { let mut out = String::new(); write_json(&root, &mut out); print!("{}", out); }
0 commit comments