ast.ml 3.12 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 * ppat * pexpr
25
26
  | `Single of ppat
  | `Approx of ppat * ppat
27
  ]
28
29
30
and toplevel_directive =
  [ `Quit
  | `Env
31
  | `Reinit_ns
32
  | `Help
33
  | `Dump of pexpr
34
35
36
  | `Print_schema of U.t
  | `Print_schema_type of Schema_types.component_kind * U.t * U.t
  | `Print_type of U.t
37
  | `Debug of debug_directive
38
39
  | `Verbose
  | `Silent
40
  ]
41

42

43
44
45
and pexpr = 
  | LocatedExpr of loc * pexpr

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

  (* Exceptions *)
  | Try of pexpr * branches

74
  (* Other *)
75
  | NamespaceIn of U.t * Ns.t * pexpr
76
  | Forget of pexpr * ppat    
77
  | Check of pexpr * ppat
78
(*  | Op of string * pexpr list *)
79
  | Ref of pexpr * ppat
80
  | External of string * ppat list
81
82


83

84
85
and label = U.t

86
and abstr = { 
87
  fun_name : id option; 
88
89
90
91
92
93
94
95
96
97
  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' =
98
  | PatVar of U.t
99
  | SchemaVar of  (* type/pattern schema variable *)
100
      Schema_types.component_kind * U.t * U.t (* kind, schema, name *)
101
  | Cst of pexpr
102
  | NsT of U.t
103
  | Recurs of ppat * (id * ppat) list
104
105
  | Internal of Types.descr
  | Or of ppat * ppat
106
  | And of ppat * ppat
107
108
  | Diff of ppat * ppat
  | Prod of ppat * ppat
109
  | XmlT of ppat * ppat
110
  | Arrow of ppat * ppat
111
  | Optional of ppat
112
  | Record of bool * (label * (ppat * ppat option)) list
113
  | Constant of id * pexpr
114
  | Regexp of regexp
115
116
117
118

and regexp =
  | Epsilon
  | Elem of ppat
119
  | Guard of ppat
120
121
122
123
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
124
  | SeqCapture of id * regexp
125

126

127
128
129
130
131
132
133
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))