Skip to content

Commit d805b06

Browse files
committed
fix(faces/pseudo): preserve indentation in transform_set
`transform_set` was calling `String.trim line` immediately, discarding any leading whitespace. Statements like ` set x to expr` inside a function body would lower to `let x = expr` at column 0, producing a snapshot mismatch with the 4-space-indented expected output. Fix: capture the leading indent before trimming and prepend it to the generated `let`/`let mut` expression. https://claude.ai/code/session_01Vrh2f1G8tf7ZbNcKh9r5U9
1 parent 264e378 commit d805b06

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/pseudocode_face.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,17 @@ let transform_function_decl trimmed =
161161

162162
(** [set x to expr] → [let x = expr] *)
163163
let transform_set line =
164-
let line = String.trim line in
165-
if starts_with line "set " then begin
166-
let rest = String.sub line 4 (String.length line - 4) in
164+
let trimmed = String.trim line in
165+
let indent_len = String.length line - String.length trimmed in
166+
let indent = String.sub line 0 indent_len in
167+
if starts_with trimmed "set " then begin
168+
let rest = String.sub trimmed 4 (String.length trimmed - 4) in
167169
(* Look for " to " *)
168170
match String.split_on_char ' ' rest with
169171
| name :: "to" :: "mut" :: value_parts ->
170-
Printf.sprintf "let mut %s = %s" name (String.concat " " value_parts)
172+
indent ^ Printf.sprintf "let mut %s = %s" name (String.concat " " value_parts)
171173
| name :: "to" :: value_parts ->
172-
Printf.sprintf "let %s = %s" name (String.concat " " value_parts)
174+
indent ^ Printf.sprintf "let %s = %s" name (String.concat " " value_parts)
173175
| _ -> line
174176
end else line
175177

0 commit comments

Comments
 (0)