diff options
| author | msozeau | 2008-05-12 12:27:25 +0000 |
|---|---|---|
| committer | msozeau | 2008-05-12 12:27:25 +0000 |
| commit | 7248f6cccfcca2b0d59b244e8789590794aefc45 (patch) | |
| tree | 8979753245e2ff2ef183d37ba324f64c90b5d337 /parsing | |
| parent | bba897d5fd964bef0aa10102ef41cee1ac5fc3bb (diff) | |
- Add -unicode flag to coqtop (sets Flags.unicode_syntax). Used to
change the default pretty-printing to use Π, λ instead of
forall and fun (and allow "," as well as "=>" for "fun" to be more
consistent with the standard forall and exists syntax). Parsing allows
theses new forms too, even if not in -unicode, and does not make Î or
λ keywords. As usual, criticism and suggestions are welcome :)
Not sure what to do about "->"/"→" ?
- [setoid_replace by] now uses tactic3() to get the right parsing level
for tactics.
- Type class [Instance] names are now mandatory.
- Document [rewrite at/by] and fix parsing of occs to support their
combination.
- Backtrack on [Enriching] modifier, now used exclusively in the
implementation of implicit arguments.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@10921 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'parsing')
| -rw-r--r-- | parsing/g_constr.ml4 | 14 | ||||
| -rw-r--r-- | parsing/g_tactic.ml4 | 3 | ||||
| -rw-r--r-- | parsing/g_vernac.ml4 | 38 | ||||
| -rw-r--r-- | parsing/ppconstr.ml | 27 | ||||
| -rw-r--r-- | parsing/ppvernac.ml | 8 |
5 files changed, 50 insertions, 40 deletions
diff --git a/parsing/g_constr.ml4 b/parsing/g_constr.ml4 index 25a7d0b698..b4bac06e83 100644 --- a/parsing/g_constr.ml4 +++ b/parsing/g_constr.ml4 @@ -205,10 +205,20 @@ GEXTEND Gram CNotation(loc,"( _ )",[c]) | _ -> c) ] ] ; + forall: + [ [ "forall" -> () + | IDENT "Î " -> () + ] ] + ; + lambda: + [ [ "fun" -> () + | IDENT "λ" -> () + ] ] + ; binder_constr: - [ [ "forall"; bl = binder_list; ","; c = operconstr LEVEL "200" -> + [ [ forall; bl = binder_list; ","; c = operconstr LEVEL "200" -> mkCProdN loc bl c - | "fun"; bl = binder_list; "=>"; c = operconstr LEVEL "200" -> + | lambda; bl = binder_list; [ "=>" | "," ]; c = operconstr LEVEL "200" -> mkCLambdaN loc bl c | "let"; id=name; bl = binders_let; ty = type_cstr; ":="; c1 = operconstr LEVEL "200"; "in"; c2 = operconstr LEVEL "200" -> diff --git a/parsing/g_tactic.ml4 b/parsing/g_tactic.ml4 index d59a46d125..5cd1732925 100644 --- a/parsing/g_tactic.ml4 +++ b/parsing/g_tactic.ml4 @@ -205,7 +205,8 @@ GEXTEND Gram | s = ne_string -> ByNotation (loc,s) ] ] ; occs: - [ [ "at"; nl = LIST1 int_or_var -> nl + [ [ "at"; nl = LIST1 integer -> List.map (fun x -> Rawterm.ArgArg x) nl + | "at"; id = identref -> [Rawterm.ArgVar id] | -> [] ] ] ; pattern_occ: diff --git a/parsing/g_vernac.ml4 b/parsing/g_vernac.ml4 index 4eafbd68c7..2efe88c0c3 100644 --- a/parsing/g_vernac.ml4 +++ b/parsing/g_vernac.ml4 @@ -495,49 +495,39 @@ GEXTEND Gram VernacContext c | global = [ IDENT "Global" -> true | -> false ]; - IDENT "Instance"; name = OPT identref; sup = OPT [ l = binders_let -> l ]; -(* name' = OPT [ "=>"; id = identref -> id ]; *) - ":" ; expl = [ "!" -> Rawterm.Implicit | -> Rawterm.Explicit ] ; t = operconstr LEVEL "200"; + IDENT "Instance"; name = identref; sup = OPT binders_let; ":"; + expl = [ "!" -> Rawterm.Implicit | -> Rawterm.Explicit ] ; t = operconstr LEVEL "200"; pri = OPT [ "|"; i = natural -> i ] ; props = typeclass_field_defs -> - let sup = match sup with None -> [] | Some l -> l in - let is = (* We reverse the default binding mode on the right *) - let n = - match name with - | Some (loc, id) -> (loc, Name id) - | None -> (dummy_loc, Anonymous) - in - n, expl, t + let sup = + match sup with + None -> [] + | Some l -> l in - VernacInstance (global, sup, is, props, pri) + let n = + let (loc, id) = name in + (loc, Name id) + in + VernacInstance (global, sup, (n, expl, t), props, pri) | IDENT "Existing"; IDENT "Instance"; is = identref -> VernacDeclareInstance is (* Implicit *) - | IDENT "Implicit"; IDENT "Arguments"; enrich = [ IDENT "Enriching" -> true | -> false ]; + | IDENT "Implicit"; IDENT "Arguments"; local = [ IDENT "Global" -> false | IDENT "Local" -> true | -> Lib.sections_are_opened () ]; qid = global; pos = OPT [ "["; l = LIST0 implicit_name; "]" -> - List.map (fun (id,b,f) -> (ExplByName id,b,f)) l ] -> - VernacDeclareImplicits (local,qid,enrich,pos) + List.map (fun (id,b,f) -> (ExplByName id,b,f)) l ] -> + VernacDeclareImplicits (local,qid,pos) | IDENT "Implicit"; ["Type" | IDENT "Types"]; idl = LIST1 identref; ":"; c = lconstr -> VernacReserve (idl,c) ] ] ; - -(* typeclass_ctx: *) -(* [ [ sup = LIST1 operconstr SEP "->"; "=>" -> sup *) -(* ] ] *) -(* ; *) implicit_name: [ [ "!"; id = ident -> (id, false, true) | id = ident -> (id,false,false) | "["; "!"; id = ident; "]" -> (id,true,true) | "["; id = ident; "]" -> (id,true, false) ] ] ; -(* typeclass_param_type: *) -(* [ [ "(" ; id = identref; ":"; t = lconstr ; ")" -> id, t *) -(* | id = identref -> id, CHole (loc, None) ] ] *) -(* ; *) typeclass_field_type: [ [ id = identref; oc = of_type_with_opt_coercion; t = lconstr -> id, oc, t ] ] ; diff --git a/parsing/ppconstr.ml b/parsing/ppconstr.ml index 41d98f2bc8..44aabc2cb4 100644 --- a/parsing/ppconstr.ml +++ b/parsing/ppconstr.ml @@ -218,13 +218,13 @@ let begin_of_binders = function let surround_binder k p = match k with Default Explicit -> hov 1 (str"(" ++ p ++ str")") - | Default Implicit -> hov 1 (str"`" ++ p ++ str"`") + | Default Implicit -> hov 1 (str"{" ++ p ++ str"}") | TypeClass b -> hov 1 (str"[" ++ p ++ str"]") let surround_implicit k p = match k with Default Explicit -> p - | Default Implicit -> (str"`" ++ p ++ str"`") + | Default Implicit -> (str"{" ++ p ++ str"}") | TypeClass b -> (str"[" ++ p ++ str"]") let pr_binder many pr (nal,k,t) = @@ -472,6 +472,16 @@ let pr_app pr a l = pr (lapp,L) a ++ prlist (fun a -> spc () ++ pr_expl_args pr a) l) +let pr_forall () = + if !Flags.unicode_syntax then str"Î " ++ spc () + else str"forall" ++ spc () + +let pr_fun () = + if !Flags.unicode_syntax then str"λ" ++ spc () + else str"fun" ++ spc () + +let pr_fun_sep = lazy (if !Flags.unicode_syntax then str "," else str " =>") + let rec pr sep inherited a = let (strm,prec) = match a with | CRef r -> pr_reference r, latom @@ -492,17 +502,16 @@ let rec pr sep inherited a = | CProdN _ -> let (bl,a) = extract_prod_binders a in hov 0 ( - hov 2 (pr_delimited_binders (fun () -> str"forall" ++ spc()) + hov 2 (pr_delimited_binders pr_forall (pr mt ltop) bl) ++ str "," ++ pr spc ltop a), lprod | CLambdaN _ -> let (bl,a) = extract_lam_binders a in hov 0 ( - hov 2 (pr_delimited_binders (fun () -> str"fun" ++ spc()) - (pr mt ltop) bl) ++ - - str " =>" ++ pr spc ltop a), + hov 2 (pr_delimited_binders pr_fun + (pr mt ltop) bl) ++ + Lazy.force pr_fun_sep ++ pr spc ltop a), llambda | CLetIn (_,(_,Name x),(CFix(_,(_,x'),[_])|CCoFix(_,(_,x'),[_]) as fx), b) when x=x' -> @@ -569,8 +578,8 @@ let rec pr sep inherited a = pr spc ltop b), lletin | CIf (_,c,(na,po),b1,b2) -> - (* On force les parenthèses autour d'un "if" sous-terme (même si le - parsing est lui plus tolérant) *) + (* On force les parenthèses autour d'un "if" sous-terme (même si le + parsing est lui plus tolérant) *) hv 0 ( hov 1 (str "if " ++ pr mt ltop c ++ pr_simple_return_type (pr mt) na po) ++ spc () ++ diff --git a/parsing/ppvernac.ml b/parsing/ppvernac.ml index bd87e09c69..a863665a97 100644 --- a/parsing/ppvernac.ml +++ b/parsing/ppvernac.ml @@ -818,12 +818,12 @@ let rec pr_vernac = function (str"Notation " ++ pr_locality local ++ pr_id id ++ prlist_with_sep spc pr_id ids ++ str" :=" ++ pr_constrarg c ++ pr_syntax_modifiers (if onlyparsing then [SetOnlyParsing] else [])) - | VernacDeclareImplicits (local,q,e,None) -> + | VernacDeclareImplicits (local,q,None) -> hov 2 (str"Implicit Arguments" ++ spc() ++ pr_reference q) - | VernacDeclareImplicits (local,q,e,Some imps) -> + | VernacDeclareImplicits (local,q,Some imps) -> hov 1 (str"Implicit Arguments" ++ pr_non_globality local ++ - spc() ++ pr_reference q ++ spc() ++ - str"[" ++ prlist_with_sep sep pr_explanation imps ++ str"]") + spc() ++ pr_reference q ++ spc() ++ + str"[" ++ prlist_with_sep sep pr_explanation imps ++ str"]") | VernacReserve (idl,c) -> hov 1 (str"Implicit Type" ++ str (if List.length idl > 1 then "s " else " ") ++ |
