summaryrefslogtreecommitdiff
path: root/tactics/extraargs.ml4
blob: 5a0b4b8ce80e0c46a9eb11097902cb18990b3ac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(*i camlp4deps: "parsing/grammar.cma" i*)

(* $Id: extraargs.ml4 8739 2006-04-26 22:23:37Z herbelin $ *)

open Pp
open Pcoq
open Genarg
open Names
open Tacexpr
open Tacinterp

(* Rewriting orientation *)

let _ = Metasyntax.add_token_obj "<-"
let _ = Metasyntax.add_token_obj "->"

let pr_orient _prc _prlc _prt = function
  | true -> Pp.mt ()
  | false -> Pp.str " <-"


ARGUMENT EXTEND orient TYPED AS bool PRINTED BY pr_orient
| [ "->" ] -> [ true ]
| [ "<-" ] -> [ false ]
| [ ] -> [ true ]
END

(* For Setoid rewrite *)
let pr_morphism_signature _ _ _ s =
  spc () ++ Setoid_replace.pr_morphism_signature s

ARGUMENT EXTEND morphism_signature
 TYPED AS morphism_signature
 PRINTED BY pr_morphism_signature
  | [ constr(out) ] -> [ [],out ]
  | [ constr(c) "++>" morphism_signature(s) ] ->
       [ let l,out = s in (Some true,c)::l,out ]
  | [ constr(c) "-->" morphism_signature(s) ] ->
       [ let l,out = s in (Some false,c)::l,out ]
  | [ constr(c) "==>" morphism_signature(s) ] ->
       [ let l,out = s in (None,c)::l,out ]
END

let pr_gen prc _prlc _prtac c = prc c

let pr_rawc _prc _prlc _prtac raw = Printer.pr_rawconstr raw

let interp_raw _ _ (t,_) = t

let glob_raw = Tacinterp.intern_constr

let subst_raw = Tacinterp.subst_rawconstr_and_expr

ARGUMENT EXTEND raw
    TYPED AS rawconstr
    PRINTED BY pr_rawc
     
     INTERPRETED BY interp_raw	
     GLOBALIZED BY glob_raw
     SUBSTITUTED BY subst_raw
     
     RAW_TYPED AS constr_expr
     RAW_PRINTED BY pr_gen
     
     GLOB_TYPED AS rawconstr_and_expr
     GLOB_PRINTED BY pr_gen
  [ lconstr(c) ] -> [ c ]
END

type 'id gen_place= ('id * hyp_location_flag,unit) location

type loc_place = identifier Util.located gen_place
type place = identifier gen_place

let pr_gen_place pr_id = function
    ConclLocation () -> Pp.mt ()
  | HypLocation (id,InHyp) -> str "in " ++ pr_id id
  | HypLocation (id,InHypTypeOnly) -> 
      str "in (Type of " ++ pr_id id ++ str ")"
  | HypLocation (id,InHypValueOnly) -> 
      str "in (Value of " ++ pr_id id ++ str ")"

let pr_loc_place _ _ _ = pr_gen_place (fun (_,id) -> Nameops.pr_id id)
let pr_place _ _ _ = pr_gen_place Nameops.pr_id

let intern_place ist = function
    ConclLocation () -> ConclLocation ()
  | HypLocation (id,hl) -> HypLocation (intern_hyp ist id,hl)

let interp_place ist gl = function
    ConclLocation () -> ConclLocation ()
  | HypLocation (id,hl) -> HypLocation (interp_hyp ist gl id,hl)

let subst_place subst pl = pl 

ARGUMENT EXTEND hloc
    TYPED AS place
    PRINTED BY pr_place
    INTERPRETED BY interp_place
    GLOBALIZED BY intern_place
    SUBSTITUTED BY subst_place
    RAW_TYPED AS loc_place
    RAW_PRINTED BY pr_loc_place
    GLOB_TYPED AS loc_place
    GLOB_PRINTED BY pr_loc_place
  [ ] -> 
    [ ConclLocation () ]
  |  [ "in" "|-" "*" ] -> 
    [ ConclLocation () ]
| [ "in" ident(id) ] ->
    [ HypLocation ((Util.dummy_loc,id),InHyp) ]
| [ "in" "(" "Type" "of" ident(id) ")" ] -> 
    [ HypLocation ((Util.dummy_loc,id),InHypTypeOnly) ]
| [ "in" "(" "Value" "of" ident(id) ")" ] -> 
    [ HypLocation ((Util.dummy_loc,id),InHypValueOnly) ]
   
 END