@@ -580,7 +580,7 @@ type ('block, 'stops_at_which_tokens) context =
580
580
| In_explicit_list : (Ast .nestable_block_element , stops_at_delimiters ) context
581
581
| In_table_cell : (Ast .nestable_block_element , stops_at_delimiters ) context
582
582
| In_code_results : (Ast .nestable_block_element , code_stop ) context
583
- | In_tag : (Ast .nestable_block_element , Token .t ) context
583
+ | In_tag : (Ast .nestable_block_element , stopped_implicitly ) context
584
584
585
585
(* This is a no-op. It is needed to prove to the type system that nestable block
586
586
elements are acceptable block elements in all contexts. *)
@@ -638,13 +638,12 @@ let rec block_element_list :
638
638
* where_in_line =
639
639
fun context ~parent_markup input ->
640
640
let rec consume_block_elements :
641
- parsed_a_tag :bool ->
642
641
where_in_line ->
643
642
block with_location list ->
644
643
block with_location list
645
644
* stops_at_which_tokens with_location
646
645
* where_in_line =
647
- fun ~ parsed_a_tag where_in_line acc ->
646
+ fun where_in_line acc ->
648
647
let describe token =
649
648
match token with
650
649
| #token_that_always_begins_an_inline_element -> " paragraph"
@@ -657,16 +656,6 @@ let rec block_element_list :
657
656
|> add_warning input
658
657
in
659
658
660
- let warn_if_after_tags { Loc. location; value = token } =
661
- if parsed_a_tag then
662
- let suggestion =
663
- Printf. sprintf " move %s before any tags." (Token. describe token)
664
- in
665
- Parse_error. not_allowed ~what: (describe token)
666
- ~in_what: " the tags section" ~suggestion location
667
- |> add_warning input
668
- in
669
-
670
659
let warn_because_not_at_top_level { Loc. location; value = token } =
671
660
let suggestion =
672
661
Printf. sprintf " move %s outside of any other markup."
@@ -700,31 +689,33 @@ let rec block_element_list :
700
689
| In_tag -> (List. rev acc, next_token, where_in_line)
701
690
| In_code_results ->
702
691
junk input;
703
- consume_block_elements ~parsed_a_tag where_in_line acc)
692
+ consume_block_elements where_in_line acc)
704
693
| { value = `Right_code_delimiter ; _ } as next_token -> (
705
694
match context with
706
695
| In_code_results -> (List. rev acc, next_token, where_in_line)
707
696
| _ ->
708
697
junk input;
709
- consume_block_elements ~parsed_a_tag where_in_line acc)
698
+ consume_block_elements where_in_line acc)
710
699
(* Whitespace. This can terminate some kinds of block elements. It is also
711
700
necessary to track it to interpret [`Minus] and [`Plus] correctly, as
712
701
well as to ensure that all block elements begin on their own line. *)
713
702
| { value = `Space _ ; _ } ->
714
703
junk input;
715
- consume_block_elements ~parsed_a_tag where_in_line acc
704
+ consume_block_elements where_in_line acc
716
705
| { value = `Single_newline _ ; _ } ->
717
706
junk input;
718
- consume_block_elements ~parsed_a_tag `At_start_of_line acc
707
+ consume_block_elements `At_start_of_line acc
719
708
| { value = `Blank_line _ ; _ } as next_token -> (
720
709
match context with
721
- (* Blank lines terminate shorthand lists ([- foo]). They also terminate
722
- paragraphs, but the paragraph parser is aware of that internally. *)
710
+ (* Blank lines terminate shorthand lists ([- foo]) and tags. They also
711
+ terminate paragraphs, but the paragraph parser is aware of that
712
+ internally. *)
723
713
| In_shorthand_list -> (List. rev acc, next_token, where_in_line)
714
+ | In_tag -> (List. rev acc, next_token, where_in_line)
724
715
(* Otherwise, blank lines are pretty much like single newlines. *)
725
716
| _ ->
726
717
junk input;
727
- consume_block_elements ~parsed_a_tag `At_start_of_line acc)
718
+ consume_block_elements `At_start_of_line acc)
728
719
(* Explicit list items ([{li ...}] and [{- ...}]) can never appear directly
729
720
in block content. They can only appear inside [{ul ...}] and [{ol ...}].
730
721
So, catch those. *)
@@ -740,7 +731,7 @@ let rec block_element_list :
740
731
|> add_warning input;
741
732
742
733
junk input;
743
- consume_block_elements ~parsed_a_tag where_in_line acc
734
+ consume_block_elements where_in_line acc
744
735
(* Table rows ([{tr ...}]) can never appear directly
745
736
in block content. They can only appear inside [{table ...}]. *)
746
737
| { value = `Begin_table_row as token ; location } ->
@@ -753,7 +744,7 @@ let rec block_element_list :
753
744
~suggestion location
754
745
|> add_warning input;
755
746
junk input;
756
- consume_block_elements ~parsed_a_tag where_in_line acc
747
+ consume_block_elements where_in_line acc
757
748
(* Table cells ([{th ...}] and [{td ...}]) can never appear directly
758
749
in block content. They can only appear inside [{tr ...}]. *)
759
750
| { value = `Begin_table_cell _ as token ; location } ->
@@ -766,9 +757,8 @@ let rec block_element_list :
766
757
~suggestion location
767
758
|> add_warning input;
768
759
junk input;
769
- consume_block_elements ~parsed_a_tag where_in_line acc
770
- (* Tags. These can appear at the top level only. Also, once one tag is seen,
771
- the only top-level elements allowed are more tags. *)
760
+ consume_block_elements where_in_line acc
761
+ (* Tags. These can appear at the top level only. *)
772
762
| { value = `Tag tag as token ; location } as next_token -> (
773
763
let recover_when_not_at_top_level context =
774
764
warn_because_not_at_top_level next_token;
@@ -779,8 +769,7 @@ let rec block_element_list :
779
769
|> accepted_in_all_contexts context
780
770
|> Loc. at location
781
771
in
782
- consume_block_elements ~parsed_a_tag `At_start_of_line
783
- (paragraph :: acc)
772
+ consume_block_elements `At_start_of_line (paragraph :: acc)
784
773
in
785
774
786
775
match context with
@@ -831,8 +820,7 @@ let rec block_element_list :
831
820
in
832
821
833
822
let tag = Loc. at location (`Tag tag) in
834
- consume_block_elements ~parsed_a_tag: true `After_text
835
- (tag :: acc)
823
+ consume_block_elements `After_text (tag :: acc)
836
824
| (`Deprecated | `Return ) as tag ->
837
825
let content, _stream_head, where_in_line =
838
826
block_element_list In_tag ~parent_markup: token input
@@ -846,8 +834,7 @@ let rec block_element_list :
846
834
location :: List. map Loc. location content |> Loc. span
847
835
in
848
836
let tag = Loc. at location (`Tag tag) in
849
- consume_block_elements ~parsed_a_tag: true where_in_line
850
- (tag :: acc)
837
+ consume_block_elements where_in_line (tag :: acc)
851
838
| (`Param _ | `Raise _ | `Before _ ) as tag ->
852
839
let content, _stream_head, where_in_line =
853
840
block_element_list In_tag ~parent_markup: token input
@@ -862,8 +849,7 @@ let rec block_element_list :
862
849
location :: List. map Loc. location content |> Loc. span
863
850
in
864
851
let tag = Loc. at location (`Tag tag) in
865
- consume_block_elements ~parsed_a_tag: true where_in_line
866
- (tag :: acc)
852
+ consume_block_elements where_in_line (tag :: acc)
867
853
| `See (kind , target ) ->
868
854
let content, _next_token, where_in_line =
869
855
block_element_list In_tag ~parent_markup: token input
@@ -873,23 +859,19 @@ let rec block_element_list :
873
859
in
874
860
let tag = `Tag (`See (kind, target, content)) in
875
861
let tag = Loc. at location tag in
876
- consume_block_elements ~parsed_a_tag: true where_in_line
877
- (tag :: acc)
862
+ consume_block_elements where_in_line (tag :: acc)
878
863
| (`Inline | `Open | `Closed | `Hidden ) as tag ->
879
864
let tag = Loc. at location (`Tag tag) in
880
- consume_block_elements ~parsed_a_tag: true `After_text
881
- (tag :: acc)))
865
+ consume_block_elements `After_text (tag :: acc)))
882
866
| ( { value = #token_that_always_begins_an_inline_element ; _ }
883
867
| { value = `Bar ; _ } ) as next_token ->
884
- warn_if_after_tags next_token;
885
868
warn_if_after_text next_token;
886
869
887
870
let block = paragraph input in
888
871
let block = Loc. map (accepted_in_all_contexts context) block in
889
872
let acc = block :: acc in
890
- consume_block_elements ~parsed_a_tag `After_text acc
873
+ consume_block_elements `After_text acc
891
874
| { value = `Verbatim s as token ; location } as next_token ->
892
- warn_if_after_tags next_token;
893
875
warn_if_after_text next_token;
894
876
if s = " " then
895
877
Parse_error. should_not_be_empty ~what: (Token. describe token) location
@@ -899,9 +881,8 @@ let rec block_element_list :
899
881
let block = accepted_in_all_contexts context token in
900
882
let block = Loc. at location block in
901
883
let acc = block :: acc in
902
- consume_block_elements ~parsed_a_tag `After_text acc
884
+ consume_block_elements `After_text acc
903
885
| { value = `Math_block s as token ; location } as next_token ->
904
- warn_if_after_tags next_token;
905
886
warn_if_after_text next_token;
906
887
if s = " " then
907
888
Parse_error. should_not_be_empty ~what: (Token. describe token) location
@@ -911,14 +892,13 @@ let rec block_element_list :
911
892
let block = accepted_in_all_contexts context token in
912
893
let block = Loc. at location block in
913
894
let acc = block :: acc in
914
- consume_block_elements ~parsed_a_tag `After_text acc
895
+ consume_block_elements `After_text acc
915
896
| {
916
897
value =
917
898
`Code_block (meta, delim, { value = s; location = v_loc }, has_outputs)
918
899
as token;
919
900
location;
920
901
} as next_token ->
921
- warn_if_after_tags next_token;
922
902
warn_if_after_text next_token;
923
903
junk input;
924
904
let delimiter = if delim = " " then None else Some delim in
@@ -958,9 +938,8 @@ let rec block_element_list :
958
938
in
959
939
let block = Loc. at location block in
960
940
let acc = block :: acc in
961
- consume_block_elements ~parsed_a_tag `After_text acc
941
+ consume_block_elements `After_text acc
962
942
| { value = `Modules s as token ; location } as next_token ->
963
- warn_if_after_tags next_token;
964
943
warn_if_after_text next_token;
965
944
966
945
junk input;
@@ -999,9 +978,8 @@ let rec block_element_list :
999
978
let block = accepted_in_all_contexts context (`Modules modules) in
1000
979
let block = Loc. at location block in
1001
980
let acc = block :: acc in
1002
- consume_block_elements ~parsed_a_tag `After_text acc
981
+ consume_block_elements `After_text acc
1003
982
| { value = `Begin_list kind as token ; location } as next_token ->
1004
- warn_if_after_tags next_token;
1005
983
warn_if_after_text next_token;
1006
984
1007
985
junk input;
@@ -1018,10 +996,9 @@ let rec block_element_list :
1018
996
let block = accepted_in_all_contexts context block in
1019
997
let block = Loc. at location block in
1020
998
let acc = block :: acc in
1021
- consume_block_elements ~parsed_a_tag `After_text acc
999
+ consume_block_elements `After_text acc
1022
1000
| { value = (`Begin_table_light | `Begin_table_heavy ) as token; location }
1023
1001
as next_token ->
1024
- warn_if_after_tags next_token;
1025
1002
warn_if_after_text next_token;
1026
1003
junk input;
1027
1004
let block, brace_location =
@@ -1037,7 +1014,7 @@ let rec block_element_list :
1037
1014
let block = accepted_in_all_contexts context (`Table block) in
1038
1015
let block = Loc. at location block in
1039
1016
let acc = block :: acc in
1040
- consume_block_elements ~parsed_a_tag `After_text acc
1017
+ consume_block_elements `After_text acc
1041
1018
| { value = (`Minus | `Plus ) as token ; location } as next_token -> (
1042
1019
(match where_in_line with
1043
1020
| `After_text | `After_shorthand_bullet ->
@@ -1046,8 +1023,6 @@ let rec block_element_list :
1046
1023
|> add_warning input
1047
1024
| _ -> () );
1048
1025
1049
- warn_if_after_tags next_token;
1050
-
1051
1026
match context with
1052
1027
| In_shorthand_list -> (List. rev acc, next_token, where_in_line)
1053
1028
| _ ->
@@ -1064,11 +1039,9 @@ let rec block_element_list :
1064
1039
let block = accepted_in_all_contexts context block in
1065
1040
let block = Loc. at location block in
1066
1041
let acc = block :: acc in
1067
- consume_block_elements ~parsed_a_tag where_in_line acc)
1042
+ consume_block_elements where_in_line acc)
1068
1043
| { value = `Begin_section_heading (level, label) as token; location } as
1069
1044
next_token -> (
1070
- warn_if_after_tags next_token;
1071
-
1072
1045
let recover_when_not_at_top_level context =
1073
1046
warn_because_not_at_top_level next_token;
1074
1047
junk input;
@@ -1083,8 +1056,7 @@ let rec block_element_list :
1083
1056
|> accepted_in_all_contexts context
1084
1057
|> Loc. at location
1085
1058
in
1086
- consume_block_elements ~parsed_a_tag `At_start_of_line
1087
- (paragraph :: acc)
1059
+ consume_block_elements `At_start_of_line (paragraph :: acc)
1088
1060
in
1089
1061
1090
1062
match context with
@@ -1094,7 +1066,10 @@ let rec block_element_list :
1094
1066
else recover_when_not_at_top_level context
1095
1067
| In_explicit_list -> recover_when_not_at_top_level context
1096
1068
| In_table_cell -> recover_when_not_at_top_level context
1097
- | In_tag -> 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
1098
1073
| In_code_results -> recover_when_not_at_top_level context
1099
1074
| Top_level ->
1100
1075
if where_in_line <> `At_start_of_line then
@@ -1127,7 +1102,7 @@ let rec block_element_list :
1127
1102
let heading = `Heading (level, label, content) in
1128
1103
let heading = Loc. at location heading in
1129
1104
let acc = heading :: acc in
1130
- consume_block_elements ~parsed_a_tag `After_text acc)
1105
+ consume_block_elements `After_text acc)
1131
1106
| { value = `Begin_paragraph_style _ as token ; location } ->
1132
1107
junk input;
1133
1108
let content, brace_location =
@@ -1146,13 +1121,11 @@ let rec block_element_list :
1146
1121
|> accepted_in_all_contexts context
1147
1122
|> Loc. at location
1148
1123
in
1149
- consume_block_elements ~parsed_a_tag `At_start_of_line (paragraph :: acc)
1124
+ consume_block_elements `At_start_of_line (paragraph :: acc)
1150
1125
| {
1151
- location;
1152
- value = `Media_with_replacement_text (href, media, content) as token;
1153
- } as next_token ->
1154
- warn_if_after_tags next_token;
1155
-
1126
+ location;
1127
+ value = `Media_with_replacement_text (href, media, content) as token;
1128
+ } ->
1156
1129
junk input;
1157
1130
1158
1131
let r_location =
@@ -1181,10 +1154,8 @@ let rec block_element_list :
1181
1154
let block = accepted_in_all_contexts context block in
1182
1155
let block = Loc. at location block in
1183
1156
let acc = block :: acc in
1184
- consume_block_elements ~parsed_a_tag `After_text acc
1185
- | { location; value = `Simple_media (href , media ) } as next_token ->
1186
- warn_if_after_tags next_token;
1187
-
1157
+ consume_block_elements `After_text acc
1158
+ | { location; value = `Simple_media (href , media ) } ->
1188
1159
junk input;
1189
1160
1190
1161
let r_location =
@@ -1198,7 +1169,7 @@ let rec block_element_list :
1198
1169
let block = accepted_in_all_contexts context block in
1199
1170
let block = Loc. at location block in
1200
1171
let acc = block :: acc in
1201
- consume_block_elements ~parsed_a_tag `After_text acc
1172
+ consume_block_elements `After_text acc
1202
1173
in
1203
1174
1204
1175
let where_in_line =
@@ -1211,7 +1182,7 @@ let rec block_element_list :
1211
1182
| In_tag -> `After_tag
1212
1183
in
1213
1184
1214
- consume_block_elements ~parsed_a_tag: false where_in_line []
1185
+ consume_block_elements where_in_line []
1215
1186
1216
1187
(* {3 Lists} *)
1217
1188
0 commit comments