Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed parse method in TLAPM API #147

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lsp/lib/parser/parser.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
let module_of_string ~content ~filename ~loader_paths =
Tlapm_lib.module_of_string ~content ~filename ~loader_paths
~prefer_stdlib:true
match
Tlapm_lib.modctx_of_string ~content ~filename ~loader_paths
~prefer_stdlib:true
with
| Ok (_mcx, mule) -> Ok mule
| Error err -> Error err
18 changes: 14 additions & 4 deletions src/tlapm_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ let init () =
exit 3

(* Access to this function has to be synchronized. *)
let module_of_string ~(content : string) ~(filename : string) ~loader_paths ~prefer_stdlib : (Module.T.mule, (string option* string)) result =
let modctx_of_string ~(content : string) ~(filename : string) ~loader_paths ~prefer_stdlib : (modctx * Module.T.mule, string option * string) result =
let parse_it () =
Errors.reset ();
Params.prefer_stdlib := prefer_stdlib;
Expand All @@ -637,11 +637,11 @@ let module_of_string ~(content : string) ~(filename : string) ~loader_paths ~pre
| false -> (mcx, found)
) (mcx, None) mods in
match mule with
| Some mule -> Ok mule
| None -> failwith "module_of_string, found no module we tried to parse."
| Some mule -> Ok (mcx, mule)
| None -> failwith "modctx_of_string, found no module we tried to parse."
in
match parse_it () with
| Ok mule -> Ok mule
| Ok (mcx, mule) -> Ok (mcx, mule)
| Error e -> Error e
| exception e ->
(match !Errors.loc, !Errors.msg with
Expand All @@ -650,4 +650,14 @@ let module_of_string ~(content : string) ~(filename : string) ~loader_paths ~pre
| Some l, None -> Error (Some l, Printexc.to_string e)
| None, None -> Error (None, Printexc.to_string e))

let module_of_string module_str =
let hparse = Tla_parser.P.use M_parser.parse in
let (flex, _) = Alexer.lex_string module_str in
Tla_parser.P.run hparse ~init:Tla_parser.init ~source:flex

let stdlib_search_paths = Params.stdlib_search_paths

let parse_module_of_string module_str =
kape1395 marked this conversation as resolved.
Show resolved Hide resolved
let hparse = Tla_parser.P.use M_parser.parse in
let (flex, _) = Alexer.lex_string module_str in
Tla_parser.P.run hparse ~init:Tla_parser.init ~source:flex
15 changes: 12 additions & 3 deletions src/tlapm_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ module Backend = Backend
val main : string list -> unit
val init : unit -> unit

val module_of_string :
val modctx_of_string :
content:string ->
filename:string ->
loader_paths:string list ->
prefer_stdlib:bool ->
(Module.T.mule, string option * string) result
(** Parse module from a specified string, assume it is located in the specified path. *)
(Module.T.modctx * Module.T.mule, string option * string) result
(** Parse and elaborate the specified module and its context
from a specified string, assume it is located in the
specified path. *)

val module_of_string : string -> M_t.mule option
(** Parse the specified string as a module. No dependencies
are considered, nor proof obligations are elaborated. *)

val parse_module_of_string: string -> M_t.mule option
(** Parse module from given string without pulling in dependencies. *)

val stdlib_search_paths : string list
(** A list of paths to look for stdlib modules. *)