Skip to content

Commit 2de7025

Browse files
dancinlifedancinlifeclaude
authored
feat(lsp): n6 BOM diagnostic + parity test fixtures (#5)
Close the PoC fidelity gap: validate_n6 now emits "byte-canonical: UTF-8 with no BOM" via byte_at (ef bb bf), avoiding the encoding-fragile U+FEFF source literal. Verified end-to-end (LSP didOpen of a BOM doc → publishDiagnostics carries the BOM diag). Adds lsp/test_fixtures/ (9 cases: BOM/CRLF/indent-header/ unknown-type/malformed/continuation-indent/unrecognised/comments/valid) as a .py-parity regression reference (run: python3 lsp/n6_lsp.py --check <fixture>). Co-authored-by: dancinlife <dancinlab@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 030d5a1 commit 2de7025

10 files changed

Lines changed: 22 additions & 1 deletion

File tree

lsp/n6_lsp.hexa

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ fn first_token(t: string) -> string {
180180
// any generic stdlib validator (commons g61 advisory).
181181
fn validate_n6(text: string) -> string {
182182
let mut diags = []
183-
// BOM check skipped (encoding-fragile in hexa) — see PR body fidelity gap.
183+
// BOM: UTF-8 byte-order-mark ef bb bf at offset 0. byte_at avoids the
184+
// encoding-fragile U+FEFF source literal — mirrors .py text.startswith(BOM).
185+
if len(text) >= 3 && byte_at(text, 0) == 239 && byte_at(text, 1) == 187 && byte_at(text, 2) == 191 {
186+
diags.push(diag(0, 0, 1, "byte-canonical: UTF-8 with no BOM", 1))
187+
}
184188
if text.contains("\r") {
185189
diags.push(diag(0, 0, 1, "byte-canonical: LF line endings only", 1))
186190
}

lsp/test_fixtures/f1_valid.n6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@P c_light = 299792458 :: physics [tier=0 active]
2+
-> derived
3+
"speed of light"
4+
unit = m_per_s
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@Z foo :: dom [g]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@P foo :: dom [g]

lsp/test_fixtures/f4_malformed.n6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@P justtext no header
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@P x :: d [g]
2+
-> toomuch

lsp/test_fixtures/f6_cont_unrec.n6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@P x :: d [g]
2+
blah blah no edge

lsp/test_fixtures/f7_comments.n6

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# a comment
2+
3+
# another

lsp/test_fixtures/f8_crlf.n6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@P x :: d [g]
2+
-> y

lsp/test_fixtures/f9_bom.n6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@P x :: d [g]

0 commit comments

Comments
 (0)