aboutsummaryrefslogtreecommitdiffhomepage
path: root/parsing/g_module.ml4
blob: 01e7256efa5e3931b39d5285845494e182b28efe (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
(***********************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team    *)
(* <O___,, *        INRIA-Rocquencourt  &  LRI-CNRS-Orsay              *)
(*   \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$ *) 

open Pp
open Ast
open Pcoq
open Prim
open Module
open Util

(* Grammar rules for module expressions and types *)

GEXTEND Gram
  GLOBAL: ne_binders_list module_expr 
          module_type;
 
  ident:
    [ [ id = Prim.var -> id ] ]
  ;

  ident_comma_list_tail:
    [ [ ","; idl = LIST0 ident SEP "," -> idl
      | -> [] ] ]
  ;

  qualid:
    [ [ id = Prim.var; l = fields -> <:ast< (QUALID $id ($LIST $l)) >>
      | id = Prim.var -> <:ast< (QUALID $id) >>
      ] ]
  ;
  fields:
    [ [ id = FIELD; l = fields -> <:ast< ($VAR $id) >> :: l
      | id = FIELD -> [ <:ast< ($VAR $id) >> ]
      ] ]
  ;

  vardecls: (* This is interpreted by Pcoq.abstract_binder *)
    [ [ id = ident; idl = ident_comma_list_tail; 
	":"; mty = module_type ->
          <:ast< (BINDER $mty $id ($LIST $idl)) >> ] ]
  ;

  ne_vardecls_list:
    [ [ id = vardecls; ";"; idl = ne_vardecls_list -> id :: idl
      | id = vardecls -> [id] ] ]
  ;
  
  rawbinders:
    [ [ "["; bl = ne_vardecls_list; "]" -> bl ] ]
  ;

  ne_binders_list:
    [ [ bl = rawbinders; bll = ne_binders_list -> bl @ bll
      | bl = rawbinders -> bl ] ]
  ;

  module_expr:
    [ [ qid = qualid -> <:ast< (MODEXPRQID $qid) >>
      | me1 = module_expr; me2 = module_expr -> 
	  <:ast< (MODEXPRAPP $me1 $me2) >>
      | "("; me = module_expr; ")" ->
	  me
(* ... *)
      ] ]
  ;

  module_type:
    [ [ qid = qualid -> <:ast< (MODTYPEQID $qid) >>
(* ... *)
      ] ]
  ;
END