2222open MoreLabels
2323include Mustache_types
2424
25+ let dummy_loc = {
26+ loc_start = Lexing. dummy_pos;
27+ loc_end = Lexing. dummy_pos;
28+ }
29+
2530module List = ListLabels
2631module String = StringLabels
2732
2833module Infix = struct
29- let (^) y x = Concat [x; y]
34+ let (^) y x = Concat (dummy_loc, [x; y])
3035end
3136
3237module Json = struct
@@ -62,30 +67,30 @@ let escape_html s =
6267
6368let rec pp fmt = function
6469
65- | String s ->
70+ | String ( _ , s ) ->
6671 Format. pp_print_string fmt s
6772
68- | Escaped s ->
73+ | Escaped ( _ , s ) ->
6974 Format. fprintf fmt " {{ %s }}" s
7075
71- | Unescaped s ->
76+ | Unescaped ( _ , s ) ->
7277 Format. fprintf fmt " {{& %s }}" s
7378
74- | Inverted_section s ->
79+ | Inverted_section ( _ , s ) ->
7580 Format. fprintf fmt " {{^%s}}%a{{/%s}}"
7681 s.name pp s.contents s.name
7782
78- | Section s ->
83+ | Section ( _ , s ) ->
7984 Format. fprintf fmt " {{#%s}}%a{{/%s}}"
8085 s.name pp s.contents s.name
8186
82- | Partial s ->
87+ | Partial ( _ , s ) ->
8388 Format. fprintf fmt " {{> %s }}" s
8489
85- | Comment s ->
90+ | Comment ( _ , s ) ->
8691 Format. fprintf fmt " {{! %s }}" s
8792
88- | Concat s ->
93+ | Concat ( _ , s ) ->
8994 List. iter (pp fmt) s
9095
9196let to_formatter = pp
@@ -100,26 +105,26 @@ let to_string x =
100105let rec fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat t =
101106 let go = fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat in
102107 match t with
103- | String s -> string s
104- | Escaped s -> escaped s
105- | Unescaped s -> unescaped s
106- | Comment s -> comment s
107- | Section { name; contents } ->
108+ | String ( _ , s ) -> string s
109+ | Escaped ( _ , s ) -> escaped s
110+ | Unescaped ( _ , s ) -> unescaped s
111+ | Comment ( _ , s ) -> comment s
112+ | Section ( _ , { name; contents } ) ->
108113 section ~inverted: false name (go contents)
109- | Inverted_section { name; contents } ->
114+ | Inverted_section ( _ , { name; contents } ) ->
110115 section ~inverted: true name (go contents)
111- | Concat ms ->
116+ | Concat ( _ , ms ) ->
112117 concat (List. map ms ~f: go)
113- | Partial p -> partial p
118+ | Partial ( _ , p ) -> partial p
114119
115- let raw s = String s
116- let escaped s = Escaped s
117- let unescaped s = Unescaped s
118- let section n c = Section { name = n ; contents = c }
119- let inverted_section n c = Inverted_section { name = n ; contents = c }
120- let partial s = Partial s
121- let concat t = Concat t
122- let comment s = Comment s
120+ let raw s = String (dummy_loc, s)
121+ let escaped s = Escaped (dummy_loc, s)
122+ let unescaped s = Unescaped (dummy_loc, s)
123+ let section n c = Section (dummy_loc, { name = n ; contents = c })
124+ let inverted_section n c = Inverted_section (dummy_loc, { name = n ; contents = c })
125+ let partial s = Partial (dummy_loc, s)
126+ let concat t = Concat (dummy_loc, t)
127+ let comment s = Comment (dummy_loc, s)
123128
124129let rec expand_partials =
125130 let section ~inverted =
@@ -176,37 +181,37 @@ let render_fmt ?(strict=true) (fmt : Format.formatter) (m : t) (js : Json.t) =
176181
177182 let rec render ' m (js : Json.value ) = match m with
178183
179- | String s ->
184+ | String ( _ , s ) ->
180185 Format. pp_print_string fmt s
181186
182- | Escaped "." ->
187+ | Escaped ( _ , "." ) ->
183188 Format. pp_print_string fmt (escape_html (Lookup. scalar js))
184- | Escaped key ->
189+ | Escaped ( _ , key ) ->
185190 Format. pp_print_string fmt (escape_html (Lookup. str ~strict ~key js))
186191
187- | Unescaped "." ->
192+ | Unescaped ( _ , "." ) ->
188193 Format. pp_print_string fmt (Lookup. scalar js)
189- | Unescaped key ->
194+ | Unescaped ( _ , key ) ->
190195 Format. pp_print_string fmt (Lookup. str ~strict ~key js)
191196
192- | Inverted_section s ->
197+ | Inverted_section ( loc , s ) ->
193198 if Lookup. inverted js s.name
194- then render' (Section s ) js
199+ then render' (Section (loc, s) ) js
195200
196- | Section s ->
201+ | Section ( _ , s ) ->
197202 begin match Lookup. section ~strict js ~key: s.name with
198203 | `Bool false -> ()
199204 | `Bool true -> render' s.contents js
200205 | `A contexts -> List. iter (render' s.contents) contexts
201206 | context -> render' s.contents context
202207 end
203208
204- | Partial _ ->
209+ | Partial ( _ , _ ) ->
205210 pp fmt m
206211
207- | Comment c -> ()
212+ | Comment ( _ , c ) -> ()
208213
209- | Concat templates ->
214+ | Concat ( _ , templates ) ->
210215 List. iter (fun x -> render' x js) templates
211216
212217 in render' m (Json. value js)
0 commit comments