From 952f97a46062bb3315d3ae20ecbfd58747019c25 Mon Sep 17 00:00:00 2001 From: ZAN DoYe Date: Fri, 8 May 2020 14:54:32 +0800 Subject: [PATCH] compatible with 4.11 * use the exposed parser to parse longident --- CHANGES.md | 6 ++++++ src/lib/uTop_complete.ml | 10 +++++++++- src/lib/uTop_main.ml | 10 +++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c8fcf1b..3a9da85 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +next +------------------ + +* compatible with OCaml 4.11 +* switch to the exposed parser + 2.5.0 (2020-04-26) ------------------ diff --git a/src/lib/uTop_complete.ml b/src/lib/uTop_complete.ml index 53df4d5..2224386 100644 --- a/src/lib/uTop_complete.ml +++ b/src/lib/uTop_complete.ml @@ -892,6 +892,14 @@ and find_context_in_quotation = function | Completion | +-----------------------------------------------------------------+ *) +#if OCAML_VERSION < (4, 11, 0) +let longident_parse= Longident.parse +#else +let longident_parse str= + let lexbuf= Lexing.from_string str in + Parse.longident lexbuf +#endif + let complete ~phrase_terminator ~input = let true_name, false_name = ("true", "false") in let tokens = UTop_lexer.lex_string input in @@ -924,7 +932,7 @@ let complete ~phrase_terminator ~input = | [(Symbol "#", _); (Lident "typeof", _); (String (tlen, false), loc)] -> let prefix = String.sub input (loc.ofs1 + tlen) (String.length input - loc.ofs1 - tlen) in - begin match Longident.parse prefix [@ocaml.warning "-3"] with + begin match longident_parse prefix with | Longident.Ldot (lident, last_prefix) -> let set = names_of_module lident in let compls = lookup last_prefix (String_set.elements set) in diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index 445808c..4f7e246 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -437,6 +437,14 @@ type rewrite_rule = { (* Whether the rule is enabled or not. *) } +#if OCAML_VERSION < (4, 11, 0) +let longident_parse= Longident.parse +#else +let longident_parse str= + let lexbuf= Lexing.from_string str in + Parse.longident lexbuf +#endif + let longident_lwt_main_run = Longident.Ldot (Longident.Lident "Lwt_main", "run") let longident_async_thread_safe_block_on_async_exn = Longident.(Ldot (Ldot (Lident "Async", "Thread_safe"), "block_on_async_exn")) @@ -1182,7 +1190,7 @@ end +-----------------------------------------------------------------+ *) let typeof sid = - let id = Longident.parse sid [@ocaml.warning "-3"] in + let id = longident_parse sid in let env = !Toploop.toplevel_env in #if OCAML_VERSION >= (4, 10, 0) let lookup_value= Env.find_value_by_name