|
| 1 | +/** |
| 2 | + * tree-sitter grammar for .n6 (knowledge-atlas grammar, v1). |
| 3 | + * |
| 4 | + * Total line model, no external scanner, no regex look-around. Every |
| 5 | + * line token requires a trailing newline → the top-level repeat always |
| 6 | + * progresses (no parser hang). .n6 files are LF-terminated by spec. |
| 7 | + * Exposes `type` + `edge_op` for queries/highlights.scm; quoted prose, |
| 8 | + * `key = expr` continuations and CJK fall through to `body` / `text`. |
| 9 | + */ |
| 10 | +module.exports = grammar({ |
| 11 | + name: 'n6', |
| 12 | + |
| 13 | + extras: $ => [], |
| 14 | + |
| 15 | + rules: { |
| 16 | + source_file: $ => repeat($._line), |
| 17 | + |
| 18 | + _line: $ => choice( |
| 19 | + $.blank, |
| 20 | + $.comment, |
| 21 | + $.header, |
| 22 | + $.edge, |
| 23 | + $.body, |
| 24 | + $.text, |
| 25 | + ), |
| 26 | + |
| 27 | + blank: $ => token(prec(1, /[ \t]*\n/)), |
| 28 | + |
| 29 | + comment: $ => token(prec(5, /[ \t]*#[^\n]*\n/)), |
| 30 | + |
| 31 | + header: $ => seq($.type, $._rest), |
| 32 | + |
| 33 | + type: $ => token(prec(4, /@[A-Z?]/)), |
| 34 | + |
| 35 | + edge: $ => seq($._indent, $.edge_op, $._rest), |
| 36 | + |
| 37 | + body: $ => seq($._indent, $._rest), |
| 38 | + |
| 39 | + _indent: $ => token(prec(3, /[ \t]+/)), |
| 40 | + |
| 41 | + // .n6 v1 edge alphabet (7): depends/derives/application/equivalent/ |
| 42 | + // converges/verified/breakthrough |
| 43 | + edge_op: $ => token(prec(4, choice( |
| 44 | + '<-', '->', '=>', '==', '~>', '|>', '!!', |
| 45 | + ))), |
| 46 | + |
| 47 | + _rest: $ => token(prec(1, /[^\n]*\n/)), |
| 48 | + |
| 49 | + text: $ => token(prec(0, /[^ \t#@\n][^\n]*\n/)), |
| 50 | + }, |
| 51 | +}); |
0 commit comments