@@ -83,7 +83,8 @@ let warning_loc =
83
83
let warning =
84
84
with_location_adjustments warning_loc
85
85
86
- let unescape_tag s start_loc input =
86
+ let unescape_tag s offset input =
87
+ let start_loc = Lexing. lexeme_start input.lexbuf + String. length offset in
87
88
let warn n c =
88
89
let start = input.offset_to_location @@ start_loc + n in
89
90
let end_ = input.offset_to_location @@ start_loc + n + 2 in
@@ -389,7 +390,7 @@ and token input = parse
389
390
in
390
391
let emit_truncated_code_block () =
391
392
let empty_content = with_location_adjustments (fun _ -> Loc. at) input " " in
392
- emit ~start_offset input (`Code_block (Some (lang_tag, None ), delim, empty_content, false ))
393
+ emit ~start_offset input (`Code_block (Some (lang_tag, [] ), delim, empty_content, false ))
393
394
in
394
395
(* Disallow result block sections for code blocks without a delimiter.
395
396
This avoids the surprising parsing of '][' ending the code block. *)
@@ -401,15 +402,15 @@ and token input = parse
401
402
code_block allow_result_block start_offset content_offset metadata
402
403
prefix delim input lexbuf
403
404
in
404
- match code_block_metadata_tail None input [] lexbuf with
405
+ match code_block_metadata_tail input [] lexbuf with
405
406
| `Ok metadata -> code_block_with_metadata metadata
406
407
| `Eof ->
407
408
warning input ~start_offset Parse_error. truncated_code_block_meta;
408
409
emit_truncated_code_block ()
409
410
| `Invalid_char c ->
410
411
warning input ~start_offset
411
412
(Parse_error. language_tag_invalid_char lang_tag_ c);
412
- code_block_with_metadata None
413
+ code_block_with_metadata []
413
414
}
414
415
415
416
| " {@" horizontal_space* '['
@@ -735,79 +736,41 @@ and bad_markup_recovery start_offset input = parse
735
736
(Parse_error. bad_markup (" {" ^ rest) ~suggestion );
736
737
emit input (`Code_span text) ~start_offset }
737
738
738
- and code_block_metadata_tail start_offset input acc = parse
739
- | (space_char* '[' ) {
740
- match acc with [] -> `Ok None | _ ->
741
- let start_offset = match start_offset with None -> Lexing. lexeme_start lexbuf | Some s -> s in
742
- let res =
743
- let res = List. rev acc in
744
- with_location_adjustments ~start_offset ~adjust_end_by: " [" (fun _ -> Loc. at) input res
745
- in
746
- `Ok (Some res)
747
- }
748
- | (space_char+ as prefix)
749
- ((('"' as quote) (tag_quoted_atom as value) '"' )
750
- | (tag_unquoted_atom as value))
739
+ and code_block_metadata_atom input = parse
740
+ | '"' (tag_quoted_atom as value) '"'
751
741
{
752
- let start_offset =
753
- match start_offset with
754
- | None -> Some (Lexing. lexeme_start lexbuf)
755
- | Some _ -> start_offset
756
- in
757
- let adjust_start_by = prefix in
758
- let start_loc =
759
- Lexing. lexeme_start input.lexbuf +
760
- (String. length adjust_start_by) +
761
- (match quote with Some _ -> 1 | _ -> 0 )
762
- in
763
- let value = `Tag (unescape_tag value start_loc input) in
764
- let tag =
765
- with_location_adjustments ~adjust_start_by (fun _ -> Loc. at) input value
766
- in
767
- let acc = tag :: acc in
768
- code_block_metadata_tail start_offset input acc lexbuf
769
- }
742
+ let adjust_start_by = " \" " in
743
+ with_location_adjustments ~adjust_start_by ~adjust_end_by: " \" " (fun _ -> Loc. at) input (unescape_tag value adjust_start_by input) }
744
+ | (tag_unquoted_atom as value)
745
+ { with_location_adjustments (fun _ -> Loc. at) input value }
746
+
747
+ and code_block_metadata_tail input acc = parse
748
+ | (space_char* '[' ) { `Ok (List. rev acc) }
770
749
| (space_char+ as prefix)
771
- (((('"' as key_quote) (tag_quoted_atom as key) '"' as full_key) |
772
- ((tag_unquoted_atom as key) as full_key))
773
- '='
774
- (((('"' as tag_quote) (tag_quoted_atom as value) '"' ) as full_value) |
775
- ((tag_unquoted_atom as value) as full_value)))
750
+ '"' (tag_quoted_atom as key) '"' '='
751
+ {
752
+ let adjust_start_by = prefix ^ " \" " in
753
+ let key = with_location_adjustments ~adjust_start_by ~adjust_end_by: " \" ="
754
+ (fun _ -> Loc. at) input (unescape_tag key adjust_start_by input) in
755
+ let value = code_block_metadata_atom input lexbuf in
756
+ code_block_metadata_tail input (`Binding (key, value) :: acc) lexbuf }
757
+ | (space_char+ as prefix)
758
+ '"' (tag_quoted_atom as tag) '"' {
759
+ let adjust_start_by = prefix ^ " \" " in
760
+ let tag = with_location_adjustments ~adjust_start_by ~adjust_end_by: " \" "
761
+ (fun _ -> Loc. at) input (unescape_tag tag adjust_start_by input) in
762
+ code_block_metadata_tail input (`Tag tag :: acc) lexbuf }
763
+ | (space_char+ as _prefix)
764
+ (tag_unquoted_atom as key) '='
776
765
{
777
- let start_offset = match start_offset with None -> Some (Lexing. lexeme_start lexbuf) | Some _ -> start_offset in
778
- let key =
779
- let adjust_start_by = prefix in
780
- let adjust_end_by = " =" ^ full_value in
781
- let start_loc =
782
- Lexing. lexeme_start input.lexbuf +
783
- (String. length adjust_start_by) +
784
- (match key_quote with Some _ -> 1 | _ -> 0 )
785
- in
786
- let key = unescape_tag key start_loc input in
787
- with_location_adjustments
788
- ~adjust_start_by ~adjust_end_by
789
- (fun _ -> Loc. at) input key
790
- in
791
- let value =
792
- let adjust_start_by = prefix ^ full_key ^ " =" in
793
- let start_loc =
794
- Lexing. lexeme_start input.lexbuf +
795
- (String. length adjust_start_by) +
796
- (match key_quote with Some _ -> 2 | _ -> 0 ) +
797
- (match tag_quote with Some _ -> 1 | _ -> 0 )
798
- in
799
- let value = unescape_tag value start_loc input in
800
- with_location_adjustments ~adjust_start_by
801
- (fun _ -> Loc. at) input value
802
- in
803
- let binding = `Binding (key, value) in
804
- let binding =
805
- let adjust_start_by = prefix in
806
- with_location_adjustments ~adjust_start_by (fun _ -> Loc. at) input binding
807
- in
808
- let acc = binding :: acc in
809
- code_block_metadata_tail start_offset input acc lexbuf
810
- }
766
+ let key = with_location_adjustments (fun _ -> Loc. at) input key in
767
+ let value = code_block_metadata_atom input lexbuf in
768
+ code_block_metadata_tail input (`Binding (key, value) :: acc) lexbuf }
769
+ | (space_char+ as _prefix)
770
+ (tag_unquoted_atom as tag)
771
+ {
772
+ let tag = with_location_adjustments (fun _ -> Loc. at) input tag in
773
+ code_block_metadata_tail input (`Tag tag :: acc) lexbuf }
811
774
| _ as c
812
775
{ `Invalid_char c }
813
776
| eof
0 commit comments