this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Format

+81 -67
+6 -9
src/parser/odoc_parser.ml
··· 81 81 82 82 (* Given a Loc.point and the result of [parse_comment], this function returns 83 83 a valid Lexing.position *) 84 - let position_of_point : 85 - t -> 86 - Loc.point -> 87 - Lexing.position = 84 + let position_of_point : t -> Loc.point -> Lexing.position = 88 85 fun v point -> 89 - let { reversed_newlines; original_pos; _} = v in 86 + let { reversed_newlines; original_pos; _ } = v in 90 87 let line_in_comment = point.Loc.line - original_pos.pos_lnum + 1 in 91 88 let rec find_pos_bol reversed_newlines_prefix = 92 89 match reversed_newlines_prefix with 93 90 | [] -> assert false 94 91 | [ _ ] -> original_pos.pos_bol 95 92 | (line_number, line_start_offset) :: prefix -> 96 - if line_number > line_in_comment then find_pos_bol prefix 97 - else line_start_offset + original_pos.pos_cnum 93 + if line_number > line_in_comment then find_pos_bol prefix 94 + else line_start_offset + original_pos.pos_cnum 98 95 in 99 96 let pos_bol = find_pos_bol reversed_newlines in 100 97 let pos_lnum = point.Loc.line in 101 98 let pos_cnum = point.column + pos_bol in 102 99 let pos_fname = original_pos.pos_fname in 103 - { Lexing.pos_bol; pos_lnum; pos_cnum; pos_fname} 100 + { Lexing.pos_bol; pos_lnum; pos_cnum; pos_fname } 104 101 105 102 (* The main entry point for this module *) 106 103 let parse_comment ~location ~text = ··· 121 118 122 119 (* Accessor functions, as [t] is opaque *) 123 120 let warnings t = t.warnings 124 - let ast t = t.ast 125 121 122 + let ast t = t.ast
+1 -3
src/parser/odoc_parser.mli
··· 17 17 in the 4th column (e.g. [{... pos_bol=0; pos_cnum=3 }]) *) 18 18 19 19 module Ast = Ast 20 - 21 20 module Loc = Loc 22 21 23 22 (** Warnings produced during parsing. *) ··· 34 33 printed. *) 35 34 end 36 35 37 - 38 36 val warnings : t -> Warning.t list 39 37 (** Extract any warnings from the parser result. *) 40 38 ··· 45 43 (** Helper function to turn the internal representation of positions back into 46 44 the usual representation in the Lexing module. Note that this relies on 47 45 the information passed in {!parse_comment}, and hence requires the result 48 - of that call in addition to the {!Loc.point} being converted. *) 46 + of that call in addition to the {!Loc.point} being converted. *)
+73 -53
src/parser/test/test.ml
··· 81 81 let tag at : Ast.tag -> sexp = function 82 82 | `Author s -> List [ Atom "@author"; Atom s ] 83 83 | `Deprecated es -> 84 - List (Atom "@deprecated" :: List.map (at.at (nestable_block_element at)) es) 84 + List 85 + (Atom "@deprecated" :: List.map (at.at (nestable_block_element at)) es) 85 86 | `Param (s, es) -> 86 87 List 87 - ([ Atom "@param"; Atom s ] @ List.map (at.at (nestable_block_element at)) es) 88 + ([ Atom "@param"; Atom s ] 89 + @ List.map (at.at (nestable_block_element at)) es) 88 90 | `Raise (s, es) -> 89 91 List 90 - ([ Atom "@raise"; Atom s ] @ List.map (at.at (nestable_block_element at)) es) 92 + ([ Atom "@raise"; Atom s ] 93 + @ List.map (at.at (nestable_block_element at)) es) 91 94 | `Return es -> 92 95 List (Atom "@return" :: List.map (at.at (nestable_block_element at)) es) 93 96 | `See (kind, s, es) -> ··· 103 106 | `Since s -> List [ Atom "@since"; Atom s ] 104 107 | `Before (s, es) -> 105 108 List 106 - ([ Atom "@before"; Atom s ] @ List.map (at.at (nestable_block_element at)) es) 109 + ([ Atom "@before"; Atom s ] 110 + @ List.map (at.at (nestable_block_element at)) es) 107 111 | `Version s -> List [ Atom "@version"; Atom s ] 108 112 | `Canonical p -> List [ Atom "@canonical"; at.at str p ] 109 113 | `Inline -> Atom "@inline" ··· 115 119 | `Heading (level, label, es) -> 116 120 let label = List [ Atom "label"; opt str label ] in 117 121 let level = string_of_int level in 118 - List [ Atom level; label; List (List.map (at.at (inline_element at)) es) ] 122 + List 123 + [ Atom level; label; List (List.map (at.at (inline_element at)) es) ] 119 124 | `Tag t -> tag at t 120 125 121 - let docs at : Ast.t -> sexp = fun f -> List (List.map (at.at (block_element at)) f) 126 + let docs at : Ast.t -> sexp = 127 + fun f -> List (List.map (at.at (block_element at)) f) 122 128 end 123 129 124 130 let error err = Atom (Odoc_parser.Warning.to_string err) ··· 131 137 List [ List [ Atom "output"; value ]; List [ Atom "warnings"; warnings ] ] 132 138 in 133 139 Sexplib0.Sexp.pp_hum formatter output; 134 - Format.pp_print_flush formatter () 135 - 136 - let test ?(location = { Loc.line = 1; column = 0 }) str = 140 + Format.pp_print_flush formatter () 141 + 142 + let test ?(location = { Loc.line = 1; column = 0 }) str = 137 143 let dummy_filename = "f.ml" in 138 144 let location = 139 145 { ··· 5091 5097 "{!indexlist}" 5092 5098 (Ok []); *) 5093 5099 5094 - let lexing_pos_to_sexp : Lexing.position -> sexp = fun v -> 5095 - List [ 5096 - List [Atom "pos_fname"; Atom v.pos_fname]; 5097 - List [Atom "pos_bol"; Atom (string_of_int v.pos_bol)]; 5098 - List [Atom "pos_lnum"; Atom (string_of_int v.pos_lnum)]; 5099 - List [Atom "pos_cnum"; Atom (string_of_int v.pos_cnum)]; 5100 + let lexing_pos_to_sexp : Lexing.position -> sexp = 5101 + fun v -> 5102 + List 5103 + [ 5104 + List [ Atom "pos_fname"; Atom v.pos_fname ]; 5105 + List [ Atom "pos_bol"; Atom (string_of_int v.pos_bol) ]; 5106 + List [ Atom "pos_lnum"; Atom (string_of_int v.pos_lnum) ]; 5107 + List [ Atom "pos_cnum"; Atom (string_of_int v.pos_cnum) ]; 5108 + ] 5109 + 5110 + let parser_output formatter pv = 5111 + let ast, warnings = Odoc_parser.(ast pv, warnings pv) in 5112 + let at conv v = 5113 + let { Loc.start; end_; _ } = Loc.location v in 5114 + let v' = Loc.value v |> conv in 5115 + let start' = 5116 + Odoc_parser.position_of_point pv start |> lexing_pos_to_sexp 5117 + in 5118 + let start'' = Location_to_sexp.point start in 5119 + let end' = 5120 + Odoc_parser.position_of_point pv end_ |> lexing_pos_to_sexp 5121 + in 5122 + let end'' = Location_to_sexp.point end_ in 5123 + List 5124 + [ 5125 + List [ Atom "start"; start' ]; 5126 + List [ Atom "start_loc"; start'' ]; 5127 + List [ Atom "end"; end' ]; 5128 + List [ Atom "end_loc"; end'' ]; 5129 + List [ Atom "value"; v' ]; 5100 5130 ] 5101 - 5102 - let parser_output formatter pv = 5103 - let ast, warnings = Odoc_parser.(ast pv, warnings pv) in 5104 - let at conv v = 5105 - let { Loc.start; end_; _ } = Loc.location v in 5106 - let v' = Loc.value v |> conv in 5107 - let start' = Odoc_parser.position_of_point pv start |> lexing_pos_to_sexp in 5108 - let start'' = Location_to_sexp.point start in 5109 - let end' = Odoc_parser.position_of_point pv end_ |> lexing_pos_to_sexp in 5110 - let end'' = Location_to_sexp.point end_ in 5111 - List [ 5112 - List [Atom "start"; start']; 5113 - List [Atom "start_loc"; start'']; 5114 - List [Atom "end"; end']; 5115 - List [Atom "end_loc"; end'']; 5116 - List [Atom "value"; v'] 5117 - ] 5118 - in 5119 - let sexp = Ast_to_sexp.(docs { at = at} ast) in 5120 - let warnings = List (List.map error warnings) in 5121 - let output = 5122 - List [ List [ Atom "output"; sexp ]; List [ Atom "warnings"; warnings ] ] 5123 - in 5124 - Sexplib0.Sexp.pp_hum formatter output; 5125 - Format.pp_print_flush formatter () 5126 - 5127 - 5128 - 5129 - let test ?(location = Lexing.{pos_bol=0; pos_cnum=0; pos_lnum=1; pos_fname="none"}) text = 5131 + in 5132 + let sexp = Ast_to_sexp.(docs { at } ast) in 5133 + let warnings = List (List.map error warnings) in 5134 + let output = 5135 + List 5136 + [ List [ Atom "output"; sexp ]; List [ Atom "warnings"; warnings ] ] 5137 + in 5138 + Sexplib0.Sexp.pp_hum formatter output; 5139 + Format.pp_print_flush formatter () 5140 + 5141 + let test 5142 + ?(location = 5143 + Lexing.{ pos_bol = 0; pos_cnum = 0; pos_lnum = 1; pos_fname = "none" }) 5144 + text = 5130 5145 let ast = Odoc_parser.parse_comment ~location ~text in 5131 5146 Format.printf "%a" parser_output ast 5132 5147 5133 5148 let non_offset_location = 5134 5149 test "one\n two\n three"; 5135 - [%expect{| 5150 + [%expect 5151 + {| 5136 5152 ((output 5137 5153 (((start ((pos_fname none) (pos_bol 0) (pos_lnum 1) (pos_cnum 0))) 5138 5154 (start_loc (1 0)) ··· 5160 5176 (start_loc (3 2)) 5161 5177 (end ((pos_fname none) (pos_bol 9) (pos_lnum 3) (pos_cnum 16))) 5162 5178 (end_loc (3 7)) (value (word three))))))))) 5163 - (warnings ())) |} ] 5179 + (warnings ())) |}] 5164 5180 5165 - let offset_location = 5166 - test ~location:Lexing.{pos_bol=10; pos_cnum=20; pos_lnum=2; pos_fname="none"} "one\n two\n three"; 5167 - [%expect{| 5181 + let offset_location = 5182 + test 5183 + ~location: 5184 + Lexing. 5185 + { pos_bol = 10; pos_cnum = 20; pos_lnum = 2; pos_fname = "none" } 5186 + "one\n two\n three"; 5187 + [%expect 5188 + {| 5168 5189 ((output 5169 5190 (((start ((pos_fname none) (pos_bol 10) (pos_lnum 2) (pos_cnum 20))) 5170 5191 (start_loc (2 10)) ··· 5192 5213 (start_loc (4 2)) 5193 5214 (end ((pos_fname none) (pos_bol 29) (pos_lnum 4) (pos_cnum 36))) 5194 5215 (end_loc (4 7)) (value (word three))))))))) 5195 - (warnings ())) |} ] 5196 - 5197 - end in 5198 - () 5216 + (warnings ())) |}] 5217 + end in 5218 + ()
+1 -2
src/parser/warning.ml
··· 13 13 in 14 14 Printf.sprintf "File \"%s\", %s:\n%s" location.file location_string message 15 15 16 - let pp fmt v = 17 - Format.fprintf fmt "%s" (to_string v) 16 + let pp fmt v = Format.fprintf fmt "%s" (to_string v) 18 17 19 18 let kasprintf k fmt = 20 19 Format.(kfprintf (fun _ -> k (flush_str_formatter ())) str_formatter fmt)