Fix orchestration.sx parse error, add parser line/col diagnostics

The parser was reporting "Unexpected char: )" with no position info.
Added line number, column, and byte position to all parse errors.

Root cause: bind-sse-swap had one extra close paren that naive paren
counting missed because a "(" exists inside a string literal on L1074
(starts-with? trimmed "("). Parse-aware counting (skipping strings
and comments) correctly identified the imbalance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 15:29:28 +00:00
parent f0f16d24bc
commit ebbdec8f4c
4 changed files with 159 additions and 82 deletions

View File

@@ -95,7 +95,11 @@ let try_number str =
let rec read_value s : value =
skip_whitespace_and_comments s;
if at_end s then raise (Parse_error "Unexpected end of input");
if at_end s then begin
let line = ref 1 in
String.iter (fun c -> if c = '\n' then incr line) s.src;
raise (Parse_error (Printf.sprintf "Unexpected end of input at line %d (pos %d)" !line s.pos))
end;
match s.src.[s.pos] with
| '(' -> read_list s ')'
| '[' -> read_list s ']'
@@ -139,7 +143,14 @@ let rec read_value s : value =
begin
(* Symbol, keyword, number, or boolean *)
let token = read_symbol s in
if token = "" then raise (Parse_error ("Unexpected char: " ^ String.make 1 s.src.[s.pos]));
if token = "" then begin
let line = ref 1 and col = ref 1 in
for i = 0 to s.pos - 1 do
if s.src.[i] = '\n' then (incr line; col := 1) else incr col
done;
raise (Parse_error (Printf.sprintf "Unexpected char: %c at line %d col %d (pos %d)"
s.src.[s.pos] !line !col s.pos))
end;
match token with
| "true" -> Bool true
| "false" -> Bool false

View File

@@ -1084,7 +1084,7 @@
(with-transition use-transition
(fn ()
(swap-html-string target trimmed swap-style)
(post-swap target)))))))))
(post-swap target))))))))
;; --------------------------------------------------------------------------

File diff suppressed because one or more lines are too long

View File

@@ -1084,7 +1084,7 @@
(with-transition use-transition
(fn ()
(swap-html-string target trimmed swap-style)
(post-swap target)))))))))
(post-swap target))))))))
;; --------------------------------------------------------------------------