123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)moduleSedlexing=Flow_sedlexing(* bol = Beginning Of Line *)typebol={line:int;offset:int;}typelex_state={lex_errors_acc:(Loc.t*Parse_error.t)list}[@@ocaml.unboxed]typet={lex_source:File_key.toption;lex_lb:Sedlexing.lexbuf;lex_bol:bol;lex_in_comment_syntax:bool;lex_enable_comment_syntax:bool;lex_state:lex_state;lex_last_loc:Loc.t;}letempty_lex_state={lex_errors_acc=[]}(* The lex_last_loc should initially be set to the beginning of the first line, so that
comments on the first line are reported as not being on a new line. *)letinitial_last_loc={Loc.source=None;start={Loc.line=1;column=0};_end={Loc.line=1;column=0}}letnew_lex_envlex_sourcelex_lb~enable_types_in_comments={lex_source;lex_lb;lex_bol={line=1;offset=0};lex_in_comment_syntax=false;lex_enable_comment_syntax=enable_types_in_comments;lex_state=empty_lex_state;lex_last_loc=initial_last_loc;}(* copy all the mutable things so that we have a distinct lexing environment
that does not interfere with ordinary lexer operations *)letcloneenv=letlex_lb=Sedlexing.lexbuf_cloneenv.lex_lbin{envwithlex_lb}letlexbufenv=env.lex_lbletsourceenv=env.lex_sourceletstateenv=env.lex_stateletlineenv=env.lex_bol.lineletbol_offsetenv=env.lex_bol.offsetletis_in_comment_syntaxenv=env.lex_in_comment_syntaxletis_comment_syntax_enabledenv=env.lex_enable_comment_syntaxletin_comment_syntaxis_inenv=ifis_in<>env.lex_in_comment_syntaxthen{envwithlex_in_comment_syntax=is_in}elseenv(* TODO *)letdebug_string_of_lexbuf_lb=""letdebug_string_of_lex_env(env:t)=letsource=matchsourceenvwith|None->"None"|Somex->Printf.sprintf"Some %S"(File_key.to_stringx)inPrintf.sprintf"{\n lex_source = %s\n lex_lb = %s\n lex_in_comment_syntax = %b\n lex_enable_comment_syntax = %b\n lex_state = {errors = (count = %d)}\n}"source(debug_string_of_lexbufenv.lex_lb)(is_in_comment_syntaxenv)(is_comment_syntax_enabledenv)(List.length(stateenv).lex_errors_acc)