Skip to content

Commit

Permalink
Merge pull request #147 from ahelwer/expose-parser
Browse files Browse the repository at this point in the history
Exposed parse method in TLAPM API
  • Loading branch information
kape1395 authored Sep 11, 2024
2 parents ee9ecc6 + 4382beb commit d8ade9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
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
13 changes: 9 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,9 @@ 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
12 changes: 9 additions & 3 deletions src/tlapm_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ 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 stdlib_search_paths : string list
(** A list of paths to look for stdlib modules. *)

0 comments on commit d8ade9a

Please sign in to comment.