Commit 4c2256b
Phase H.3: parse-level recovery — token-stream healing
examples/self_healing_h3.omc — the healer gains a stage BELOW the parser.
H.1/H.2 worked on the AST. But an AST presumes a successful parse,
and a parse presumes a syntactically valid token stream. H.3 adds
the missing layer: TOKEN-LEVEL repair that runs BEFORE the parser
sees anything. Three repair classes at this layer:
- Unbalanced LBRACE/RBRACE — count opens vs closes; append missing
RBRACE tokens before EOF until balanced.
- Unbalanced LPAREN/RPAREN — same shape.
- Missing SEMI — scan adjacent token pairs. When a clear expression
terminator (NUMBER, STRING, RPAREN, RBRACKET) is followed by a
clear statement starter (H, FN, IF, WHILE, RETURN, BREAK, PRINT)
or EOF, insert SEMI between them.
The pipeline is now two-stage:
source → tokenize_b → token_heal (H.3) → tokens'
↓
p_program
↓
AST
↓
heal_until_fixpoint (H.1/H.2)
↓
healed AST
↓
emit_source
Token-level repair and AST-level healing are different STAGES, not
different DIAGNOSTIC CLASSES. The parser falls off a cliff on
unbalanced braces; nothing downstream of a broken parse produces a
meaningful AST. Token-level repair has to run FIRST.
Four demos:
Demo 1: 3 missing SEMIs. Output: 8 + 13 = 21 (Fibonacci).
Demo 2: missing RBRACE. Output: double(13) = 26.
Demo 3: missing RPAREN. Output: id(21) = 21 (Fibonacci).
Demo 4: 5 bugs (2 token + 3 AST). Output: safe(8) → 8 (Fibonacci).
Demo 4 is the headline: missing SEMI + missing RBRACE + safef→safe
+ 7→8 + (n/0)→safe_divide(n,0). Three of the five would have
produced compile errors in any conventional compiler; the other two
would have produced runtime crashes. The OMC pipeline turns ALL
FIVE into a working program landing on attractor.
Known limit: naive brace placement (append-at-EOF) can fold mid-
source statements into a function body if the missing brace is
conceptually inside the source. Demos structured so missing
braces are genuinely at EOF avoid this; smarter placement using
indentation analysis logged for H.3.1.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 1fc031a commit 4c2256b
2 files changed
Lines changed: 2183 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
7 | 70 | | |
8 | 71 | | |
9 | 72 | | |
| |||
0 commit comments