2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
10 (* Note: While Pos.string prints out positions as closed intervals, pos_start
11 * and pos_end actually form a half-open interval (i.e. pos_end points to the
12 * character *after* the last character of the relevant lexeme.) *)
13 type 'a pos
[@@deriving eq
, ord
, show
]
15 (** The underlying type used to construct Pos instances.
17 * See "val make: 'a -> b -> 'a pos" *)
20 type t
= Relative_path.t pos
[@@deriving eq
]
22 val pp
: Format.formatter
-> t
-> unit
24 type absolute
= string pos
[@@deriving eq
, ord
, show
]
28 val filename
: 'a pos
-> 'a
30 val start_offset
: 'a pos
-> int
32 val end_offset
: 'a pos
-> int
34 val line
: 'a pos
-> int
36 val line_column
: 'a pos
-> int * int
38 val end_line
: 'a pos
-> int
40 val end_line_column
: 'a pos
-> int * int
42 (** Return line number, beginning of line character number and character number of start position. *)
43 val line_beg_offset
: t
-> int * int * int
45 val end_line_beg_offset
: t
-> int * int * int
47 (** For spans over just one line, return the line number, start column and end column.
48 This returns a closed interval.
49 Undefined for multi-line spans. *)
50 val info_pos
: 'a pos
-> int * int * int
52 (** Return start line, end line, start column and end column.
53 This returns a closed interval. *)
54 val info_pos_extended
: 'a pos
-> int * int * int * int
56 (** Return start character number and end character number. *)
57 val info_raw
: 'a pos
-> int * int
59 (** Return start line, start column, end line and end column.
60 This returns a half-open interval. *)
61 val destruct_range
: 'a pos
-> int * int * int * int
63 val length
: 'a pos
-> int
65 (* This returns a closed interval. *)
66 val string : absolute
-> string
68 (* This returns a half-open interval. *)
69 val multiline_string
: absolute
-> string
71 (* This returns a closed interval. *)
72 val string_no_file
: 'a pos
-> string
74 (* This returns a half-open interval. *)
75 val multiline_string_no_file
: 'a pos
-> string
77 (* This returns a closed interval. *)
78 val json
: absolute
-> Hh_json.json
80 val json_no_filename
: absolute
-> Hh_json.json
82 (* This returns a half-open interval. *)
83 val multiline_json
: absolute
-> Hh_json.json
85 val multiline_json_no_filename
: 'a pos
-> Hh_json.json
87 val inside
: 'a pos
-> int -> int -> bool
89 val exactly_matches_range
:
97 val contains
: t
-> t
-> bool
99 (* Does first position strictly overlap the second position? *)
100 val overlaps
: t
-> t
-> bool
102 val make
: 'a
-> b
-> 'a pos
104 val make_from_lexing_pos
: 'a
-> Lexing.position
-> Lexing.position
-> 'a pos
106 val make_from
: 'a
-> 'a pos
108 val btw_nocheck
: 'a pos
-> 'a pos
-> 'a pos
110 val is_hhi
: t
-> bool
112 (** Fill in the gap "between" first position and second position.
113 Not valid if from different files or second position precedes first *)
114 val btw
: t
-> t
-> t
116 (* Symmetric version of above: order doesn't matter *)
117 val merge
: 'a pos
-> 'a pos
-> 'a pos
119 val last_char
: t
-> t
121 val first_char_of_line
: t
-> t
123 val to_absolute
: t
-> absolute
125 val to_relative
: absolute
-> t
127 val to_relative_string
: t
-> string pos
129 val get_text_from_pos
: content
:string -> 'a pos
-> string
131 (* Advance the ending position by one character *)
132 val advance_one
: 'a pos
-> 'a pos
134 (* Reduce the size of this position element by one character on the left and
135 * one character on the right. For example, if you've captured a position
136 * that includes outside apostrophes, this will shrink it to only the contents
137 * within the apostrophes. *)
138 val shrink_by_one_char_both_sides
: 'a pos
-> 'a pos
140 (* Compare by filename, then tie-break by start position, and finally by the
142 val compare
: t
-> t
-> int
144 val set_file
: 'a
-> 'b pos
-> 'a pos
146 (* Return a zero-width position that occurs at the start of input position. *)
147 val shrink_to_start
: 'a pos
-> 'a pos
149 val set_col_start
: int -> 'a pos
-> 'a pos
151 val set_col_end
: int -> 'a pos
-> 'a pos
153 val make_from_lnum_bol_offset
:
154 pos_file
:Relative_path.t
->
155 pos_start
:int * int * int ->
156 pos_end
:int * int * int ->
159 module Map
: WrappedMap.S
with type key
= t
161 module AbsolutePosMap
: WrappedMap.S
with type key
= absolute
163 module Set
: Set.S
with type elt
= t
165 val print_verbose_absolute
: absolute
-> string
167 val print_verbose_relative
: t
-> string
169 val pessimize_enabled
: t
-> float -> bool
171 val set_from_reason
: 'a pos
-> 'a pos
173 val get_from_reason
: 'a pos
-> bool