@@ -111,11 +111,40 @@ let parse ~filename =
111
111
in
112
112
(structure, print)
113
113
114
+ let diff ~filename ~newContents =
115
+ match Files. readFile ~filename with
116
+ | None -> assert false
117
+ | Some oldContents ->
118
+ let rec findFirstLineDifferent n old new_ =
119
+ match (old, new_) with
120
+ | old1 :: oldRest , new1 :: newRest ->
121
+ if old1 = new1 then findFirstLineDifferent (n + 1 ) oldRest newRest
122
+ else (n, old, new_)
123
+ | _ -> (n, old, new_)
124
+ in
125
+ let oldLines = String. split_on_char '\n' oldContents in
126
+ let newLines = String. split_on_char '\n' newContents in
127
+ let firstLineDifferent, old, new_ =
128
+ findFirstLineDifferent 0 oldLines newLines
129
+ in
130
+ let firstLineR, _oldR, newR =
131
+ findFirstLineDifferent 0 (List. rev old) (List. rev new_)
132
+ in
133
+ let lastLineEqual = firstLineDifferent + List. length old - firstLineR in
134
+ let newLines = List. rev newR in
135
+ (firstLineDifferent, lastLineEqual, newLines)
136
+
114
137
let command ~path ~pos =
115
138
if Filename. check_suffix path " .res" then
116
139
let structure, print = parse ~filename: path in
117
140
match IfThenElse. xform ~pos structure with
118
141
| None -> ()
119
142
| Some newStructure ->
120
143
let formatted = print newStructure in
121
- Printf. printf " Hit IfThenElse. Formatted:\n %s" formatted
144
+ let firstLineDifferent, lastLineEqual, newLines =
145
+ diff ~filename: path ~new Contents:formatted
146
+ in
147
+ Printf. printf
148
+ " Hit IfThenElse firstLineDifferent:%d lastLineEqual:%d newLines:\n %s\n "
149
+ firstLineDifferent lastLineEqual
150
+ (newLines |> String. concat " \n " )
0 commit comments