Ismaila FALL pushed to branch location-sinfo at Stefan / Typer
Commits:
5b74723c by “falismai(a)iro.umontreal.xn--ca-02t at 2022-05-31T22:18:07+00:00
Suppression du module Int
- - - - -
5 changed files:
- − Int
- src/debug.ml
- src/elab.ml
- src/eval.ml
- src/pexp.ml
Changes:
=====================================
Int deleted
=====================================
@@ -1,28 +0,0 @@
-btl/builtins.typer:Integer->Int = Built-in "Integer->Int" : Integer -> Int;
-btl/builtins.typer:Integer->String = Built-in "Integer->String" : Integer -> String;
-btl/pervasive.typer: | nil => (Integer->Int 0)
-btl/pervasive.typer: (Int_+ (Integer->Int 1) (List_length tl));
-btl/pervasive.typer: => case Int_<= n (Integer->Int 0)
-btl/pervasive.typer: | false => List_nth (Int_- n (Integer->Int 1)) xs d;
-btl/pervasive.typer: | cons x xs => cons (f x i) (helper f (Int_+ i (Integer->Int 1)) xs);
-btl/pervasive.typer:in helper f (Integer->Int 0) xs;
-btl/pervasive.typer:List_empty xs = Int_eq (List_length xs) (Integer->Int 0);
-btl/pervasive.typer: (cons (List_nth (Integer->Int 1) ss Sexp_error) nil)));
-btl/pervasive.typer: head = List_nth (Integer->Int 0) head-pair Sexp_error;
-btl/pervasive.typer: type-type = List_nth (Integer->Int 1) head-pair Sexp_error;
-btl/pervasive.typer: | vnil (p ::: Eq n (Integer->Int 0))
-btl/pervasive.typer: | vcons a (LList a ?n1) (p ::: Eq n (Int_+ ?n1 (Integer->Int 1)));
-btl/pervasive.typer: let e1 = List_nth (Integer->Int 0) args Sexp_error;
-btl/pervasive.typer: e2 = List_nth (Integer->Int 1) args Sexp_error;
-btl/pervasive.typer: e3 = List_nth (Integer->Int 2) args Sexp_error;
-btl/pervasive.typer:in case (Int_eq r (Integer->Int -1))
-btl/poly-lits.typer:IntFromInteger = mkFromInteger Integer->Int;
-btl/tuple.typer: elem-sym = Sexp_symbol (String_concat "%" (Integer->String n));
-samples/nats.typer:Integer->Nat : Integer -> Nat;
-samples/nats.typer:Integer->Nat i =
-samples/nats.typer: S (Integer->Nat (Integer_- i 1))
-samples/nats.typer:NatFromInteger = mkFromInteger Integer->Nat;
-src/eval.ml: let name = "Integer->Int" in
-src/eval.ml: | _ -> error loc "Integer->String expects one Integer argument"
-src/eval.ml: ("Integer->String", integer_to_string, 1);
-tests/eval_test.ml:intFromIntegerCoercion = mkCoercible (Integer->Int);
=====================================
src/debug.ml
=====================================
@@ -121,7 +121,8 @@ let debug_lexp_decls decls =
List.iter (fun e ->
let ((loc, _name), lxp, _ltp) = e in
- printf "%-15s[%s]" (lexp_name lxp) (Source.Location.to_string (sexp_location loc));
+ printf "%-15s[%s]" (lexp_name lxp) (Source.Location.to_string
+ (sexp_location loc));
let str = lexp_str_decls (!debug_ppctx) [e] in
=====================================
src/elab.ml
=====================================
@@ -1114,7 +1114,7 @@ and lexp_parse_inductive ctors ctx =
acc impossible in
let g = resolve_instances_and_generalize nctx altacc in
let altacc' = g (fun _ne vname t _l e
- -> mkArrow (lexp_sinfo altacc, Aerasable, vname, t, e))
+ -> mkArrow (lexp_sinfo e, Aerasable, vname, t, e))
altacc in
if altacc' == altacc
then acc (* No generalization! *)
@@ -1334,7 +1334,8 @@ and lexp_decls_1
(* FIXME: Move this to a "special form"! *)
-> (match args with
| [Symbol (loc, vname); stp]
- -> let ltp = infer_and_generalize_type nctx stp (Symbol(loc, ""), Some vname) in
+ -> let ltp = infer_and_generalize_type nctx stp (stp,
+ Some vname) in
if SMap.mem vname pending_decls then
(* Don't burp: take'em all and unify! *)
let pt_idx = senv_lookup vname nctx in
@@ -1355,7 +1356,7 @@ and lexp_decls_1
pending_defs then
(error ~loc {|Variable "%s" already defined!|} vname;
recur [] nctx pending_decls pending_defs)
- else recur [] (ectx_extend nctx (Symbol(loc, ""), Some vname) ForwardRef ltp)
+ else recur [] (ectx_extend nctx (stp, Some vname) ForwardRef ltp)
(SMap.add vname loc pending_decls)
pending_defs
| _
@@ -1367,13 +1368,13 @@ and lexp_decls_1
| Some (Node (Symbol (loc, "_=_") as head, args) as thesexp)
(* FIXME: Move this to a "special form"! *)
-> (match args with
- | [Symbol ((_l, vname)); sexp]
+ | [Symbol ((l, vname)); sexp]
when SMap.is_empty pending_decls
-> assert (pending_defs == []);
(* Used to be true before we added define-operator. *)
(* assert (ectx == nctx); *)
let (lexp, ltp) = infer_and_generalize_def nctx sexp in
- let var = (sexp, Some vname) in
+ let var = (epsilon (l), Some vname) in
(* Lexp decls are always recursive, so we have to shift by 1 to
* account for the extra var (ourselves). *)
[(var, mkSusp lexp (S.shift 1), ltp)], sdecls, toks,
=====================================
src/eval.ml
=====================================
@@ -717,7 +717,7 @@ and print_eval_trace trace =
print_trace " EVAL TRACE " trace a
let io_bind loc depth args_val =
- let trace_dum = (Var ((Symbol(loc, ""), None), -1)) in
+ let trace_dum = (Var ((epsilon loc, None), -1)) in
match args_val with
| [Vcommand cmd; callback]
=====================================
src/pexp.ml
=====================================
@@ -20,9 +20,6 @@ more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. *)
-(*
-*open Util
-*)
open Sexp (* Symbol *)
let pexp_error loc = Log.log_error ~section:"PEXP" ~loc
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/5b74723c05d49bbca4f84c67b6eaf384a…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/5b74723c05d49bbca4f84c67b6eaf384a…
You're receiving this email because of your account on gitlab.com.
Ismaila FALL pushed to branch location-sinfo at Stefan / Typer
Commits:
b638446c by “falismai(a)iro.umontreal.xn--ca-02t at 2022-05-31T22:03:08+00:00
Suppression du dossier idea
- - - - -
4 changed files:
- src/elab.ml
- src/lexp.ml
- src/opslexp.ml
- src/unification.ml
Changes:
=====================================
src/elab.ml
=====================================
@@ -176,7 +176,7 @@ let elab_check_proper_type (ctx : elab_context) ltp var =
let elab_check_def (ctx : elab_context) var lxp ltype =
let lctx = ectx_to_lctx ctx in
- let loc = sinfo_location lxp in
+ let loc = lexp_sinfo lxp in
let ltype' = try OL.check lctx lxp
with e -> match e with
@@ -652,7 +652,7 @@ and infer (p : sexp) (ctx : elab_context): lexp * ltype =
| (e, Inferred t) -> (e, t)
and elab_special_form ctx f args ot =
- let loc = sinfo_location f in
+ let loc = lexp_sinfo f in
match (OL.lexp'_whnf f (ectx_to_lctx ctx)) with
| Builtin ((_, name), _) ->
(* Special form. *)
@@ -663,7 +663,7 @@ and elab_special_form ctx f args ot =
sform_dummy_ret ctx loc
and elab_special_decl_form ctx f args =
- let loc = sinfo_location f in
+ let loc = lexp_sinfo f in
match (OL.lexp'_whnf f (ectx_to_lctx ctx)) with
| Builtin ((_, name), _) ->
(* Special form. *)
@@ -675,9 +675,9 @@ and instantiate_implicit e t ctx =
let rec instantiate t args =
match OL.lexp'_whnf t (ectx_to_lctx ctx) with
| Arrow (_, ((Aerasable | Aimplicit) as ak), (_, v), t1, t2)
- -> let arg = newInstanceMetavar ctx (sinfo_location e, v) t1 in
+ -> let arg = newInstanceMetavar ctx (lexp_sinfo e, v) t1 in
instantiate (mkSusp t2 (S.substitute arg)) ((ak, arg)::args)
- | _ -> (mkCall (sinfo_location e, e, List.rev args), t)
+ | _ -> (mkCall (lexp_sinfo e, e, List.rev args), t)
in instantiate t []
and resolve_instances e =
@@ -718,7 +718,7 @@ and infer_type pexp ectx (var: vname) =
| _ ->
(* FIXME: Here we rule out TypeLevel/TypeOmega.
* Maybe it's actually correct?! *)
- let l = sinfo_location s in
+ let l = lexp_sinfo s in
match
Unif.unify (mkSort (l, Stype (newMetalevel
(ectx_to_lctx ectx)
@@ -1006,7 +1006,7 @@ and elab_macro_call
(ot : ltype option)
: lexp * sform_type =
- let location = sinfo_location func in
+ let location = lexp_sinfo func in
let t =
match ot with
| None -> newMetatype (ectx_to_lctx ctx) (ectx_to_scope_level ctx) location
@@ -1029,7 +1029,7 @@ and elab_macro_call
(* Identify Call Type and return processed call. *)
and elab_call ctx (func, ltp) (sargs: sexp list) =
- let loc = sinfo_location func in
+ let loc = lexp_sinfo func in
let rec handle_fun_args largs sargs pending ltp =
let ltp' = OL.lexp_whnf ltp (ectx_to_lctx ctx) in
@@ -1114,7 +1114,7 @@ and lexp_parse_inductive ctors ctx =
acc impossible in
let g = resolve_instances_and_generalize nctx altacc in
let altacc' = g (fun _ne vname t _l e
- -> mkArrow (sinfo_location altacc, Aerasable, vname, t, e))
+ -> mkArrow (lexp_sinfo altacc, Aerasable, vname, t, e))
altacc in
if altacc' == altacc
then acc (* No generalization! *)
=====================================
src/lexp.ml
=====================================
@@ -516,30 +516,30 @@ let _ = assert (S.identity_p (scompose (S.shift 5) (sunshift 5)))
* S.sink (fun l i -> mkVar (l, i)) l s *)
-let rec sinfo_location s =
+let rec lexp_sinfo s =
match lexp_lexp' s with
| Sort (l,_) -> l
- | SortLevel (SLsucc s) -> sinfo_location s
- | SortLevel (SLlub (s, _)) -> sinfo_location s
+ | SortLevel (SLsucc s) -> lexp_sinfo s
+ | SortLevel (SLlub (s, _)) -> lexp_sinfo s
| SortLevel SLz -> dummy_sinfo
| Imm s -> s
| Var ((l,_),_) -> l
- | Builtin ((l, _), _) -> Symbol (l, "")
+ | Builtin ((l, _), _) -> epsilon l
| Let (l,_,_) -> l
| Arrow (l,_,_,_,_) -> l
| Lambda (_,(l,_),_,_) -> l
- | Call (_,f,_) -> sinfo_location f
+ | Call (_,f,_) -> lexp_sinfo f
| Inductive (l,_,_,_) -> l
- | Cons (_,(l,_)) -> Symbol (l, "")
+ | Cons (_,(l,_)) -> epsilon l
| Case (l,_,_,_,_) -> l
- | Susp (s, _) -> sinfo_location s
+ | Susp (s, _) -> lexp_sinfo s
(* | Susp (_, e) -> lexp_location e *)
| Metavar (_,_,(l,_)) -> l
| Proj (l,_,_) -> l
let lexp_location e =
- sexp_location (sinfo_location e)
+ sexp_location (lexp_sinfo e)
(********* Normalizing a term *********)
=====================================
src/opslexp.ml
=====================================
@@ -781,7 +781,7 @@ and check'' erased ctx e =
mkSort (l, Stype level)
| (ak, v, t)::args
-> let _k = check_type DB.set_empty ctx t in
- mkArrow (sinfo_location t, ak, v, t,
+ mkArrow (lexp_sinfo t, ak, v, t,
arg_loop (DB.lctx_extend ctx v Variable t)
(dbset_push ak erased)
args) in
@@ -937,7 +937,7 @@ and check'' erased ctx e =
mkCall (l, mkSusp t (S.shift nargs),
indtype fargs (nargs - 1))
| (ak, vd, ftype) :: ftypes
- -> mkArrow (sinfo_location ftype, ak, vd, ftype,
+ -> mkArrow (lexp_sinfo ftype, ak, vd, ftype,
fieldargs ftypes) in
let rec buildtype fargs =
match fargs with
@@ -1207,7 +1207,7 @@ and get_type ctx e =
cases (mkSortLevel SLz) in
mkSort (l, Stype level)
| (ak, v, t)::args
- -> mkArrow (sinfo_location t, ak, v, t,
+ -> mkArrow (lexp_sinfo t, ak, v, t,
arg_loop args (DB.lctx_extend ctx v Variable t)) in
let tct = arg_loop args ctx in
tct
@@ -1228,7 +1228,7 @@ and get_type ctx e =
mkCall (l, mkSusp t (S.shift nargs),
indtype fargs (nargs - 1))
| (ak, vd, ftype) :: ftypes
- -> mkArrow (sinfo_location ftype, ak, vd, ftype,
+ -> mkArrow (lexp_sinfo ftype, ak, vd, ftype,
fieldargs ftypes) in
let rec buildtype fargs =
match fargs with
=====================================
src/unification.ml
=====================================
@@ -146,7 +146,7 @@ let common_subset ctx s1 s2 =
&& OL.conv_p ctx (mkSusp le1 (S.shift o1)) (mkSusp le2 (S.shift o2))
then match loop s1' s2' o1 o2 1 with
| S.Identity 1 -> S.Identity o (* Optimization! *)
- | s' -> S.Cons (mkVar ((sinfo_location le1, None), 0),
+ | s' -> S.Cons (mkVar ((lexp_sinfo le1, None), 0),
s', o)
else loop s1' s2' o1 o2 (o + 1)
(* If one of them reached `Identity`, unroll it, knowing that
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/b638446cf2ce663e056c4c053c6334b8b…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/b638446cf2ce663e056c4c053c6334b8b…
You're receiving this email because of your account on gitlab.com.
Soilihi BEN SOILIHI BOINA pushed to branch minimal-server at Stefan / Typer
Commits:
8f23b347 by Soilih at 2022-05-24T14:42:30-04:00
fixing variable searching
- - - - -
3 changed files:
- src/lexp.ml
- + src/lsp_server_test.ml
- src/typer_lsp_server.ml
Changes:
=====================================
src/lexp.ml
=====================================
@@ -1068,7 +1068,7 @@ and lexp_str ctx (exp : lexp) : string =
let print_arg str (arg_type, lxp) =
match arg_type with
- | Aerasable when pp_erasable ctx -> str ^ " " ^ (lexp_str' lxp)
+ | Aerasable when pp_erasable ctx -> ""
| Aimplicit when pp_implicit ctx -> str ^ " " ^ (lexp_str' lxp)
| Anormal -> str ^ " " ^ (lexp_str' lxp)
| _ -> str in (
=====================================
src/lsp_server_test.ml
=====================================
@@ -0,0 +1,216 @@
+(*
+*
+*
+* HOVER
+*
+*
+**)
+
+let comp (a:string) (b:string) : string =
+ if (String.equal a b) then "/*******-----:-):-):-):-):-):-):-)__________SUCCESS_______:-):-):-):-):-):-):-)-----*******/\n\n\n"
+ else "/*******-----:-(:-(:-(:-(:-(:-(:-(____FAILED___:-(:-(:-(:-(:-(:-(:-(-----*******/\n\n\n"
+
+let hoverTest (ctx:Debruijn.lexp_context) (name:string) (content:string) (position: int * int) (expected:string) =
+let (_, ast,_) = Typer_lsp_server.compile_string content in
+let (list_list, _) = Option.get ast in
+let (l,c) = position in
+let pos = Typer_lsp_server.pos_of_tuple position in
+
+let (lctx,vx) = Typer_lsp_server.lexp_search ctx list_list pos in
+let ((lvn,_),lexp,ltyp) = vx in
+let (l_ctx_r,_,_,_,_,_) as ret = Typer_lsp_server.browse_lexp lctx lexp pos [] in
+let ret' = (l_ctx_r, None, ltyp, None, lvn,[]) in
+let (_,_,l_type,_,_,_) = Typer_lsp_server.browse_list_lexp [ret;ret'] pos in
+
+let excpect = "excpected : " ^ expected ^ "\n" in
+let output = "output : " ^ (Lexp.lexp_string_for_lsp l_type) ^ "\n\n" in
+let input = "input : " ^ content ^ "\n" in
+let res = "result : " ^ (comp expected (Lexp.lexp_string_for_lsp l_type)) in
+let pos = "position : line " ^ (string_of_int l) ^ " character " ^ (string_of_int c) ^ "\n" in
+let sep = "################################################\n" in
+let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 name in
+output_string oc (sep ^ input ^ pos ^ excpect ^ output ^ res ^ sep );
+close_out oc
+
+let sep name s =
+let content = "\n\n\n/*-----------------------------" ^ s ^ "-----------------------------------*/\n\n\n" in
+let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 name in
+output_string oc content;
+close_out oc
+
+
+let test_hover () =
+let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in
+let name = "/home/soilih/Bureau/test/test.txt" in
+sep name "INT";
+hoverTest ctx name "e = 12 ;" (1,1) "##Int";
+hoverTest ctx name "e = 12 ;" (1,5) "##Int";
+sep name "STRING";
+hoverTest ctx name "s = \"hejej\" ;" (1,1) "##String";
+hoverTest ctx name "s = \"hejej\" ;" (1,8) "##String";
+sep name "FLOAT";
+hoverTest ctx name "f = 12.3 ;" (1,1) "##Float";
+hoverTest ctx name "f = 12.3 ;" (1,6) "##Float";
+sep name "LAMBDA";
+hoverTest ctx name "l = (lambda x -> _+_ x 2) ;" (1,1) "(x : ##Int) -> Int";
+hoverTest ctx name "l = (lambda x -> _+_ x 2) ;" (1,8) "##Int";
+hoverTest ctx name "l = (lambda x -> _+_ x 2) ;" (1,13) "##Int";
+hoverTest ctx name "l = (lambda x y -> _+_ x y) ;" (1,23) "";
+hoverTest ctx name "l = (lambda x -> _+_ x 2) ;" (1,19) "(Int -> (Int -> Int))";
+hoverTest ctx name "l = (lambda x -> _+_ x 2) ;" (1,21) "##Int";
+hoverTest ctx name "l = (lambda x y -> x + y) ;" (1,20) "##Int";
+hoverTest ctx name "l = (lambda x y -> x + y) ;" (1,24) "##Int";
+hoverTest ctx name "l = (lambda x y -> _+_ x y) ;" (1,24) "##Int";
+hoverTest ctx name "l = (lambda x y -> _+_ x y) ;" (1,26) "##Int";
+sep name "FUNCTION(LAMBDA)";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,1) "(ℓ : ##TypeLevel) ≡> (τ : (##Type_ ℓ)) ≡> (x : ##Int) -> (y : ##Int) -> (z : τ) -> Int";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,10) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,12) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,14) "τ";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,18) "(Int -> (Int -> Int))";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,21) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ;" (1,23) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,1) "(x : ##Int) -> (y : ##Int) -> (z : ##Int) -> Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,10) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,12) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,14) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,18) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,20) "(Int -> (Int -> Int))";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,22) "##Int";
+hoverTest ctx name "multiply x y z = x + y + z ;" (1,26) "##Int";
+sep name "CALL";
+hoverTest ctx name "multiply x y z = _*_ x y ; \n\n\ne = multiply 2 3 \"h\" ;" (4,1) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ; \n\n\ne = multiply 2 3 \"h\" ;" (4,7) "(ℓ : ##TypeLevel) ≡> (τ : (##Type_ ℓ)) ≡> (x : ##Int) -> (y : ##Int) -> (z : τ) -> Int";
+hoverTest ctx name "multiply x y z = _*_ x y ; \n\n\ne = multiply 2 3 \"h\" ;" (4,13) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ; \n\n\ne = multiply 2 3 \"h\" ;" (4,15) "##Int";
+hoverTest ctx name "multiply x y z = _*_ x y ; \n\n\ne = multiply 2 3 \"h\" ;" (4,19) "##String";
+sep name "BUILTIN";
+hoverTest ctx name "foo = ##Int ;" (1,1) "##Type";
+hoverTest ctx name "foo = ##Int ;" (1,9) "##Type";
+sep name "SUSP";
+hoverTest ctx name "foo = ##Int ; \n\n\nv = foo ;" (4,1) "(##Type_ ##TypeLevel.z)";
+hoverTest ctx name "foo = ##Int ; \n\n\nv = foo ;" (4,6) "(##Type_ ##TypeLevel.z)";
+hoverTest ctx name "foo = ##String ; \n\n\nv = foo ;" (4,1) "(##Type_ (##TypeLevel.succ ##TypeLevel.z))";
+hoverTest ctx name "foo = ##Type ; \n\n\nv = foo ;" (4,1) "(##Type_ ##TypeLevel.z)";
+sep name "LIST";
+hoverTest ctx name "lst = cons 2 ( (cons 1 ) nil ) ;" (1,1) "(List ##TypeLevel.z ##Int)";
+hoverTest ctx name "lst = cons 2 ( (cons 1 ) nil ) ;" (1,8) "(ℓ : TypeLevel) ≡> (a : (##Type_ ℓ)) ≡> (a -> ((List ℓ a) -> (List ℓ a)))";
+hoverTest ctx name "lst = cons 2 ( (cons 1 ) nil ) ;" (1,12) "##Int";
+hoverTest ctx name "lst = cons 2 ( (cons 1 ) nil ) ;" (1,27) "(ℓ : TypeLevel) ≡> (a : (##Type_ ℓ)) ≡> (List ℓ a)";
+sep name "TUPLE";
+hoverTest ctx name "lst = cons 2 ( (cons 1 ) nil ) ; \n\n\ntup = (1,2,\"str\",lst) ;" (4,1) "typecons (Tuple) (cons ##Int ##Int ##String (List ##TypeLevel.z ##Int))";
+hoverTest ctx name "tup = (1,2,\"str\",false) ;" (1,8) "##Int";
+hoverTest ctx name "tup = (1,2,\"str\",false) ;" (1,10) "##Int";
+hoverTest ctx name "tup = (1,2,\"str\",false) ;" (1,15) "##String";
+hoverTest ctx name "tup = (1,2,\"str\",false) ;" (1,21) "Bool";
+sep name "ARROW";
+hoverTest ctx name "type Floo = bar Int Int ;" (1,1) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (4,17) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (4,29) "";
+hoverTest ctx name "v = Int -> Int ;" (1,1) "";
+sep name "INDUCTIVE";
+hoverTest ctx name "type Floo = bar Int Int ;" (1,7) "";
+hoverTest ctx name "type Floo = bar Int Int ;" (1,18) "";
+hoverTest ctx name "type Floo = bar Int Int ;" (1,22) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (1,1) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (1,19) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (1,26) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (4,1) "";
+hoverTest ctx name "floo = typecons (floo) (bar Int Int) ;\n\n\nbar = datacons floo bar ;" (4,10) "";
+hoverTest ctx name "Bool = typecons (Bool) (true) (false);" (1,1) "";
+hoverTest ctx name "Bool = typecons (Bool) (true) (false);" (1,10) "";
+hoverTest ctx name "Bool = typecons (Bool) (true) (false);" (1,18) "";
+hoverTest ctx name "Bool = typecons (Bool) (true) (false);" (1,24) "";
+hoverTest ctx name "Bool = typecons (Bool) (true) (false);" (1,32) "";
+sep name "METAVAR";
+hoverTest ctx name "x : ?t = 3 ;" (1,1) "";
+hoverTest ctx name "x : ?t = 3 ;" (1,6) "";
+hoverTest ctx name "f x = _+_ ?y x ;" (1,1) "";
+hoverTest ctx name "f x = _+_ ?y x ;" (1,3) "";
+hoverTest ctx name "f x = _+_ ?y x ;" (1,12) "";
+hoverTest ctx name "f x = _+_ ?y x ;" (1,14) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (1,1) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (1,6) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (1,10) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (4,1) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (4,11) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (4,15) "";
+hoverTest ctx name "x : ?t ; x = 3 ;\n\n\nfoo = let x : ?t = 3 in x;" (4,24) "";
+sep name "LET";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,1) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,10) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,18) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,26) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,35) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,37) "";
+hoverTest ctx name "bar = let x = 1 ; y = 2 ; z = 6 in x + y + z ;" (1,41) "";
+sep name "CASE";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (1,1) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (1,5) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (1,14) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (3,4) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (3,13) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (5,4) "";
+hoverTest ctx name "foo x = case x\n\n| true => \"true\"\n\n| false => \"false\" ;" (5,14) ""
+
+
+(*
+*
+*
+* AFFICHER LA LISTE DE LISTE
+*
+*
+**)
+
+let afficher_lst code filename =
+ let ch = open_in code in
+ let content = really_input_string ch (in_channel_length ch) in
+ close_in ch;
+ let (_,ast,_) = Typer_lsp_server.compile_string content in
+ let (list_list, _) = Option.get ast in
+ List.iteri (fun i x ->
+ let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 filename in
+ output_string oc ("\n\n---------------liste: " ^ (string_of_int i) ^ " --------------\n\n");
+ close_out oc;
+ List.iteri (fun _j (y : Util.vname * Lexp.lexp * Lexp.ltype)->
+ let (vn,_,_) = y in
+ let (l,ss) = vn in
+ let s = try Option.get ss
+ with _ -> failwith "The Var doesn't have a string!"
+ in
+ let output = "Var: " ^ s ^ "\nline: " ^ (string_of_int l.start_line) ^ " - " ^
+ (string_of_int l.end_line) ^ "\ncolumn: " ^ (string_of_int l.start_column) ^ " - "
+ ^ (string_of_int l.end_column) ^ "\n\n"
+ in
+ let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 filename in
+ output_string oc output;
+ close_out oc;
+ ) x
+ ) list_list
+
+(*
+*
+*
+* BREADCRUMBS
+*
+*
+**)
+let testerBread cursor str =
+ let (_,ast,_) = Typer_lsp_server.compile_string str in
+ let (list_list, _) = Option.get ast in
+ let typer_loc = Typer_lsp_server.pos_of_tuple cursor in
+ let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in
+ let lexp = Typer_lsp_server.trans_list_in_list_to_let list_list in
+ let (_,_,_,_,_,lst) = Typer_lsp_server.browse_lexp ctx lexp typer_loc [] in
+ let str = List.fold_left (
+ fun str x ->
+ let (_,st) = x in
+ (Option.get st) ^ " > " ^ str
+ ) "" lst in
+ let name = "/home/soilih/Bureau/test/symbol.txt" in
+ let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 name in
+ output_string oc ("bread: " ^ str ^ "\n")
+
+let bread_test =
+ afficher_lst "/home/soilih/Bureau/exemple.typer" "/home/soilih/Bureau/test/highlight.txt";
+ testerBread (2,2) "multiply _x = \nlet lst = cons 2 nil in\nlst"
\ No newline at end of file
=====================================
src/typer_lsp_server.ml
=====================================
@@ -729,15 +729,15 @@ let rec str_order (substr:string) (str:string) : bool =
(* Filter completions list by a string *)
let complete_oth (str:string) (liste: Lsp.Types.CompletionItem.t list) =
-match liste with
-| [] -> liste
-| _ -> let lst = List.filter (fun (x:Lsp.Types.CompletionItem.t) ->
- string_contain str x.label
- ) liste
- in
- List.filter (fun (x:Lsp.Types.CompletionItem.t) ->
- str_order str x.label
- ) lst
+ match liste with
+ | [] -> liste
+ | _ -> let lst = List.filter (fun (x:Lsp.Types.CompletionItem.t) ->
+ string_contain str x.label
+ ) liste
+ in
+ List.filter (fun (x:Lsp.Types.CompletionItem.t) ->
+ str_order str x.label
+ ) lst
@@ -746,21 +746,21 @@ let sep_list = [';';',';'(';')';' ';'{';'}']
let split_string_line (content:string) (line:int) =
-let str_list = String.split_on_char '\n' content in
-List.nth str_list (line - 1)
+ let str_list = String.split_on_char '\n' content in
+ List.nth str_list (line - 1)
(* Find the word in which the cursor is *)
let rec search_word_in_cursor (str:string) (char_list:char list) (pos:int) (ret:string) : string =
-if (String.equal str "") then ""
-else if (Int.equal pos 0) then String.make 1 str.[pos] ^ ret
-else if (List.exists (fun x -> Char.equal x str.[pos]) char_list) then ret
-else search_word_in_cursor str char_list (pos - 1) ((String.make 1 str.[pos]) ^ ret)
+ if (String.equal str "") then ""
+ else if (Int.equal pos 0) then String.make 1 str.[pos] ^ ret
+ else if (List.exists (fun x -> Char.equal x str.[pos]) char_list) then ret
+ else search_word_in_cursor str char_list (pos - 1) ((String.make 1 str.[pos]) ^ ret)
let use_search_word (str:string) (char_list:char list) (pos:int) (ret:string) : string =
-match pos with
-| 0 -> search_word_in_cursor str char_list pos ret
-| _ -> search_word_in_cursor str char_list (pos - 1) ret
+ match pos with
+ | 0 -> search_word_in_cursor str char_list pos ret
+ | _ -> search_word_in_cursor str char_list (pos - 1) ret
@@ -920,7 +920,7 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) =
| Var _ -> None
| Susp (e, s) -> browse_defs (Lexp.push_susp e s) cursor
| Let (_, defs, el)
- -> let idx = (List.length defs) - 1 in
+ -> (let idx = (List.length defs) - 1 in
let rec foo (ctx_list: (vname * Lexp.lexp * Lexp.lexp) list) cursor comp =
match ctx_list with
| [] -> failwith "No Variable on the cursor"
@@ -929,8 +929,29 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) =
else foo tl cursor (comp + 1)
| _::tl -> foo tl cursor (comp + 1)
in
- foo defs cursor 0
-
+ let rec foo'' (ctx_list: (vname * Lexp.lexp * Lexp.lexp) list) cursor comp =
+ match ctx_list with
+ | [] -> failwith "No variable found on the cursor!"
+ | (_, _, ltp)::tl
+ -> if (not ((browse_defs lxp cursor) = None)) then
+ browse_defs ltp cursor
+ else foo'' tl cursor (comp + 1)
+ in
+ let rec foo' (ctx_list: (vname * Lexp.lexp * Lexp.lexp) list) cursor comp =
+ match ctx_list with
+ | [] -> foo'' ctx_list cursor comp
+ | (_, lxp, _)::tl
+ -> if (not ((browse_defs lxp cursor) = None)) then
+ browse_defs lxp cursor
+ else foo' tl cursor (comp + 1)
+ in
+ try foo defs cursor 0
+ with _
+ -> if (not ((browse_defs el cursor) = None)) then
+ browse_defs el cursor
+ else foo' defs cursor 0
+ )
+
| Arrow (_, v, t1, _, t2)
-> if (vn_on_the_cursor v cursor) then
Some (t2, v, 0)
@@ -941,7 +962,10 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) =
| Lambda (_, v, t, e) -> (*let ctx' = Debruijn.lctx_extend ctx v Variable t in*)
if (vn_on_the_cursor v cursor) then Some (e, v, 0)
- else browse_defs t cursor
+ else (if not ((browse_defs e cursor) = None) then
+ browse_defs e cursor
+ else browse_defs t cursor
+ )
| Call (f, args) -> if not ((browse_defs f cursor) = None) then
browse_defs f cursor
@@ -1361,56 +1385,11 @@ class lsp_server =
end
-
-let afficher_lst code filename =
- let ch = open_in code in
- let content = really_input_string ch (in_channel_length ch) in
- close_in ch;
- let (_,ast,_) = compile_string content in
- let (list_list, _) = Option.get ast in
- List.iteri (fun i x ->
- let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 filename in
- output_string oc ("\n\n---------------liste: " ^ (string_of_int i) ^ " --------------\n\n");
- close_out oc;
- List.iteri (fun _j (y : vname * Lexp.lexp * Lexp.ltype)->
- let (vn,_,_) = y in
- let (l,ss) = vn in
- let s = try Option.get ss
- with _ -> failwith "The Var doesn't have a string!"
- in
- let output = "Var: " ^ s ^ "\nline: " ^ (string_of_int l.start_line) ^ " - " ^
- (string_of_int l.end_line) ^ "\ncolumn: " ^ (string_of_int l.start_column) ^ " - "
- ^ (string_of_int l.end_column) ^ "\n\n"
- in
- let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 filename in
- output_string oc output;
- close_out oc;
- ) x
- ) list_list
-
-let testerBread cursor str =
- let (_,ast,_) = compile_string str in
- let (list_list, _) = Option.get ast in
- let typer_loc = pos_of_tuple cursor in
- let ctx = Debruijn.ectx_to_lctx (Elab.default_ectx) in
- let lexp = trans_list_in_list_to_let list_list in
- let (_,_,_,_,_,lst) = browse_lexp ctx lexp typer_loc [] in
- let str = List.fold_left (
- fun str x ->
- let (_,st) = x in
- (Option.get st) ^ " > " ^ str
- ) "" lst in
- let name = "/home/soilih/Bureau/test/symbol.txt" in
- let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 name in
- output_string oc ("bread: " ^ str ^ "\n")
-
(* Main code
This is the code that creates an instance of the lsp server class
and runs it as a task. *)
let run () =
ignore (Arg.Set Log.lsp_enabled);
- afficher_lst "/home/soilih/Bureau/exemple.typer" "/home/soilih/Bureau/test/highlight.txt";
- testerBread (2,2) "multiply _x = \nlet lst = cons 2 nil in\nlst";
let s = new lsp_server in
let server = Linol_lwt.Jsonrpc2.create_stdio s in
let task = Linol_lwt.Jsonrpc2.run server in
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/8f23b3470dcd115470055142bcb399b8e…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/8f23b3470dcd115470055142bcb399b8e…
You're receiving this email because of your account on gitlab.com.