From 697922b455ae95fcfb99151a457a4fea8841c305 Mon Sep 17 00:00:00 2001 From: Drup Date: Wed, 15 Apr 2020 20:37:33 +0200 Subject: [PATCH 1/4] Improve the typing for restricted block constructs This strengthen a bit the typing for dt, address and header elements that are not supposed to be nested. --- lib/html_types.mli | 504 ++++++++++++++++++++++----------------------- 1 file changed, 248 insertions(+), 256 deletions(-) diff --git a/lib/html_types.mli b/lib/html_types.mli index cc6b88be5..263113f1a 100644 --- a/lib/html_types.mli +++ b/lib/html_types.mli @@ -378,19 +378,30 @@ type labelable = [ | resetable | `Progress | `Meter | `Button ] type labelable_without_interactive = [ `Progress | `Meter] -type formatblock = +type formatblock_without_sectioning_heading_header_footer_address = [ - | heading - | sectioning | `Pre | `P - | `Header - | `Footer | `Div | `Blockquote + ] +type formatblock_without_sectioning_heading_header_footer = + [ + | formatblock_without_sectioning_heading_header_footer_address | `Address ] - +type formatblock_without_header_footer = + [ + | heading + | sectioning + | formatblock_without_sectioning_heading_header_footer + ] +type formatblock = + [ + | formatblock_without_header_footer + | `Header + | `Footer + ] type sectionningroot = [ | `Td | `Figure | `Fieldset | `Details | `Body | `Blockquote ] @@ -427,7 +438,7 @@ type (+'interactive, +'noscript, +'regular, +'media) transparent = | `Audio of 'media | `Video of 'media ] -(* _interactive variants are not used for now *) + type (+'noscript, +'regular, +'media) transparent_without_interactive = [ | `Noscript of 'noscript @@ -898,13 +909,8 @@ type phrasing_without_meter = phrasing_without_meter, phrasing_without_media) transparent ] -type core_flow5 = - [ - | core_phrasing - | formassociated - | formatblock +type core_block_misc = [ | `Ul - | `Table | `Style | `Ol | `Menu @@ -912,231 +918,217 @@ type core_flow5 = | `Form | `Figure | `Dl - | `Details | `Main + | `Table ] -type core_flow5_without_interactive = +type core_block = [ - | core_phrasing_without_interactive | formassociated | formatblock - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr + | core_block_misc + | `Details | `Form - | `Figure - | `Dl - | `Main ] - -type core_flow5_without_noscript = + +type core_block_without_form = [ - | core_phrasing_without_noscript | formassociated | formatblock - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr - | `Form - | `Figure - | `Dl + | core_block_misc | `Details - | `Main ] -type core_flow5_without_media = + +type core_block_without_header_footer = [ - | core_phrasing_without_media + | formatblock_without_header_footer + | core_phrasing | formassociated - | formatblock - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr + | core_block_misc + | `Details | `Form - | `Figure - | `Dl + ] +type core_block_without_sectioning_heading_header_footer = + [ + | formatblock_without_sectioning_heading_header_footer + | formassociated + | core_block_misc | `Details - | `Main + | `Form ] - -type flow5_without_interactive = +type core_block_without_sectioning_heading_header_footer_address = [ - core_flow5_without_interactive - | (flow5_without_noscript, flow5, flow5_without_media) - transparent_without_interactive + | formatblock_without_sectioning_heading_header_footer_address + | formassociated + | core_block_misc + | `Details + | `Form ] +type[@deprecated] core_flow5 = + [ core_phrasing | core_block ] +type[@deprecated] core_flow5_without_interactive = + [ core_phrasing_without_interactive | core_block ] +type[@deprecated] core_flow5_without_noscript = + [ core_phrasing_without_noscript | core_block ] +type[@deprecated] core_flow5_without_media = + [ core_phrasing_without_media | core_block ] + +type flow5_without_interactive = + [ core_phrasing_without_interactive + | core_block + | (flow5_without_noscript, + flow5, + flow5_without_media) transparent_without_interactive + ] and flow5_without_noscript = - [ | core_flow5_without_noscript - | (flow5_without_interactive, - flow5, - flow5_without_media) transparent_without_noscript + [ core_phrasing_without_noscript + | core_block + | (flow5_without_interactive, + flow5, + flow5_without_media) transparent_without_noscript ] - and flow5_without_media = - [ core_flow5_without_media + [ core_phrasing_without_media + | core_block | (flow5_without_interactive, flow5_without_noscript, flow5) transparent_without_media ] and flow5 = - [ - | core_flow5 - | (flow5_without_interactive, flow5_without_noscript, flow5, - flow5_without_media) transparent + [ core_phrasing + | core_block + | (flow5_without_interactive, + flow5_without_noscript, + flow5, + flow5_without_media) transparent ] -type flow5_without_table = - [ - | core_phrasing - | formassociated - | formatblock - | `Ul - | `Style - | `Ol - | `Menu - | `Hr - | `Form - | `Figure - | `Dl - | `Details - | `Main - | (flow5_without_interactive, flow5_without_noscript, flow5, - flow5_without_media) transparent - ] type flow5_without_interactive_header_footer = - [ - | heading - | sectioning - | `Pre - | `P - | `Div - | `Blockquote - | `Address - | core_phrasing_without_interactive - | formassociated - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr - | `Form - | `Figure - | `Dl - | `Main - | (flow5_without_noscript, flow5, flow5_without_media) - transparent_without_interactive + [ core_phrasing_without_interactive + | core_block + | (flow5_without_noscript_header_footer, + flow5_without_header_footer, + flow5_without_media_header_footer) transparent_without_interactive + ] +and flow5_without_noscript_header_footer = + [ core_phrasing_without_noscript + | core_block + | (flow5_without_interactive_header_footer, + flow5_without_header_footer, + flow5_without_media_header_footer) transparent_without_noscript + ] +and flow5_without_media_header_footer = + [ core_phrasing_without_media + | core_block + | (flow5_without_interactive_header_footer, + flow5_without_noscript_header_footer, + flow5_without_header_footer) transparent_without_media ] +and flow5_without_header_footer = + [ core_phrasing + | core_block + | (flow5_without_interactive_header_footer, + flow5_without_noscript_header_footer, + flow5_without_header_footer, + flow5_without_media_header_footer) transparent ] -type flow5_without_header_footer = - [ - | heading - | sectioning - | `Pre - | `P - | `Div - | `Blockquote - | `Address - | core_phrasing - | formassociated - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr - | `Form - | `Figure - | `Dl - | `Details - | `Main - | (flow5_without_interactive_header_footer, - flow5_without_noscript, flow5, - flow5_without_media) transparent - ] - -type +'a between_flow5_and_flow5_without_interactive_header_footer = - [< flow5 > `Abbr `Address `Article `Aside `Audio `B `Bdo `Blockquote `Br - `Button `Canvas `Cite `Code `Command `Datalist `Del `Dfn `Div `Dl `Em - `Fieldset `Figure `Form `H1 `H2 `H3 `H4 `H5 `H6 `Hgroup `Hr `I `Img `Picture - `Input `Ins `Kbd `Keygen `Label `Map`Mark `Menu `Meter `Nav `Noscript - `Object `Ol `Output `P `PCDATA `Pre `Progress `Q `Ruby `Samp `Script - `Section `Select `Small `Span `Strong `Style `Sub `Sup `Svg `Table - `Template `Textarea `Time `U `Ul `Var `Video `Wbr] as 'a - -type (+'a, +'b) between_flow5_and_flow5_without_header_footer = - [< core_flow5 - | ([< flow5_without_interactive ] as 'b, - flow5_without_noscript, 'a, - flow5_without_media) +type flow5_without_interactive_sectioning_heading_header_footer = + [ core_phrasing_without_interactive + | core_block_without_sectioning_heading_header_footer + | (flow5_without_noscript_sectioning_heading_header_footer, + flow5_without_sectioning_heading_header_footer, + flow5_without_media_sectioning_heading_header_footer) + transparent_without_interactive + ] +and flow5_without_noscript_sectioning_heading_header_footer = + [ core_phrasing_without_noscript + | core_block_without_sectioning_heading_header_footer + | (flow5_without_interactive_sectioning_heading_header_footer, + flow5_without_sectioning_heading_header_footer, + flow5_without_media_sectioning_heading_header_footer) + transparent_without_noscript + ] +and flow5_without_media_sectioning_heading_header_footer = + [ core_phrasing_without_media + | core_block_without_sectioning_heading_header_footer + | (flow5_without_interactive_sectioning_heading_header_footer, + flow5_without_noscript_sectioning_heading_header_footer, + flow5_without_sectioning_heading_header_footer) + transparent_without_media + ] +and flow5_without_sectioning_heading_header_footer = + [ core_phrasing + | core_block_without_sectioning_heading_header_footer + | (flow5_without_interactive_sectioning_heading_header_footer, + flow5_without_noscript_sectioning_heading_header_footer, + flow5_without_sectioning_heading_header_footer, + flow5_without_media_sectioning_heading_header_footer) transparent - > `A `Abbr `Address `Article `Aside `Audio `Audio_interactive `B - `Bdo `Blockquote `Br `Button `Canvas `Cite `Code `Command - `Datalist `Del `Details `Dfn `Div `Dl `Em `Embed `Fieldset - `Figure `Form `H1 `H2 `H3 `H4 `H5 `H6 `Hgroup `Hr `I `Iframe - `Img `Img_interactive `Picture `Input `Ins `Kbd `Keygen `Label `Map - `Mark `Menu `Meter `Nav `Noscript `Object `Object_interactive - `Ol `Output `P `PCDATA `Pre `Progress `Q `Ruby `Samp `Script - `Section `Select `Small `Span `Strong `Style `Sub `Sup `Svg - `Table `Template `Textarea `Time `U `Ul `Var `Video `Video_interactive - `Wbr ] as 'a - -type flow5_without_form = - [ - | core_phrasing - | formassociated - | formatblock - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr - | `Figure - | `Dl - | `Details - | `Main - | (flow5_without_interactive, flow5_without_noscript, flow5, - flow5_without_media) transparent ] -type flow5_without_sectioning_heading_header_footer_address = - [ - | core_phrasing - | formassociated - | `Pre - | `P - | `Div - | `Blockquote - | `Ul - | `Table - | `Style - | `Ol - | `Menu - | `Hr - | `Form - | `Figure - | `Dl - | `Details - | `Main - | (flow5_without_interactive, flow5_without_noscript, flow5, - flow5_without_media) transparent +type flow5_without_interactive_sectioning_heading_header_footer_address = + [ core_phrasing_without_interactive + | core_block_without_sectioning_heading_header_footer_address + | (flow5_without_noscript_sectioning_heading_header_footer_address, + flow5_without_sectioning_heading_header_footer_address, + flow5_without_media_sectioning_heading_header_footer_address) + transparent_without_interactive + ] +and flow5_without_noscript_sectioning_heading_header_footer_address = + [ core_phrasing_without_noscript + | core_block_without_sectioning_heading_header_footer_address + | (flow5_without_interactive_sectioning_heading_header_footer_address, + flow5_without_sectioning_heading_header_footer_address, + flow5_without_media_sectioning_heading_header_footer_address) + transparent_without_noscript + ] +and flow5_without_media_sectioning_heading_header_footer_address = + [ core_phrasing_without_media + | core_block_without_sectioning_heading_header_footer_address + | (flow5_without_interactive_sectioning_heading_header_footer_address, + flow5_without_noscript_sectioning_heading_header_footer_address, + flow5_without_sectioning_heading_header_footer_address) + transparent_without_media + ] +and flow5_without_sectioning_heading_header_footer_address = + [ core_phrasing + | core_block_without_sectioning_heading_header_footer_address + | (flow5_without_interactive_sectioning_heading_header_footer_address, + flow5_without_noscript_sectioning_heading_header_footer_address, + flow5_without_sectioning_heading_header_footer_address, + flow5_without_media_sectioning_heading_header_footer_address) + transparent ] -type flow5_without_sectioning_heading_header_footer = - [ - | flow5_without_sectioning_heading_header_footer_address - | `Address + +type flow5_without_interactive_form = + [ core_phrasing_without_interactive + | core_block_without_form + | (flow5_without_noscript_form, + flow5_without_form, + flow5_without_media_form) transparent_without_interactive + ] +and flow5_without_noscript_form = + [ core_phrasing_without_noscript + | core_block_without_form + | (flow5_without_interactive_form, + flow5_without_form, + flow5_without_media_form) transparent_without_noscript + ] +and flow5_without_media_form = + [ core_phrasing_without_media + | core_block_without_form + | (flow5_without_interactive_form, + flow5_without_noscript_form, + flow5_without_form) transparent_without_media ] +and flow5_without_form = + [ core_phrasing + | core_block_without_form + | (flow5_without_interactive_form, + flow5_without_noscript_form, + flow5_without_form, + flow5_without_media_form) transparent ] (* @@ -1189,9 +1181,9 @@ type body_attrib = | `OnUnload ] -type body_content = flow5 +type body_content = flow5_without_header_footer -type body_content_fun = flow5 +type body_content_fun = flow5_without_header_footer type svg = [ `Svg ] @@ -1235,18 +1227,18 @@ type header_attrib = [ | common ] (* NAME: section, KIND: star, TYPE: [= common ], [= flow5 ], [=`Section], ARG: [= flow5 ], ATTRIB: OUT: [=`Section] *) type section = [ | `Section ] -type section_content = [ | flow5 ] +type section_content = [ | flow5_without_header_footer ] -type section_content_fun = [ | flow5 ] +type section_content_fun = [ | flow5_without_header_footer ] type section_attrib = [ | common ] (* NAME: nav, KIND: star, TYPE: [= common ], [= flow5 ], [=`Nav], ARG: [= flow5 ], ATTRIB: OUT: [=`Nav] *) type nav = [ | `Nav ] -type nav_content = [ | flow5 ] +type nav_content = [ | flow5_without_header_footer ] -type nav_content_fun = [ | flow5 ] +type nav_content_fun = [ | flow5_without_header_footer ] type nav_attrib = [ | common ] @@ -1329,27 +1321,27 @@ type address_attrib = [ | common ] (* NAME: article, KIND: star, TYPE: [= common ], [= flow5 ], [=`Article], ARG: [= flow5 ], ATTRIB: OUT: [=`Article] *) type article = [ | `Article ] -type article_content = [ | flow5 ] +type article_content = [ | flow5_without_header_footer ] -type article_content_fun = [ | flow5 ] +type article_content_fun = [ | flow5_without_header_footer ] type article_attrib = [ | common ] (* NAME: aside, KIND: star, TYPE: [= common ], [= flow5 ], [=`Aside], ARG: [= flow5 ], ATTRIB: OUT: [=`Aside] *) type aside = [ | `Aside ] -type aside_content = [ | flow5 ] +type aside_content = [ | flow5_without_header_footer ] -type aside_content_fun = [ | flow5 ] +type aside_content_fun = [ | flow5_without_header_footer ] type aside_attrib = [ | common ] (* NAME: main, KIND: star, TYPE: [= common ], [= flow5 ], [=`Main], ARG: [= flow5 ], ATTRIB: OUT: [=`Main] *) type main = [ | `Main ] -type main_content = [ | flow5 ] +type main_content = [ | flow5_without_header_footer ] -type main_content_fun = [ | flow5 ] +type main_content_fun = [ | flow5_without_header_footer ] type main_attrib = [ | common ] @@ -1374,18 +1366,18 @@ type pre_attrib = [ | common ] (* NAME: blockquote, KIND: star, TYPE: [= common | `Cite ],[= flow5 ], [=`Blockquote], ARG: [= flow5 ], ATTRIB: OUT: [=`Blockquote] *) type blockquote = [ | `Blockquote ] -type blockquote_content = [ | flow5 ] +type blockquote_content = [ | flow5_without_header_footer ] -type blockquote_content_fun = [ | flow5 ] +type blockquote_content_fun = [ | flow5_without_header_footer ] type blockquote_attrib = [ | common | `Cite ] (* NAME: div, KIND: star, TYPE: [= common ], [= flow5 ], [=`Div], ARG: [= flow5 ], ATTRIB: OUT: [=`Div] *) type div = [ | `Div ] -type div_content = [ | flow5 ] +type div_content = [ | flow5_without_header_footer ] -type div_content_fun = [ | flow5 ] +type div_content_fun = [ | flow5_without_header_footer ] type div_attrib = [ | common ] @@ -1399,9 +1391,9 @@ type ol_content_fun = [ | `Li of [ | common | `Int_Value ] ] type ol_attrib = [ | common | `Reversed | `Start ] (* NAME: li, KIND: star, TYPE: [= common | `Int_Value] as 'a, [=flow5 ], [=`Li of 'a], ARG: [=flow5 ], ATTRIB: OUT: [=`Li of 'a] *) -type li_content = [ | flow5 ] +type li_content = [ | flow5_without_header_footer ] -type li_content_fun = [ | flow5 ] +type li_content_fun = [ | flow5_without_header_footer ] type li_attrib = [ | common | `Int_Value ] @@ -1418,18 +1410,18 @@ type ul_attrib = [ | common ] (* NAME: dd, KIND: star, TYPE: [= common ], [= flow5 ], [=`Dd], ARG: [= flow5 ], ATTRIB: OUT: [=`Dd] *) type dd = [ | `Dd ] -type dd_content = [ | flow5 ] +type dd_content = [ | flow5_without_header_footer ] -type dd_content_fun = [ | flow5 ] +type dd_content_fun = [ | flow5_without_header_footer ] type dd_attrib = [ | common ] (* NAME: dt, KIND: star, TYPE: [= common ], [= phrasing], [=`Dt], ARG: [= phrasing], ATTRIB: OUT: [=`Dt] *) type dt = [ | `Dt ] -type dt_content = [ | flow5_without_sectioning_heading_header_footer ] +type dt_content = [ | flow5_without_sectioning_heading_header_footer_address ] -type dt_content_fun = [ | flow5_without_sectioning_heading_header_footer ] +type dt_content_fun = [ | flow5_without_sectioning_heading_header_footer_address ] type dt_attrib = [ | common ] @@ -1446,9 +1438,9 @@ type dl_attrib = [ | common ] (* NAME: figcaption, KIND: star, TYPE: [= common ], [= flow5], [=`Figcaption], ARG: [= flow5], ATTRIB: OUT: [=`Figcaption] *) type figcaption = [ | `Figcaption ] -type figcaption_content = [ | flow5 ] +type figcaption_content = [ | flow5_without_header_footer ] -type figcaption_content_fun = [ | flow5 ] +type figcaption_content_fun = [ | flow5_without_header_footer ] type figcaption_attrib = [ | common ] @@ -1456,9 +1448,9 @@ type figcaption_attrib = [ | common ] (* figure *) type figure = [ | `Figure ] -type figure_content = [ | flow5 ] +type figure_content = [ | flow5_without_header_footer ] -type figure_content_fun = [ | flow5 ] +type figure_content_fun = [ | flow5_without_header_footer ] type figure_attrib = [ | common ] @@ -1688,9 +1680,9 @@ type var_content_fun = [ | phrasing ] type var_attrib = [ | common ] (* NAME: a, KIND: star, TYPE: [= common | `Href | `Hreflang | `Media | `Rel | `Target | `Mime_type ], 'a, [= `A of 'a ], ARG: 'a, ATTRIB: OUT: [= `A of 'a ] *) -type a_content = flow5_without_interactive +type a_content = flow5_without_interactive_header_footer -type a_content_fun = flow5_without_interactive +type a_content_fun = flow5_without_interactive_header_footer type 'a a = [ | `A of 'a ] type a_ = [ `A of a_content ] (* should not be used as it may break *) @@ -1701,18 +1693,18 @@ type a_attrib = (* NAME: del, KIND: star, TYPE: [= common | `Cite | `Datetime ], 'a,[=`Del of 'a], ARG: 'a, ATTRIB: OUT: [=`Del of 'a] *) type 'a del = [ | `Del of 'a ] -type del_content = flow5 +type del_content = flow5_without_header_footer type del_ = del_content del -type del_content_fun = flow5 +type del_content_fun = flow5_without_header_footer type del_attrib = [ | common | `Cite | `Datetime ] (* NAME: ins, KIND: star, TYPE: [= common | `Cite | `Datetime ],'a ,[=`Ins of 'a], ARG: 'a , ATTRIB: OUT: [=`Ins of 'a] *) type 'a ins = [ | `Ins of 'a ] -type ins_content = flow5 +type ins_content = flow5_without_header_footer type ins_ = ins_content ins -type ins_content_fun = flow5 +type ins_content_fun = flow5_without_header_footer type ins_attrib = [ | common | `Cite | `Datetime ] @@ -1738,9 +1730,9 @@ type iframe_attrib = | `Referrerpolicy ] -type object__content = [ | flow5 | `Param ] +type object__content = [ | flow5_without_header_footer | `Param ] -type object__content_fun = flow5 +type object__content_fun = flow5_without_header_footer type 'a object_ = [ | `Object of 'a | `Object_interactive of 'a] type object__ = object__content object_ @@ -1794,9 +1786,9 @@ type media_attrib = type 'a audio = [ | `Audio of 'a ] type 'a audio_interactive = [ | `Audio of 'a | `Audio_interactive of 'a ] -type audio_content = flow5_without_media +type audio_content = flow5_without_media_header_footer type audio_ = audio_content audio -type audio_content_fun = flow5_without_media +type audio_content_fun = flow5_without_media_header_footer type audio_attrib = [ | common @@ -1807,9 +1799,9 @@ type audio_attrib = type 'a video = [ | `Video of 'a ] type 'a video_interactive = [ | `Video of 'a | `Video_interactive of 'a ] -type video_content = flow5_without_media +type video_content = flow5_without_media_header_footer type video_ = video_content video -type video_content_fun = flow5_without_media +type video_content_fun = flow5_without_media_header_footer type video_attrib = [ | common @@ -1822,9 +1814,9 @@ type video_attrib = (* NAME: canvas, KIND: star, TYPE: [= common |`Width |`Height],'a, [=`Canvas of 'a], ARG: 'a, ATTRIB: OUT: [=`Canvas of 'a] *) type 'a canvas = [ | `Canvas of 'a ] -type canvas_content = flow5 +type canvas_content = flow5_without_header_footer type canvas_ = canvas_content canvas -type canvas_content_fun = flow5 +type canvas_content_fun = flow5_without_header_footer type canvas_attrib = [ | common | `Width | `Height ] @@ -1861,19 +1853,19 @@ type area_attrib = (* NAME: map, KIND: plus, TYPE: [=common | `Name ],'a, [=`Map of 'a], ARG: 'a, ATTRIB: OUT: [=`Map of 'a] *) type 'a map = [ | `Map of 'a ] -type map_content = flow5 +type map_content = flow5_without_header_footer type map_ = map_content map -type map_content_fun = flow5 +type map_content_fun = flow5_without_header_footer type map_attrib = [ | common | `Name ] (* NAME: caption, KIND: star, TYPE: [= common ], [= flow5_without_table], [=`Caption], ARG: [= flow5_without_table], ATTRIB: OUT: [=`Caption] *) type caption = [ | `Caption ] -type caption_content = [ | flow5_without_table ] +type caption_content = flow5_without_header_footer -type caption_content_fun = [ | flow5_without_table ] +type caption_content_fun = flow5_without_header_footer type caption_attrib = [ | common ] @@ -1943,18 +1935,18 @@ type tfoot_attrib = [ | common ] (* NAME: td, KIND: star, TYPE: [= common | `Colspan | `Headers | `Rowspan ], [= flow5 ], [=`Td], ARG: [= flow5 ], ATTRIB: OUT: [=`Td] *) type td = [ | `Td ] -type td_content = [ | flow5 ] +type td_content = [ | flow5_without_header_footer ] -type td_content_fun = [ | flow5 ] +type td_content_fun = [ | flow5_without_header_footer ] type td_attrib = [ | common | `Colspan | `Headers | `Rowspan ] (* NAME: th, KIND: star, TYPE: [= common | `Colspan | `Headers | `Rowspan | `Scope], [= flow5], [=`Th], ARG: [= flow5], ATTRIB: OUT: [=`Th] *) type th = [ | `Th ] -type th_content = [ | flow5 ] +type th_content = [ | flow5_without_header_footer ] -type th_content_fun = [ | flow5 ] +type th_content_fun = [ | flow5_without_header_footer ] type th_attrib = [ | common | `Colspan | `Headers | `Rowspan | `Scope ] @@ -1990,9 +1982,9 @@ type form_attrib = (* NAME: fieldset, KIND: star, TYPE: [= common | `Disabled | `Form | `Name], [= flow5 ], [=`Fieldset], ARG: [= flow5 ], ATTRIB: OUT: [=`Fieldset] *) type fieldset = [ | `Fieldset ] -type fieldset_content = [ | flow5 ] +type fieldset_content = [ | flow5_without_header_footer ] -type fieldset_content_fun = [ | flow5 ] +type fieldset_content_fun = [ | flow5_without_header_footer ] type fieldset_attrib = [ | common | `Disabled | `Form | `Name ] @@ -2184,9 +2176,9 @@ type output_elt_attrib = [ | common | `Form | `Output_for | `Name ] (* NAME: details, KIND: star, TYPE: [= common | `Open ], [= flow5] elt, [= `Details], ARG: [= flow5] elt, ATTRIB: OUT: [= `Details] *) type details = [ | `Details ] -type details_content = [ | flow5 ] +type details_content = [ | flow5_without_header_footer ] -type details_content_fun = [ | flow5 ] +type details_content_fun = [ | flow5_without_header_footer ] type details_attrib = [ | common | `Open ] @@ -2220,11 +2212,11 @@ type menu_content_fun = notag type menu_attrib = [ | common | `Label | `Menu_Type ] (* NAME: noscript, KIND: plus, TYPE: [= common ], 'a, [=`Noscript of 'a], ARG: 'a, ATTRIB: OUT: [=`Noscript of 'a] *) -type noscript = [ | `Noscript of flow5_without_noscript ] +type noscript = [ | `Noscript of flow5_without_noscript_header_footer ] -type noscript_content = flow5_without_noscript +type noscript_content = flow5_without_noscript_header_footer -type noscript_content_fun = flow5_without_noscript +type noscript_content_fun = flow5_without_noscript_header_footer type noscript_attrib = [ | common ] @@ -2262,9 +2254,9 @@ type template = [ | `Template ] type template_attrib = [ | common ] -type template_content = [ | flow5 ] +type template_content = [ | flow5_without_header_footer ] -type template_content_fun = [ | flow5 ] +type template_content_fun = [ | flow5_without_header_footer ] (* NAME: link, KIND: nullary, TYPE: [= common | `Hreflang | `Media | `Rel | `Href | `Sizes | `Mime_type ], [=`Link], ARG: notag, ATTRIB: OUT: [=`Link] *) type link = [ | `Link ] From 5523e07ca62a0ff8be2c56c65d93752a336760f6 Mon Sep 17 00:00:00 2001 From: Drup Date: Wed, 15 Apr 2020 20:48:19 +0200 Subject: [PATCH 2/4] Remove the remaining `between_*` type. --- lib/html_types.mli | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/html_types.mli b/lib/html_types.mli index 263113f1a..77bda8efb 100644 --- a/lib/html_types.mli +++ b/lib/html_types.mli @@ -701,17 +701,6 @@ and phrasing = | core_phrasing ] -type (+'a, +'b) between_phrasing_and_phrasing_without_interactive = - ( [< core_phrasing - | ([< phrasing_without_interactive] as 'b, - phrasing_without_noscript, - phrasing, - phrasing_without_media) transparent - > `Abbr `B `Bdo `Br `Canvas `Cite `Code `Command - `Datalist `Del `Dfn `Em `I `Img `Picture `Ins `Kbd `Map `Mark `Meter - `Noscript `Object `PCDATA `Progress `Q `Ruby `Samp `Script - `Small `Span `Strong `Sub `Sup `Svg `Template `Time `U `Var `Wbr ] as 'a) - (** Phrasing without the interactive markups *) type phrasing_without_dfn = [ From 455781d154467c430f80085e58cbde820bb5e3a9 Mon Sep 17 00:00:00 2001 From: Drup Date: Wed, 15 Apr 2020 20:38:36 +0200 Subject: [PATCH 3/4] Expand the tests to check for proper coercability. --- test/dune | 10 +- test/html_fail.expected | 235 +++++++++++++++++++++++++++++++++++++--- test/html_fail.ml | 4 + test/test_typing.ml | 32 ++++++ 4 files changed, 258 insertions(+), 23 deletions(-) create mode 100644 test/test_typing.ml diff --git a/test/dune b/test/dune index dc3b16e8a..8068242aa 100644 --- a/test/dune +++ b/test/dune @@ -7,8 +7,8 @@ ) (tests - (names test_html test_svg) - (modules test_html test_svg) + (names test_html test_svg test_typing) + (modules test_html test_svg test_typing) (libraries tyxml alcotest tyxml_test) (package tyxml) ) @@ -43,11 +43,11 @@ ; (rule ; (targets html_fail.result) ; (deps ppx.exe html_fail.ml) -; (action (system "TERM= %{ocaml} -I ../implem/.tyxml.objs/ -noinit -noprompt -ppx './%{exe:ppx.exe} --as-ppx' < html_fail.ml 2>&1 | tail -n +3 > %{targets}")) +; (action (system "TERM= %{ocaml} -I ../implem/.tyxml.objs/byte/ -noinit -noprompt -ppx './%{exe:ppx.exe} --as-ppx' < html_fail.ml 2>&1 | tail -n +3 > %{targets}")) ; ) -; (alias -; (name runtest) +; (rule +; (alias runtest) ; (deps html_fail.result html_fail.expected) ; (action (diff html_fail.expected html_fail.result)) ; (package tyxml-ppx) diff --git a/test/html_fail.expected b/test/html_fail.expected index 1aa855dca..a3a82ed9f 100644 --- a/test/html_fail.expected +++ b/test/html_fail.expected @@ -1,31 +1,33 @@ -Characters 6-14: - div [a [a []]] ;; - ^^^^^^^^ -Error: This expression has type - ([> 'b Html_types.a ] as 'a) Tyxml.Html.elt = 'a Tyxml_html.elt +Line 2, characters 5-13: +2 | div [a [a []]] ;; + ^^^^^^^^ +Error: This expression has type + ([> ([> 'c Html_types.a ] as 'b) Html_types.a ] as 'a) + Tyxml.Html.elt = 'a Tyxml_html.elt but an expression was expected of type ([< Html_types.div_content_fun ] as 'd) Tyxml.Html.elt = 'd Tyxml_html.elt Type 'a = [> `A of 'b ] is not compatible with type 'd = - [< `A of Html_types.flow5_without_interactive + [< `A of Html_types.flow5_without_interactive_header_footer | `Abbr | `Address | `Article | `Aside - | `Audio of Html_types.flow5_without_media - | `Audio_interactive of Html_types.flow5_without_media + | `Audio of Html_types.flow5_without_media_header_footer + | `Audio_interactive of + Html_types.flow5_without_media_header_footer | `B | `Bdo | `Blockquote | `Br | `Button - | `Canvas of Html_types.flow5 + | `Canvas of Html_types.flow5_without_header_footer | `Cite | `Code | `Command | `Datalist - | `Del of Html_types.flow5 + | `Del of Html_types.flow5_without_header_footer | `Details | `Dfn | `Div @@ -50,23 +52,24 @@ Error: This expression has type | `Img | `Img_interactive | `Input - | `Ins of Html_types.flow5 + | `Ins of Html_types.flow5_without_header_footer | `Kbd | `Keygen | `Label | `Main - | `Map of Html_types.flow5 + | `Map of Html_types.flow5_without_header_footer | `Mark | `Menu | `Meter | `Nav - | `Noscript of Html_types.flow5_without_noscript - | `Object of Html_types.flow5 - | `Object_interactive of Html_types.flow5 + | `Noscript of Html_types.flow5_without_noscript_header_footer + | `Object of Html_types.flow5_without_header_footer + | `Object_interactive of Html_types.flow5_without_header_footer | `Ol | `Output | `P | `PCDATA + | `Picture | `Pre | `Progress | `Q @@ -83,15 +86,211 @@ Error: This expression has type | `Sup | `Svg | `Table + | `Template | `Textarea | `Time | `U | `Ul | `Var - | `Video of Html_types.flow5_without_media - | `Video_interactive of Html_types.flow5_without_media + | `Video of Html_types.flow5_without_media_header_footer + | `Video_interactive of + Html_types.flow5_without_media_header_footer | `Wbr ] Type 'b = [> `A of 'c ] is not compatible with type - Html_types.flow5_without_interactive + Html_types.flow5_without_interactive_header_footer + Types for tag `A are incompatible +Line 2, characters 14-28: +2 | div [address [a [address []]]];; + ^^^^^^^^^^^^^^ +Error: This expression has type + ([> ([> Html_types.address ] as 'b) Html_types.a ] as 'a) + Tyxml.Html.elt = 'a Tyxml_html.elt + but an expression was expected of type + ([< Html_types.address_content_fun ] as 'c) Tyxml.Html.elt = + 'c Tyxml_html.elt + Type 'a = [> `A of 'b ] is not compatible with type + 'c = + [< `A of + Html_types.flow5_without_interactive_sectioning_heading_header_footer_address + | `Abbr + | `Audio of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Audio_interactive of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `B + | `Bdo + | `Blockquote + | `Br + | `Button + | `Canvas of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Cite + | `Code + | `Command + | `Datalist + | `Del of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Details + | `Dfn + | `Div + | `Dl + | `Em + | `Embed + | `Fieldset + | `Figure + | `Form + | `Hr + | `I + | `Iframe + | `Img + | `Img_interactive + | `Input + | `Ins of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Kbd + | `Keygen + | `Label + | `Main + | `Map of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Mark + | `Menu + | `Meter + | `Noscript of + Html_types.flow5_without_noscript_sectioning_heading_header_footer_address + | `Object of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Object_interactive of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Ol + | `Output + | `P + | `PCDATA + | `Picture + | `Pre + | `Progress + | `Q + | `Ruby + | `Samp + | `Script + | `Select + | `Small + | `Span + | `Strong + | `Style + | `Sub + | `Sup + | `Svg + | `Table + | `Template + | `Textarea + | `Time + | `U + | `Ul + | `Var + | `Video of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Video_interactive of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Wbr ] + Type 'b = [> `Address ] is not compatible with type + Html_types.flow5_without_interactive_sectioning_heading_header_footer_address + Types for tag `A are incompatible +Line 2, characters 30-48: +2 | body [dl [dd [txt "foo"]; dt [a [h1 [txt "foo"]]]]];; + ^^^^^^^^^^^^^^^^^^ +Error: This expression has type + ([> ([> Html_types.h1 ] as 'b) Html_types.a ] as 'a) Tyxml.Html.elt + = 'a Tyxml_html.elt + but an expression was expected of type + ([< Html_types.dt_content_fun ] as 'c) Tyxml.Html.elt = + 'c Tyxml_html.elt + Type 'a = [> `A of 'b ] is not compatible with type + 'c = + [< `A of + Html_types.flow5_without_interactive_sectioning_heading_header_footer_address + | `Abbr + | `Audio of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Audio_interactive of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `B + | `Bdo + | `Blockquote + | `Br + | `Button + | `Canvas of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Cite + | `Code + | `Command + | `Datalist + | `Del of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Details + | `Dfn + | `Div + | `Dl + | `Em + | `Embed + | `Fieldset + | `Figure + | `Form + | `Hr + | `I + | `Iframe + | `Img + | `Img_interactive + | `Input + | `Ins of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Kbd + | `Keygen + | `Label + | `Main + | `Map of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Mark + | `Menu + | `Meter + | `Noscript of + Html_types.flow5_without_noscript_sectioning_heading_header_footer_address + | `Object of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Object_interactive of + Html_types.flow5_without_sectioning_heading_header_footer_address + | `Ol + | `Output + | `P + | `PCDATA + | `Picture + | `Pre + | `Progress + | `Q + | `Ruby + | `Samp + | `Script + | `Select + | `Small + | `Span + | `Strong + | `Style + | `Sub + | `Sup + | `Svg + | `Table + | `Template + | `Textarea + | `Time + | `U + | `Ul + | `Var + | `Video of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Video_interactive of + Html_types.flow5_without_media_sectioning_heading_header_footer_address + | `Wbr ] + Type 'b = [> `H1 ] is not compatible with type + Html_types.flow5_without_interactive_sectioning_heading_header_footer_address Types for tag `A are incompatible diff --git a/test/html_fail.ml b/test/html_fail.ml index 36f044d4a..3382af029 100644 --- a/test/html_fail.ml +++ b/test/html_fail.ml @@ -1,3 +1,7 @@ open Tyxml.Html ;; div [a [a []]] ;; + +div [address [a [address []]]];; + +body [dl [dd [txt "foo"]; dt [a [h1 [txt "foo"]]]]];; diff --git a/test/test_typing.ml b/test/test_typing.ml new file mode 100644 index 000000000..bb29186de --- /dev/null +++ b/test/test_typing.ml @@ -0,0 +1,32 @@ +open Html_types + +(* We test various type coercion that should always hold *) + +let x = Obj.magic 0 (* get a strong 'a *) + +(* Part of the phrasing hierarchy *) +let _ = + (x : phrasing_without_interactive :> phrasing) +let _ = + (x : phrasing_without_dfn :> phrasing) + +(* Full flow hierarchy *) +let _ = + (x : flow5_without_form :> flow5) +let _ = + (x : flow5_without_sectioning_heading_header_footer_address + :> flow5_without_sectioning_heading_header_footer) +let _ = + (x : flow5_without_sectioning_heading_header_footer + :> flow5_without_header_footer) +let _ = + (x : flow5_without_header_footer + :> flow5) + +(* Part of the flow derived hierarchies *) +let _ = + (x : flow5_without_interactive_header_footer + :> flow5_without_interactive) +let _ = + (x : flow5_without_media_sectioning_heading_header_footer + :> flow5_without_media) From a42c0dbe6676f1af0428517aafd411919fff3e4d Mon Sep 17 00:00:00 2001 From: Drup Date: Wed, 22 Jul 2020 13:56:47 +0200 Subject: [PATCH 4/4] Add change entry. --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 90a3ca9e5..a8f1c13d5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# NEXT + +* Better support for nesting of block elements + (#265 by Gabriel Radanne) + # 4.4.0 * Add support for Reason's JSX syntax with a new `tyxml-jsx` package