this repo has no description
at main 42 lines 1.4 kB view raw
1include Odoc_parser.Loc 2 3let set_end_as_offset_from_start offset span = 4 { span with end_ = { span.start with column = span.start.column + offset } } 5 6let point_in_string s offset point = 7 let rec scan_string line column index = 8 if index >= offset then (line, column) 9 else if index >= String.length s then (line, column) 10 else 11 match s.[index] with 12 | '\n' -> scan_string (line + 1) 0 (index + 1) 13 | _ -> scan_string line (column + 1) (index + 1) 14 in 15 16 let line, column = scan_string 0 0 0 in 17 18 { line = point.line + line; column = point.column + column } 19 20(* Calling this repeatedly on the same string can be optimized, but there is no 21 evidence yet that performance of this is a problem. *) 22let in_string s ~offset ~length s_span = 23 { 24 s_span with 25 start = point_in_string s offset s_span.start; 26 end_ = point_in_string s (offset + length) s_span.start; 27 } 28 29let pp fmt l = 30 Format.fprintf fmt "File \"%s\", " l.file; 31 if l.start.line = l.end_.line then 32 Format.fprintf fmt "line %i, characters %i-%i" l.start.line l.start.column 33 l.end_.column 34 else 35 Format.fprintf fmt "line %i, character %i to line %i, character %i" 36 l.start.line l.start.column l.end_.line l.end_.column 37 38let pp_span_start fmt s = 39 Format.fprintf fmt "File \"%s\", line %d, character %d" s.file s.start.line 40 s.start.column 41 42let span_equal = ( = )