package melange
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Toolchain to produce JS from Reason/OCaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
melange-6.0.1-414.tbz
sha256=c1cce011864740dc43ee0f4e8130f70725f5e7042942cce653be5b6a8b439fb5
sha512=04fc82d97d5b9632c4ee041414d9fe104556a8c329e7444ffd71017baa00612da103fda91c309fc29a16e143c29d8748e1b1035a74681b61ff65fcfdf7f4e59c
doc/src/melange.js_parser/loc.ml.html
Source file loc.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186type position = { line: int ; column: int }[@@deriving (eq, show)] include struct let _ = fun (_ : position) -> () let rec equal_position : position -> position -> bool = (( fun lhs rhs -> ((fun (a : int) b -> a = b) lhs.line rhs.line) && ((fun (a : int) b -> a = b) lhs.column rhs.column)) [@ocaml.warning "-39"][@ocaml.warning "-A"])[@@ocaml.warning "-39"] let _ = equal_position let rec pp_position : Format.formatter -> position -> unit = (( fun fmt x -> Format.fprintf fmt "@[<2>{ "; ((Format.fprintf fmt "@[%s =@ " "Loc.line"; (Format.fprintf fmt "%d") x.line; Format.fprintf fmt "@]"); Format.fprintf fmt ";@ "; Format.fprintf fmt "@[%s =@ " "column"; (Format.fprintf fmt "%d") x.column; Format.fprintf fmt "@]"); Format.fprintf fmt "@ }@]") [@ocaml.warning "-39"][@ocaml.warning "-A"]) and show_position : position -> string = fun x -> Format.asprintf "%a" pp_position x [@@ocaml.warning "-32"] let _ = pp_position and _ = show_position end[@@ocaml.doc "@inline"][@@merlin.hide ] type t = { source: File_key.t option ; start: position ; _end: position }[@@deriving show] include struct let _ = fun (_ : t) -> () let rec pp : Format.formatter -> t -> unit = ((let __2 = pp_position and __1 = pp_position and __0 = File_key.pp in (( fun fmt x -> Format.fprintf fmt "@[<2>{ "; (((Format.fprintf fmt "@[%s =@ " "Loc.source"; ((function | None -> Format.pp_print_string fmt "None" | Some x -> (Format.pp_print_string fmt "(Some "; (__0 fmt) x; Format.pp_print_string fmt ")"))) x.source; Format.fprintf fmt "@]"); Format.fprintf fmt ";@ "; Format.fprintf fmt "@[%s =@ " "start"; (__1 fmt) x.start; Format.fprintf fmt "@]"); Format.fprintf fmt ";@ "; Format.fprintf fmt "@[%s =@ " "_end"; (__2 fmt) x._end; Format.fprintf fmt "@]"); Format.fprintf fmt "@ }@]") [@ocaml.warning "-A"])) [@ocaml.warning "-39"]) and show : t -> string = fun x -> Format.asprintf "%a" pp x[@@ocaml.warning "-32"] let _ = pp and _ = show end[@@ocaml.doc "@inline"][@@merlin.hide ] let none = { source = None; start = { line = 0; column = 0 }; _end = { line = 0; column = 0 } } let is_none (x : t) = (x == none) || (match x with | { source = None; start = { line = 0; column = 0 }; _end = { line = 0; column = 0 } } -> true | _ -> false) let is_none_ignore_source (x : t) = (x == none) || (match x with | { source = _; start = { line = 0; column = 0 }; _end = { line = 0; column = 0 } } -> true | _ -> false) let btwn loc1 loc2 = { source = (loc1.source); start = (loc1.start); _end = (loc2._end) } let char_before loc = let start = let { line; column } = loc.start in let column = if column > 0 then column - 1 else column in { line; column } in let _end = loc.start in { loc with start; _end } let first_char loc = let start = loc.start in let _end = { start with column = (start.column + 1) } in { loc with _end } let pos_cmp a b = let k = a.line - b.line in if k = 0 then a.column - b.column else k let span_compare a b = let k = File_key.compare_opt a.source b.source in if k = 0 then let k = pos_cmp a.start b.start in (if k <= 0 then let k = pos_cmp a._end b._end in (if k >= 0 then 0 else (-1)) else 1) else k[@@ocaml.doc "\n * If `a` spans (completely contains) `b`, then returns 0.\n * If `b` starts before `a` (even if it ends inside), returns < 0.\n * If `b` ends after `a` (even if it starts inside), returns > 0.\n "] let contains loc1 loc2 = (span_compare loc1 loc2) = 0[@@ocaml.doc " [contains loc1 loc2] returns true if [loc1] entirely overlaps [loc2] "] let intersects loc1 loc2 = ((File_key.compare_opt loc1.source loc2.source) = 0) && (not (((pos_cmp loc1._end loc2.start) < 0) || ((pos_cmp loc1.start loc2._end) > 0)))[@@ocaml.doc " [intersects loc1 loc2] returns true if [loc1] intersects [loc2] at all "] let lines_intersect loc1 loc2 = ((File_key.compare_opt loc1.source loc2.source) = 0) && (not (((loc1._end).line < (loc2.start).line) || ((loc1.start).line > (loc2._end).line)))[@@ocaml.doc " [lines_intersect loc1 loc2] returns true if [loc1] and [loc2] cover any part of\n the same line, even if they don't actually intersect.\n\n For example, if [loc1] ends and then [loc2] begins later on the same line,\n [intersects loc1 loc2] is false, but [lines_intersect loc1 loc2] is true. "] let compare_ignore_source loc1 loc2 = match pos_cmp loc1.start loc2.start with | 0 -> pos_cmp loc1._end loc2._end | k -> k let compare loc1 loc2 = let k = File_key.compare_opt loc1.source loc2.source in if k = 0 then compare_ignore_source loc1 loc2 else k let equal loc1 loc2 = (compare loc1 loc2) = 0 let debug_to_string ?(include_source= false) loc = let source = if include_source then Printf.sprintf "%S: " (match loc.source with | Some src -> File_key.to_string src | None -> "<NONE>") else "" in let pos = Printf.sprintf "(%d, %d) to (%d, %d)" (loc.start).line (loc.start).column (loc._end).line (loc._end).column in source ^ pos[@@ocaml.doc "\n * This is mostly useful for debugging purposes.\n * Please don't dead-code delete this!\n "] let to_string_no_source loc = let line = (loc.start).line in let start = (loc.start).column + 1 in let end_ = (loc._end).column in if line <= 0 then "0:0" else if (line = (loc._end).line) && (start = end_) then Printf.sprintf "%d:%d" line start else if line != (loc._end).line then Printf.sprintf "%d:%d,%d:%d" line start (loc._end).line end_ else Printf.sprintf "%d:%d-%d" line start end_ let start_pos_to_string_for_vscode_loc_uri_fragment loc = let line = (loc.start).line in let start = (loc.start).column + 1 in let (line, start) = if line <= 0 then (0, 0) else (line, start) in Printf.sprintf "#L%d,%d" line start let mk_loc ?source (start_line, start_column) (end_line, end_column) = { source; start = { line = start_line; column = start_column }; _end = { line = end_line; column = end_column } } let source loc = loc.source let cursor source line column = { source; start = { line; column }; _end = { line; column } }[@@ocaml.doc " Produces a zero-width Loc.t, where start = end "] let start_loc loc = { loc with _end = (loc.start) } let end_loc loc = { loc with start = (loc._end) } let update_source f loc = { loc with source = (f loc.source) }
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>