Skip to content

Commit ea628f4

Browse files
panglesdjonludlam
authored andcommitted
Parser: factor tag and shorthand list context
1 parent f4a0094 commit ea628f4

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

src/parser/syntax.ml

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,12 @@ let _check_subset : stopped_implicitly -> Token.t = fun t -> (t :> Token.t)
576576
- The type of token that the block parser stops at. See discussion above. *)
577577
type ('block, 'stops_at_which_tokens) context =
578578
| Top_level : (Ast.block_element, stops_at_delimiters) context
579-
| In_shorthand_list : (Ast.nestable_block_element, stopped_implicitly) context
579+
| In_implicitely_ended :
580+
[ `Tag | `Shorthand_list ]
581+
-> (Ast.nestable_block_element, stopped_implicitly) context
580582
| In_explicit_list : (Ast.nestable_block_element, stops_at_delimiters) context
581583
| In_table_cell : (Ast.nestable_block_element, stops_at_delimiters) context
582584
| In_code_results : (Ast.nestable_block_element, code_stop) context
583-
| In_tag : (Ast.nestable_block_element, stopped_implicitly) context
584585

585586
(* This is a no-op. It is needed to prove to the type system that nestable block
586587
elements are acceptable block elements in all contexts. *)
@@ -592,11 +593,10 @@ let accepted_in_all_contexts :
592593
fun context block ->
593594
match context with
594595
| Top_level -> (block :> Ast.block_element)
595-
| In_shorthand_list -> block
596+
| In_implicitely_ended (`Tag | `Shorthand_list) -> block
596597
| In_explicit_list -> block
597598
| In_table_cell -> block
598599
| In_code_results -> block
599-
| In_tag -> block
600600

601601
(* Converts a tag to a series of words. This is used in error recovery, when a
602602
tag cannot be generated. *)
@@ -672,9 +672,9 @@ let rec block_element_list :
672672
| { value = `End; _ } as next_token -> (
673673
match context with
674674
| Top_level -> (List.rev acc, next_token, where_in_line)
675-
| In_shorthand_list -> (List.rev acc, next_token, where_in_line)
675+
| In_implicitely_ended (`Tag | `Shorthand_list) ->
676+
(List.rev acc, next_token, where_in_line)
676677
| In_explicit_list -> (List.rev acc, next_token, where_in_line)
677-
| In_tag -> (List.rev acc, next_token, where_in_line)
678678
| In_table_cell -> (List.rev acc, next_token, where_in_line)
679679
| In_code_results -> (List.rev acc, next_token, where_in_line))
680680
| { value = `Right_brace; _ } as next_token -> (
@@ -683,10 +683,10 @@ let rec block_element_list :
683683
possible values of [context]. *)
684684
match context with
685685
| Top_level -> (List.rev acc, next_token, where_in_line)
686-
| In_shorthand_list -> (List.rev acc, next_token, where_in_line)
686+
| In_implicitely_ended (`Tag | `Shorthand_list) ->
687+
(List.rev acc, next_token, where_in_line)
687688
| In_explicit_list -> (List.rev acc, next_token, where_in_line)
688689
| In_table_cell -> (List.rev acc, next_token, where_in_line)
689-
| In_tag -> (List.rev acc, next_token, where_in_line)
690690
| In_code_results ->
691691
junk input;
692692
consume_block_elements where_in_line acc)
@@ -710,8 +710,8 @@ let rec block_element_list :
710710
(* Blank lines terminate shorthand lists ([- foo]) and tags. They also
711711
terminate paragraphs, but the paragraph parser is aware of that
712712
internally. *)
713-
| In_shorthand_list -> (List.rev acc, next_token, where_in_line)
714-
| In_tag -> (List.rev acc, next_token, where_in_line)
713+
| In_implicitely_ended (`Tag | `Shorthand_list) ->
714+
(List.rev acc, next_token, where_in_line)
715715
(* Otherwise, blank lines are pretty much like single newlines. *)
716716
| _ ->
717717
junk input;
@@ -778,15 +778,11 @@ let rec block_element_list :
778778
(* If a tag starts at the beginning of a line, it terminates the preceding
779779
tag and/or the current shorthand list. In this case, return to the
780780
caller, and let the caller decide how to interpret the tag token. *)
781-
| In_shorthand_list ->
781+
| In_implicitely_ended (`Tag | `Shorthand_list) ->
782782
if where_in_line = `At_start_of_line then
783783
(List.rev acc, next_token, where_in_line)
784784
else recover_when_not_at_top_level context
785785
| In_table_cell -> recover_when_not_at_top_level context
786-
| In_tag ->
787-
if where_in_line = `At_start_of_line then
788-
(List.rev acc, next_token, where_in_line)
789-
else recover_when_not_at_top_level context
790786
| In_code_results -> recover_when_not_at_top_level context
791787
(* If this is the top-level call to [block_element_list], parse the
792788
tag. *)
@@ -823,7 +819,8 @@ let rec block_element_list :
823819
consume_block_elements `After_text (tag :: acc)
824820
| (`Deprecated | `Return) as tag ->
825821
let content, _stream_head, where_in_line =
826-
block_element_list In_tag ~parent_markup:token input
822+
block_element_list (In_implicitely_ended `Tag)
823+
~parent_markup:token input
827824
in
828825
let tag =
829826
match tag with
@@ -837,7 +834,8 @@ let rec block_element_list :
837834
consume_block_elements where_in_line (tag :: acc)
838835
| (`Param _ | `Raise _ | `Before _) as tag ->
839836
let content, _stream_head, where_in_line =
840-
block_element_list In_tag ~parent_markup:token input
837+
block_element_list (In_implicitely_ended `Tag)
838+
~parent_markup:token input
841839
in
842840
let tag =
843841
match tag with
@@ -852,7 +850,8 @@ let rec block_element_list :
852850
consume_block_elements where_in_line (tag :: acc)
853851
| `See (kind, target) ->
854852
let content, _next_token, where_in_line =
855-
block_element_list In_tag ~parent_markup:token input
853+
block_element_list (In_implicitely_ended `Tag)
854+
~parent_markup:token input
856855
in
857856
let location =
858857
location :: List.map Loc.location content |> Loc.span
@@ -1024,7 +1023,8 @@ let rec block_element_list :
10241023
| _ -> ());
10251024

10261025
match context with
1027-
| In_shorthand_list -> (List.rev acc, next_token, where_in_line)
1026+
| In_implicitely_ended `Shorthand_list ->
1027+
(List.rev acc, next_token, where_in_line)
10281028
| _ ->
10291029
let items, where_in_line =
10301030
shorthand_list_items next_token where_in_line input
@@ -1060,16 +1060,12 @@ let rec block_element_list :
10601060
in
10611061

10621062
match context with
1063-
| In_shorthand_list ->
1063+
| In_implicitely_ended (`Tag | `Shorthand_list) ->
10641064
if where_in_line = `At_start_of_line then
10651065
(List.rev acc, next_token, where_in_line)
10661066
else recover_when_not_at_top_level context
10671067
| In_explicit_list -> recover_when_not_at_top_level context
10681068
| In_table_cell -> recover_when_not_at_top_level context
1069-
| In_tag ->
1070-
if where_in_line = `At_start_of_line then
1071-
(List.rev acc, next_token, where_in_line)
1072-
else recover_when_not_at_top_level context
10731069
| In_code_results -> recover_when_not_at_top_level context
10741070
| Top_level ->
10751071
if where_in_line <> `At_start_of_line then
@@ -1175,11 +1171,11 @@ let rec block_element_list :
11751171
let where_in_line =
11761172
match context with
11771173
| Top_level -> `At_start_of_line
1178-
| In_shorthand_list -> `After_shorthand_bullet
1174+
| In_implicitely_ended `Shorthand_list -> `After_shorthand_bullet
11791175
| In_explicit_list -> `After_explicit_list_bullet
11801176
| In_table_cell -> `After_table_cell
11811177
| In_code_results -> `After_tag
1182-
| In_tag -> `After_tag
1178+
| In_implicitely_ended `Tag -> `After_tag
11831179
in
11841180

11851181
consume_block_elements where_in_line []
@@ -1219,7 +1215,8 @@ and shorthand_list_items :
12191215
junk input;
12201216

12211217
let content, stream_head, where_in_line =
1222-
block_element_list In_shorthand_list ~parent_markup:bullet input
1218+
block_element_list (In_implicitely_ended `Shorthand_list)
1219+
~parent_markup:bullet input
12231220
in
12241221
if content = [] then
12251222
Parse_error.should_not_be_empty ~what:(Token.describe bullet)

0 commit comments

Comments
 (0)