1+ (* Copyright (C) 2020 - Authors of BuckleScript
2+ *
3+ * This program is free software: you can redistribute it and/or modify
4+ * it under the terms of the GNU Lesser General Public License as published by
5+ * the Free Software Foundation, either version 3 of the License, or
6+ * (at your option) any later version.
7+ *
8+ * In addition to the permissions granted to you by the LGPL, you may combine
9+ * or link a "work that uses the Library" with a publicly distributed version
10+ * of this file to produce a combined library or application, then distribute
11+ * that combined work under the terms of your choosing, with no requirement
12+ * to comply with the obligations normally placed on you by section 4 of the
13+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
14+ * should you choose to use a later version).
15+ *
16+ * This program is distributed in the hope that it will be useful,
17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+ * GNU Lesser General Public License for more details.
20+ *
21+ * You should have received a copy of the GNU Lesser General Public License
22+ * along with this program; if not, write to the Free Software
23+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+ let offset_pos
27+ ({pos_lnum; pos_bol; pos_cnum} as loc : Lexing.position )
28+ ({line; column} : Loc.position )
29+ first_line_offset : Lexing.position =
30+ if line = 1 then
31+ {loc with pos_cnum = pos_cnum + column + first_line_offset }
32+ else {
33+ loc with
34+ pos_lnum = pos_lnum + line - 1 ;
35+ pos_cnum = pos_bol + column
36+ }
37+
38+
39+ let flow_deli_offset deli =
40+ (match deli with
41+ | None -> 1 (* length of '"'*)
42+ | Some deli ->
43+ String. length deli + 2 (* length of "{|"*)
44+ )
45+
46+ ;;
47+
48+
49+ (* Here the loc is the payload loc *)
50+ let check_flow_errors ~(loc : Location.t )
51+ ~offset
52+ (errors : (Loc.t * Parse_error.t) list ) =
53+ match errors with
54+ | [] -> ()
55+ | ({start ;
56+ _end },first_error) :: _ ->
57+ let loc_start = loc.loc_start in
58+ Location. raise_errorf
59+ ~loc: {loc with
60+ loc_start = offset_pos loc_start start
61+ offset ;
62+ loc_end = offset_pos loc_start _end
63+ offset } " %s"
64+ (Parse_error.PP. error first_error)
0 commit comments