|
| 1 | +# 01 — TS ISC Parser (Peggy grammar) |
| 2 | + |
| 3 | +## Priority: P0 — blocks all website restructure work |
| 4 | + |
| 5 | +## Problem |
| 6 | +The TS runtime currently consumes compiled JSON IR (`.json` files generated |
| 7 | +by Ruby). To eliminate JSON IR, the TS runtime needs its own ISC parser. |
| 8 | + |
| 9 | +## Design |
| 10 | + |
| 11 | +Port the Ruby Parslet grammar to Peggy (PEG parser generator for JS/TS). |
| 12 | +The grammar rules map 1:1: |
| 13 | + |
| 14 | +| Parslet (Ruby) | Peggy (JS) | |
| 15 | +|----------------|------------| |
| 16 | +| `str("system")` | `"system"` | |
| 17 | +| `whitespace` | `\\s+` | |
| 18 | +| `quoted_string` | `'"' ('\\\\' ./ | !'"' .)* '"'` | |
| 19 | +| `braced(inner)` | `'{' \\s* inner \\s* '}'` | |
| 20 | +| `rule(:name) do ... end` | `name = ...` | |
| 21 | + |
| 22 | +### Structure |
| 23 | +``` |
| 24 | +interscript-ts/ |
| 25 | + src/ |
| 26 | + isc/ |
| 27 | + grammar.peggy # Peggy grammar (source of truth for TS) |
| 28 | + parser.ts # Wrapper: parse(src) → document hash |
| 29 | + document-builder.ts # Hash → typed CompiledMap |
| 30 | + types.ts # IscDocument, IscStage, IscRule, IscItem types |
| 31 | + test/ |
| 32 | + isc/ |
| 33 | + parser.test.ts # Unit tests |
| 34 | + parity.test.ts # Cross-validate with Ruby document hashes |
| 35 | +``` |
| 36 | + |
| 37 | +### Grammar scope (from Ruby Parslet) |
| 38 | +- System block: `system "CODE" { body }` |
| 39 | +- Metadata: `metadata { key value ... }` |
| 40 | +- Tests: `tests { "input" -> "expected" }` |
| 41 | +- Aliases: `aliases { name = item }` |
| 42 | +- Stages: `stage name { parallel { ... } sub "a" "b" ... }` |
| 43 | +- Items: quoted strings, any(), capture(), ref(), none, primitives |
| 44 | +- Constraints: before, after, not_before, not_after |
| 45 | +- Directives: run, separate, compose, downcase/upcase/title_case |
| 46 | + |
| 47 | +### API |
| 48 | +```typescript |
| 49 | +import { parseIsc } from "interscript-ts/isc" |
| 50 | + |
| 51 | +const doc = parseIsc(iscSource, "map.isc") |
| 52 | +// doc: { systemCode, metadata, tests, stages, aliases, dependencies } |
| 53 | +``` |
| 54 | + |
| 55 | +### Loader strategy |
| 56 | +```typescript |
| 57 | +import { iscStrategy } from "interscript-ts" |
| 58 | + |
| 59 | +configure({ strategies: [iscStrategy({ baseUrl: "/maps" })] }) |
| 60 | +// Fetches /maps/foo.isc, parses, feeds to runtime |
| 61 | +``` |
| 62 | + |
| 63 | +## Verification |
| 64 | +- Parse all 289 .isc files |
| 65 | +- Document hash matches Ruby document hash (cross-validate) |
| 66 | +- Transliteration output matches Ruby 100% |
0 commit comments