You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
942 B

module type S = sig
val get_mem_new_line : unit -> int list
val unexpected_char : char -> unit
val incr_offset_string : string -> unit
val new_line_met : unit -> unit
val incr_offset : int -> unit
end
module Make () : S = struct
let curr_line = ref 1
let curr_offset = ref 1
let total_offset = ref 1
let mem_new_line = ref []
let get_mem_new_line () = List.rev !mem_new_line
let new_line_met () =
incr total_offset ;
mem_new_line := !total_offset :: !mem_new_line ;
incr curr_line ;
curr_offset := 0
let incr_offset x =
total_offset := !total_offset + x ;
curr_offset := !curr_offset + x
let incr_offset_string x = incr_offset (String.length x)
let fail msg =
Utils.failwith
(Format.sprintf "lexer: line %d, at offset %d: %s" !curr_line !curr_offset
msg)
let unexpected_char c =
fail (Format.sprintf "unexpected character: '%s'" (Char.escaped c))
end