Skip to content

Commit cd7dd7a

Browse files
committed
Compiler: do no rely on menhir lib
1 parent a734547 commit cd7dd7a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/lib-wasm/wat_preprocess.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Stdlib
33
exception Error of (Lexing.position * Lexing.position) * string
44

55
let report_error loc msg =
6-
let location = MenhirLib.LexerUtil.range loc in
6+
let location = Lexing.range_to_string loc in
77
Format.eprintf "%s%s%!" location msg;
88
exit 1
99

compiler/lib/stdlib.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,19 @@ module Hashtbl = struct
11881188
=
11891189
Hashtbl.of_seq
11901190
end
1191+
1192+
module Lexing = struct
1193+
include Lexing
1194+
1195+
let range_to_string (pos1, pos2) =
1196+
if phys_equal pos1 dummy_pos || phys_equal pos2 dummy_pos
1197+
then "At an unknown location:\n"
1198+
else
1199+
let file = pos1.pos_fname in
1200+
let line = pos1.pos_lnum in
1201+
let char1 = pos1.pos_cnum - pos1.pos_bol in
1202+
let char2 = pos2.pos_cnum - pos1.pos_bol in
1203+
(* yes, [pos1.pos_bol] *)
1204+
Printf.sprintf "File \"%s\", line %d, characters %d-%d:\n" file line char1 char2
1205+
(* use [char1 + 1] and [char2 + 1] if *not* using Caml mode *)
1206+
end

0 commit comments

Comments
 (0)