Skip to content

Commit decd6af

Browse files
committed
Merge pull request #105 from ocsigen/4.03
Restore compatibility with 4.03
2 parents f9ab218 + 7ceddde commit decd6af

12 files changed

+55
-37
lines changed

_oasis

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ License: LGPL-2.1 with OCaml linking exception
1515
Plugins: META (0.3), DevFiles (0.3)
1616
BuildTools: ocamlbuild
1717
AlphaFeatures: pure_interface
18+
OCamlVersion: >= 4.02.0
1819

1920
Synopsis: Statically correct HTML and SVG documents
2021

@@ -182,10 +183,12 @@ Test html
182183
TestTools: main_test
183184
Run$: flag(tests) && flag(ppx)
184185

185-
Test html_fail
186-
Command: ocamlbuild test/html_fail.stamp
187-
TestTools: main_test
188-
Run$: flag(tests) && flag(ppx)
186+
## This test is disabled as it can't run on both 4.03 and 4.02
187+
## Curent oasis doesn't allow to restrict the version just for this test.
188+
# Test html_fail
189+
# Command: ocamlbuild -use-ocamlfind test/html_fail.stamp
190+
# TestTools: main_test
191+
# Run$: flag(tests) && flag(ppx)
189192

190193
## Examples
191194

myocamlbuild.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2020
* 02111-1307, USA.
2121
*)
22-
22+
[@@@ocaml.warning "-3"]
2323
(* OASIS_START *)
2424
(* OASIS_STOP *)
2525
# 26 "myocamlbuild.ml"

opam

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ depopts: [
4242
"markup"
4343
"ppx_tools"
4444
]
45+
conflicts: [
46+
"ppx_tools" { < "5.0" }
47+
]
4548
available: ocaml-version >= "4.02"
4649
messages: [
4750
"For tyxml's ppx, please install markup and ppx_tools."

ppx/ppx_attribute_value.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02111-1307, USA.
1818
*)
1919

20-
open Asttypes
2120
open Ast_helper
2221
module Pc = Ppx_common
2322

@@ -134,12 +133,12 @@ let group_matched index s =
134133

135134
let int_exp loc s =
136135
try Some (Ppx_common.int loc (int_of_string s))
137-
with Failure "int_of_string" -> None
136+
with Failure _ -> None
138137

139138
let float_exp loc s =
140139
try
141140
Some (Ppx_common.float loc @@ float_of_string s)
142-
with Failure "float_of_string" ->
141+
with Failure _ ->
143142
None
144143

145144
let bool_exp loc b =
@@ -161,18 +160,17 @@ let char ?separated_by:_ ?default:_ loc name s =
161160
let c =
162161
match next decoded with
163162
| None -> Ppx_common.error loc "No character in attribute %s" name
164-
| Some i ->
165-
try Char.chr i
166-
with Invalid_argument "Char.chr" ->
167-
Ppx_common.error loc "Character out of range in attribute %s" name
163+
| Some i when i <= 255 -> Char.chr i
164+
| Some _ ->
165+
Ppx_common.error loc "Character out of range in attribute %s" name
168166
in
169167

170168
begin match next decoded with
171169
| None -> ()
172170
| Some _ -> Ppx_common.error loc "Multiple characters in attribute %s" name
173171
end;
174172

175-
Some (Exp.constant ~loc (Const_char c))
173+
Some (with_default_loc loc @@ fun () -> Ast_convenience.char c)
176174

177175
let onoff ?separated_by:_ ?default:_ loc name s =
178176
let b = match s with
@@ -256,7 +254,7 @@ let icon_size =
256254
try
257255
int_of_string (Re_str.matched_group 1 s),
258256
int_of_string (Re_str.matched_group 2 s)
259-
with Invalid_argument "int_of_string" ->
257+
with Invalid_argument _ ->
260258
Ppx_common.error loc "Icon dimension out of range in %s" name
261259
in
262260

@@ -417,7 +415,7 @@ let transform =
417415
(* String-like. *)
418416

419417
let string ?separated_by:_ ?default:_ loc _ s =
420-
Some (Exp.constant ~loc (Const_string (s, None)))
418+
Some (with_default_loc loc @@ fun () -> Ast_convenience.str s)
421419

422420
let variand s =
423421
let without_backtick s =

ppx/ppx_attributes.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let parse loc (ns, element_name) attributes =
6565
| Some e -> e
6666
in
6767

68-
(label, e)::labeled, regular
68+
(Ppx_common.Label.labelled label, e)::labeled, regular
6969

7070
| None ->
7171
(* The attribute is not individually labeled, so it is passed in ~a.
@@ -135,5 +135,8 @@ let parse loc (ns, element_name) attributes =
135135
for a list, and prefix that with the ~a label. *)
136136
if regular = [] then List.rev labeled
137137
else
138-
let regular = "a", Ppx_common.list loc (List.rev regular) in
138+
let regular =
139+
Ppx_common.Label.labelled "a",
140+
Ppx_common.list loc (List.rev regular)
141+
in
139142
List.rev (regular::labeled)

ppx/ppx_attributes.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
val parse :
2525
Location.t -> Markup.name -> (Markup.name * string Ppx_common.value) list ->
26-
(Asttypes.label * Parsetree.expression) list
26+
(Ppx_common.Label.t * Parsetree.expression) list
2727
(** [parse loc element_name attributes] evaluates to a list of labeled parse
2828
trees, each representing an attribute argument to the element function for
2929
[element_name]. For example, if called on the HTML element

ppx/ppx_common.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ let find f l =
5757

5858
let with_loc loc f x =
5959
with_default_loc loc @@ fun () -> f x
60-
let error loc fmt = Location.raise_errorf ~loc ("Error: "^^fmt)
60+
61+
let error_prefix : _ format6 = "Error: "
62+
(* We use a custom implementation because the type of Location.raise_errorf
63+
changed in 4.03 *)
64+
let error loc ppf =
65+
let buf = Buffer.create 17 in
66+
let fmt = Format.formatter_of_buffer buf in
67+
Format.kfprintf
68+
(fun _ -> Location.raise_errorf ~loc "%s" (Buffer.contents buf))
69+
fmt
70+
(error_prefix^^ppf)
6171

6272
(** Ast manipulation *)
6373

ppx/ppx_common.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@ val list_wrap_value :
6262
lang -> Location.t -> Parsetree.expression value list -> Parsetree.expression
6363

6464

65-
val error : Location.t -> ('b, unit, string, 'a) format4 -> 'b
66-
(** Raises an error using compiler module [Location]. *)
65+
val error : Location.t -> ('b, Format.formatter, unit, 'a) format4 -> 'b

ppx/ppx_element_content.ml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ let figure ~lang ~loc ~name children =
127127
| [] -> star ~lang ~loc ~name children
128128
| first::others ->
129129
if is_element_with_name (html "figcaption") first then
130-
("figcaption",
130+
(Pc.Label.labelled "figcaption",
131131
[%expr `Top [%e Pc.wrap_value lang loc first]])::
132132
(star ~lang ~loc ~name others)
133133
else
134134
let children_reversed = List.rev children in
135135
let last = List.hd children_reversed in
136136
if is_element_with_name (html "figcaption") last then
137137
let others = List.rev (List.tl children_reversed) in
138-
("figcaption",
138+
(Pc.Label.labelled "figcaption",
139139
[%expr `Bottom [%e Pc.wrap_value lang loc last]])::
140140
(star ~lang ~loc ~name others)
141141
else
@@ -146,15 +146,17 @@ let object_ ~lang ~loc ~name children =
146146
let params, others = partition (html "param") children in
147147

148148
if params <> [] then
149-
("params", Pc.list_wrap_value lang loc params) :: star ~lang ~loc ~name others
149+
(Pc.Label.labelled "params", Pc.list_wrap_value lang loc params) ::
150+
star ~lang ~loc ~name others
150151
else
151152
star ~lang ~loc ~name others
152153

153154
let audio_video ~lang ~loc ~name children =
154155
let sources, others = partition (html "source") children in
155156

156157
if sources <> [] then
157-
("srcs", Pc.list_wrap_value lang loc sources) :: star ~lang ~loc ~name others
158+
(Pc.Label.labelled "srcs", Pc.list_wrap_value lang loc sources) ::
159+
star ~lang ~loc ~name others
158160
else
159161
star ~lang ~loc ~name others
160162

@@ -166,13 +168,13 @@ let table ~lang ~loc ~name children =
166168

167169
let one label = function
168170
| [] -> []
169-
| [child] -> [label, Pc.wrap_value lang loc child]
171+
| [child] -> [Pc.Label.labelled label, Pc.wrap_value lang loc child]
170172
| _ -> Pc.error loc "%s cannot have more than one %s" name label
171173
in
172174

173175
let columns =
174176
if columns = [] then []
175-
else ["columns", Pc.list_wrap_value lang loc columns]
177+
else [Pc.Label.labelled "columns", Pc.list_wrap_value lang loc columns]
176178
in
177179

178180
(one "caption" caption) @
@@ -187,7 +189,7 @@ let fieldset ~lang ~loc ~name children =
187189
match legend with
188190
| [] -> star ~lang ~loc ~name others
189191
| [legend] ->
190-
("legend", Pc.wrap_value lang loc legend)::
192+
(Pc.Label.labelled "legend", Pc.wrap_value lang loc legend)::
191193
(star ~lang ~loc ~name others)
192194
| _ -> Pc.error loc "%s cannot have more than one legend" name
193195

@@ -197,11 +199,11 @@ let datalist ~lang ~loc ~name children =
197199
let children =
198200
begin match others with
199201
| [] ->
200-
"children",
202+
Pc.Label.labelled "children",
201203
[%expr `Options [%e Pc.list_wrap_value lang loc options]]
202204

203205
| _ ->
204-
"children",
206+
Pc.Label.labelled "children",
205207
[%expr `Phras [%e Pc.list_wrap_value lang loc children]]
206208
end [@metaloc loc]
207209
in
@@ -219,7 +221,7 @@ let details ~lang ~loc ~name children =
219221

220222
let menu ~lang ~loc ~name children =
221223
let children =
222-
"child",
224+
Pc.Label.labelled "child",
223225
[%expr `Flows [%e Pc.list_wrap_value lang loc children]]
224226
[@metaloc loc]
225227
in

ppx/ppx_tyxml.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ let ast_to_stream expr =
246246

247247
let strings =
248248
expressions |> List.map @@ fun expr ->
249-
match expr.pexp_desc with
250-
(* TODO: Doesn't work in 4.03, can't pattern match. *)
251-
| Pexp_constant (Const_string (s, delimiter)) ->
249+
match Ast_convenience.get_str_with_quotation_delimiter expr with
250+
| Some (s, delimiter) ->
252251
(s, Loc.string_start delimiter expr.pexp_loc)
253-
| _ ->
252+
| None ->
254253
(Antiquot.create expr, expr.pexp_loc.loc_start)
255254
in
256255

0 commit comments

Comments
 (0)