ast.ml 3.08 KB
Newer Older
1
(*  Abstract syntax as produced by the parser *)
2
3

open Location
4
open Ident
5
6
7
8
9

type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
10
  | TypeDecl of id * ppat
11
  | SchemaDecl of U.t * string  (* name, uri *)
12
  | LetDecl of ppat * pexpr
13
  | FunDecl of pexpr
14
  | Namespace of U.t * Ns.t
15
  | Using of U.t * U.t
16
  | EvalStatement of pexpr
17
  | Directive of toplevel_directive
18
19
and debug_directive =
  [ `Filter of ppat * ppat
20
  | `Sample of ppat
21
  | `Accept of ppat
22
  | `Compile of ppat * ppat list 
23
  | `Subtype of ppat * ppat
24
  | `Explain of ppat * pexpr
25
  ]
26
27
28
and toplevel_directive =
  [ `Quit
  | `Env
29
  | `Reinit_ns
30
  | `Help
31
  | `Dump of pexpr
32
33
34
  | `Print_schema of U.t
  | `Print_schema_type of Schema_types.component_kind * U.t * U.t
  | `Print_type of U.t
35
  | `Debug of debug_directive
36
  ]
37

38

39
40
41
and pexpr = 
  | LocatedExpr of loc * pexpr

42
  (* CDuce is a Lambda-calculus ... *)
43
  | Var of U.t
44
45
46
47
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
48
  | Const of Types.Const.t
49
50
  | Integer of Intervals.V.t
  | Char of Chars.V.t
51
  | Pair of pexpr * pexpr
52
  | Atom of U.t
53
  | Xml of pexpr * pexpr
54
  | RecordLitt of (label * pexpr) list
55
  | String of U.uindex * U.uindex * U.t * pexpr
56
57
58
      
  (* Data destructors *)
  | Match of pexpr * branches
59
60
  | Map of pexpr * branches
  | Transform of pexpr * branches
61
  | Xtrans of pexpr * branches
62
  | Validate of pexpr * Schema_types.component_kind * U.t * U.t
63
      (* exp, schema component kind, schema name, element name *)
64
  | Dot of pexpr * label
65
  | RemoveField of pexpr * label
66
67
68
69

  (* Exceptions *)
  | Try of pexpr * branches

70
  (* Other *)
71
  | NamespaceIn of U.t * Ns.t * pexpr
72
  | Forget of pexpr * ppat    
73
(*  | Op of string * pexpr list *)
74
  | Ref of pexpr * ppat
75
  | External of string * ppat list
76
77


78

79
80
and label = U.t

81
and abstr = { 
82
  fun_name : id option; 
83
84
85
86
87
88
89
90
91
92
  fun_iface : (ppat * ppat) list;
  fun_body : branches
}

and branches = (ppat * pexpr) list
    
(* A common syntactic class for patterns and types *) 

and ppat = ppat' located
and ppat' =
93
  | PatVar of U.t
94
  | SchemaVar of  (* type/pattern schema variable *)
95
      Schema_types.component_kind * U.t * U.t (* kind, schema, name *)
96
  | Cst of pexpr
97
  | NsT of U.t
98
  | Recurs of ppat * (id * ppat) list
99
100
  | Internal of Types.descr
  | Or of ppat * ppat
101
  | And of ppat * ppat
102
103
  | Diff of ppat * ppat
  | Prod of ppat * ppat
104
  | XmlT of ppat * ppat
105
  | Arrow of ppat * ppat
106
  | Optional of ppat
107
  | Record of bool * (label * ppat) list
108
  | Constant of id * pexpr
109
  | Regexp of regexp * ppat
110
      (* regular expression, continuation: [ re ; cont ], e.g: [ re ; nil ] *)
111
112
113
114

and regexp =
  | Epsilon
  | Elem of ppat
115
  | Guard of ppat
116
117
118
119
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
120
  | SeqCapture of id * regexp
121

122

123
124
125
126
127
128
129
let pat_true = mknoloc (Internal Builtin_defs.true_type)
let pat_false = mknoloc (Internal Builtin_defs.false_type) 
let cst_true = Const (Types.Atom Builtin_defs.true_atom)
let cst_false = Const (Types.Atom Builtin_defs.false_atom)

let cst_nil =  Const Sequence.nil_cst
let pat_nil = mknoloc (Internal (Sequence.nil_type))