Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ppx. #89

Merged
merged 35 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2d250c6
Add ppx.
aantron Feb 26, 2016
e798a19
Typo.
Drup Mar 18, 2016
243f360
Fix merlin and improve _oasis.
Drup Mar 18, 2016
f21c1cd
Small simplification in ppx_common.
Drup Mar 18, 2016
65c4893
Remove some confusing whitespaces.
Drup Mar 18, 2016
76e74e7
Fix warnings
Drup Mar 18, 2016
28837bb
Remove the various _.
Drup Mar 18, 2016
703eb46
Use a datatype for the language (and shorten some combinators).
Drup Mar 18, 2016
e37c8d3
Remove some superfluous functions.
Drup Mar 18, 2016
1317c9e
Fix comment.
Drup Mar 18, 2016
024bd87
Various changes for 4.03
Drup Mar 18, 2016
e703ffe
Sometimes, |> is not an improvement.
Drup Mar 18, 2016
7274c09
Move list wrap to common.
Drup Mar 18, 2016
1534200
Simplify Ppx_common.make.
Drup Mar 18, 2016
4f6e005
Misc changes.
Drup Mar 18, 2016
dd6ab0a
Remove str
Drup Mar 29, 2016
76e1db8
Freshen up ppx_reflect a bit.
Drup Mar 29, 2016
e0c18e8
Rewrite IO part of ppx_reflect to behave sensibly.
Drup Mar 29, 2016
ce057f5
Compile ppx_tyxml in native if possible.
Drup Mar 29, 2016
55c3c72
Have OPAM pass the --enable-ppx flag to OASIS.
aantron Mar 29, 2016
742bf82
Depend on Markup.ml in opam file.
aantron Mar 29, 2016
3d1a4c9
Introduce value parsers and modify various types.
Drup Mar 30, 2016
7ce2be0
Implement antiquotations using placeholder elements.
Drup Mar 30, 2016
36b04fb
Add testing for the ppx.
Drup Mar 30, 2016
871f52a
Untangle things a bit more.
Drup Mar 30, 2016
8d68c53
Split Ppx_namespace and export some internal bits.
Drup Mar 31, 2016
295e01e
Add handling of comments.
Drup Mar 31, 2016
f89faf6
Make the pattern match complete.
Drup Mar 31, 2016
9dca2fa
Rewrite ppx_reflect's handling of attribute arguments.
Drup Mar 31, 2016
00bcb62
Use expressions instead of strings in ppx_reflect.
Drup Mar 31, 2016
1714b35
Allow to modify the module implementation.
Drup Mar 31, 2016
3125fe6
Allow %html5 and %svg, along with changing the base module.
Drup Mar 31, 2016
9a95ba1
Suppress warnings about topdirs.cmi.
aantron Apr 1, 2016
42f98cd
Remove a_fs_rows and a_fs_cols.
aantron Apr 1, 2016
04c40fb
Adapt ppx test to module renamings.
Drup Apr 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .merlin
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
S lib
S syntax
S tools
S ppx

B _build/*

Expand All @@ -9,3 +10,4 @@ FLG -w -32-34-37
FLG -strict_sequence -safe_string

PKG uutf re
PKG compiler-libs.common ppx_tools.metaquot markup
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
OCAMLFIND_IGNORE_DUPS_IN = $(shell ocamlfind query compiler-libs)
export OCAMLFIND_IGNORE_DUPS_IN

# OASIS_START
# DO NOT EDIT (digest: a3c674b4239234cbbe53afe090018954)

Expand Down
33 changes: 32 additions & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Flag syntax
Description: Build the camlp4 syntax extension.
Default: true

Flag ppx
Description: Build the ppx syntax extension.
Default: false

Library tyxml
FindlibName: tyxml
Path: implem
Expand Down Expand Up @@ -106,6 +110,33 @@ Library tymlx_p
Modules:
Simplexmlparser

Library ppx
Build$: flag(ppx)
FindlibName: ppx
FindlibParent: tyxml
Path: ppx
InternalModules: Ppx_tyxml
XMETADescription:
HTML5 and SVG syntax extension (ppx)
XMETARequires: tyxml
XMETAExtraLines: ppx = "ppx_tyxml"

Executable ppx_tyxml
Build$: flag(ppx)
Path: ppx
MainIs: ppx_tyxml.ml
BuildDepends:
re.str, ppx_tools.metaquot, markup, tyxml.tools
CompiledObject: best

Executable ppx_reflect
Build$: flag(ppx)
Path: ppx
MainIs: ppx_reflect.ml
BuildDepends:
compiler-libs.common, ppx_tools.metaquot
CompiledObject: best

## Tests

Executable emit_big
Expand Down Expand Up @@ -173,4 +204,4 @@ Document "tyxml-api"
BuildTools: ocamldoc
XOCamlbuildPath: ./
XOCamlbuildLibraries:
tyxml, tyxml.functor, tyxml.parser, tyxml.syntax
tyxml, tyxml.functor, tyxml.parser, tyxml.syntax, tyxml.ppx
3 changes: 3 additions & 0 deletions _tags
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ not <syntax/*>: warn_error(+1..49), warn_error(-45-3)
not <syntax/*>: strict_sequence, safe_string, short_paths

true: keep_locs

# Tests use the tyxml ppx
<test/*.ml>: ppx_tyxml
10 changes: 0 additions & 10 deletions lib/html5_f.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ struct
(* space-separated *)
let length_attrib = user_attrib C.string_of_multilength

let multilengths_attrib name x =
user_attrib C.string_of_multilengths name x

let linktypes_attrib name x =
user_attrib C.string_of_linktypes name x

Expand Down Expand Up @@ -461,10 +458,6 @@ struct

let a_codetype = string_attrib "codetype"

let a_fs_rows mls = multilengths_attrib "rows" mls

let a_fs_cols mls = multilengths_attrib "cols" mls

let a_frameborder x =
user_attrib C.string_of_big_variant "frameborder" x

Expand Down Expand Up @@ -1042,9 +1035,6 @@ struct
let string_of_numbers l =
String.concat "," (List.map string_of_number l)

let string_of_multilengths l =
String.concat ", " (List.map string_of_multilength l)

let string_of_mediadesc l =
String.concat ", " (List.map string_of_mediadesc_token l)

Expand Down
30 changes: 23 additions & 7 deletions lib/html5_sigs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,12 @@ module type T = sig
val a_max : float_number wrap -> [> | `Max] attrib

val a_input_max : float_number wrap -> [> | `Input_Max] attrib
[@@reflect.attribute "max" ["input"]]

val a_min : float_number wrap -> [> | `Min] attrib

val a_input_min : float_number wrap -> [> | `Input_Min] attrib
[@@reflect.attribute "min" ["input"]]

val a_novalidate : [> | `Novalidate] attrib

Expand Down Expand Up @@ -360,6 +362,7 @@ module type T = sig
val a_srcset : image_candidate list wrap -> [> | `Srcset] attrib

val a_img_sizes : text list wrap -> [> | `Img_sizes] attrib
[@@reflect.attribute "sizes" ["img"]]

val a_start : number wrap -> [> | `Start] attrib

Expand Down Expand Up @@ -456,6 +459,7 @@ module type T = sig
val a_for : idref wrap -> [> | `For] attrib

val a_for_list : idrefs wrap -> [> | `For_List] attrib
[@@reflect.attribute "for" ["output"]]

val a_maxlength : number wrap -> [> | `Maxlength] attrib

Expand Down Expand Up @@ -506,29 +510,36 @@ module type T = sig
| `Date
| `Color
| `Button] wrap -> [> | `Input_Type] attrib
[@@reflect.attribute "type" ["input"]]

val a_text_value : text wrap -> [> | `Text_Value] attrib
[@@reflect.attribute "value" ["param"; "button"; "option"]]
(** This attribute specifies the initial value of the
control. If this attribute is not set, the initial value is
set to the contents of the [option] element. *)

val a_int_value : number wrap -> [> | `Int_Value] attrib
[@@reflect.attribute "value" ["li"]]

(*VVV NO *)
val a_value : cdata wrap -> [> | `Value] attrib

val a_float_value : float_number wrap -> [> | `Float_Value] attrib
[@@reflect.attribute "value" ["progress"; "meter"]]

val a_disabled : [> | `Disabled] attrib

val a_readonly : [> | `ReadOnly] attrib
val a_button_type :
[< | `Button | `Submit | `Reset] wrap -> [> | `Button_Type] attrib
[@@reflect.attribute "type" ["button"]]

val a_command_type :
[< | `Command | `Checkbox | `Radio] wrap -> [> | `Command_Type] attrib
[@@reflect.attribute "type" ["command"]]

val a_menu_type : [< | `Context | `Toolbar] wrap -> [> | `Menu_Type] attrib
[@@reflect.attribute "type" ["menu"]]

val a_label : text wrap -> [> | `Label] attrib

Expand Down Expand Up @@ -581,10 +592,6 @@ module type T = sig

val a_codetype : contenttype wrap -> [> | `Codetype] attrib

val a_fs_rows : multilengths wrap -> [> | `FS_Rows] attrib

val a_fs_cols : multilengths wrap -> [> | `FS_Cols] attrib

val a_frameborder : [< | `Zero | `One] wrap -> [> | `Frameborder] attrib

val a_marginheight : pixels wrap -> [> | `Marginheight] attrib
Expand Down Expand Up @@ -614,10 +621,12 @@ module type T = sig
val html :
?a: ((html_attrib attrib) list) ->
[< | `Head] elt wrap -> [< | `Body] elt wrap -> [> | `Html] elt
[@@reflect.element "html"]

val head :
?a: ((head_attrib attrib) list) ->
[< | `Title] elt wrap -> (head_content_fun elt) list_wrap -> [> | head] elt
[@@reflect.element "head"]

val base : ([< | base_attrib], [> | base]) nullary

Expand Down Expand Up @@ -698,6 +707,7 @@ module type T = sig
val figure :
?figcaption: ([`Top of [< `Figcaption ] elt wrap | `Bottom of [< `Figcaption ] elt wrap ]) ->
([< | figure_attrib], [< | figure_content_fun], [> | figure]) star
[@@reflect.element "figure"]

val hr : ([< | hr_attrib], [> | hr]) nullary

Expand Down Expand Up @@ -783,6 +793,7 @@ module type T = sig
| `Name
| `Usemap
], 'a, [> | `Object of 'a ]) star
[@@reflect.element "object_" "object"]

val param : ([< | param_attrib], [> | param]) nullary

Expand All @@ -793,11 +804,13 @@ module type T = sig
?src:Xml.uri wrap ->
?srcs:(([< | source] elt) list_wrap) ->
([< | audio_attrib], 'a, [> 'a audio ]) star
[@@reflect.element "audio_video"]

val video :
?src:Xml.uri wrap ->
?srcs: (([< | source] elt) list_wrap) ->
([< | video_attrib], 'a, [> 'a video]) star
[@@reflect.element "audio_video"]

val canvas : ([< | canvas_attrib], 'a, [> | 'a canvas]) star

Expand Down Expand Up @@ -830,13 +843,15 @@ module type T = sig
?thead: [< | thead] elt wrap ->
?tfoot: [< | tfoot] elt wrap ->
([< | table_attrib], [< | table_content_fun], [> | table]) star
[@@reflect.element "table"]

val tablex :
?caption: [< | caption] elt wrap ->
?columns: [< | colgroup] elt list_wrap ->
?thead: [< | thead] elt wrap ->
?tfoot: [< | tfoot] elt wrap ->
([< | tablex_attrib], [< | tablex_content_fun], [> | tablex]) star
[@@reflect.element "table" "table"]

val colgroup :
([< | colgroup_attrib], [< | colgroup_content_fun], [> | colgroup]) star
Expand Down Expand Up @@ -866,6 +881,7 @@ module type T = sig
?legend: [ | `Legend ] elt wrap ->
([< | common | `Disabled | `Form | `Name], [< | flow5],
[> | `Fieldset]) star
[@@reflect.element "fieldset"]

val legend :
([< | legend_attrib], [< | legend_content_fun], [> | legend]) star
Expand All @@ -891,6 +907,7 @@ module type T = sig
| `Options of ([< | `Option] elt) list_wrap
| `Phras of ([< | phrasing] elt) list_wrap
]) -> ([< | common], [> | `Datalist]) nullary
[@@reflect.element "datalist"]

val optgroup :
label: text wrap ->
Expand Down Expand Up @@ -929,6 +946,7 @@ module type T = sig
val details :
[< | `Summary] elt wrap ->
([< | common | `Open], [< | flow5], [> | `Details]) star
[@@reflect.element "details"]

val summary :
([< | summary_attrib], [< | summary_content_fun], [> | summary]) star
Expand All @@ -950,6 +968,7 @@ module type T = sig
| `Lis of ([< | `Li of [< | common]] elt) list_wrap
| `Flows of ([< | flow5] elt) list_wrap
]) -> ([< | common | `Label | `Menu_Type], [> | `Menu]) nullary
[@@reflect.element "menu"]

(** {3 Scripting} *)

Expand Down Expand Up @@ -1106,9 +1125,6 @@ module type Wrapped_functions = sig
val string_of_multilength :
([< Html5_types.multilength], string) Xml.W.ft

val string_of_multilengths :
([< Html5_types.multilength] list, string) Xml.W.ft

val string_of_numbers : (Html5_types.numbers, string) Xml.W.ft

val string_of_sandbox :
Expand Down
8 changes: 2 additions & 6 deletions lib/html5_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type linktype =
| `Sidebar
| `Tag
| `Up
| `Other of string ]
| `Other of string ] [@@reflect.total_variant]

type linktypes = linktype list
(** Authors may use the following recognized link types, listed here with
Expand Down Expand Up @@ -194,7 +194,7 @@ type mediadesc_token =
| `Speech
| `TTY
| `TV
| `Raw_mediadesc of string ]
| `Raw_mediadesc of string ] [@@reflect.total_variant]

type mediadesc = mediadesc_token list

Expand Down Expand Up @@ -237,10 +237,6 @@ type multilength = [ | length | `Relative of int ]
["2*"], and ["3*"], the ["1*"] will be allotted 10 pixels, the ["2*"] will be
allotted 20 pixels, and the ["3*"] will be allotted 30 pixels. *)

(* comma-separated *)
type multilengths = multilength list
(** A comma separated list of items of type MultiLength. *)

type number = int

(* space-separated *)
Expand Down
2 changes: 1 addition & 1 deletion lib/svg_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ type in_value =
| `BackgroundAlpha
| `FillPaint
| `StrokePaint
| `Ref of string ]
| `Ref of string ] [@@reflect.total_variant]

type offset =
[ `Number of float
Expand Down
27 changes: 27 additions & 0 deletions myocamlbuild.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@

open Ocamlbuild_plugin

(* Determine extension of CompiledObject: best *)
let native_suffix =
let env =
BaseEnvLight.load ~allow_empty:true
~filename:MyOCamlbuildBase.env_filename ()
in
if BaseEnvLight.var_get "is_native" env = "true"
then "native" else "byte"

let reflect_ppx () =
let ppx_reflect = "ppx/ppx_reflect."^native_suffix in

let prod = "ppx/%_reflected.ml" in
let dep = "lib/%.mli" in

rule "ppx_reflect: mli -> _reflected.ml" ~prod ~deps:[dep; ppx_reflect]
begin fun env _ ->
Cmd (S [A ppx_reflect ; P (env dep); P (env prod)])
end

let tyxml_ppx () =
let ppx_tyxml = "ppx/ppx_tyxml."^native_suffix in
flag_and_dep [ "ocaml" ; "compile" ; "ppx_tyxml" ] (S [A "-ppx"; P ppx_tyxml])

let () =
dispatch
(fun hook ->
Expand All @@ -44,6 +68,9 @@ let () =
if String.sub Sys.ocaml_version 0 4 = "4.00" then
flag ["ocaml"; "bin_annot"; "compile"] (A "-bin-annot");

reflect_ppx () ;
tyxml_ppx () ;

| _ ->
())

Expand Down
4 changes: 4 additions & 0 deletions opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ dev-repo: "https://github.com/ocsigen/tyxml.git"
build: [
["ocaml" "setup.ml" "-configure"
"--%{camlp4:enable}%-syntax"
"--%{ppx_tools:enable}%-ppx"
"--prefix" prefix]
["ocaml" "setup.ml" "-build"]
]
build-test: [
["ocaml" "setup.ml" "-configure"
"--%{camlp4:enable}%-syntax"
"--%{ppx_tools:enable}%-ppx"
"--enable-tests"
"--prefix" prefix]
["ocaml" "setup.ml" "-build"]
Expand All @@ -31,6 +33,8 @@ depends: [
"uutf"
"base-bytes"
"re"
"markup"
( "base-no-ppx" | "ppx_tools" )
"alcotest" {test}
## OASIS is not required in released version
"oasis" {build & >= "0.4.4"}
Expand Down
Loading