ast.ml 3.16 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 (Location.loc * U.t) * ppat
11
  | SchemaDecl of U.t * string * U.t option (* name, uri, ns prefix *)
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
  | `Print_schema of U.t
35
  | `Print_type of ppat
36
  | `Debug of debug_directive
37
38
  | `Verbose
  | `Silent
39
  ]
40

41

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

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

  (* Exceptions *)
  | Try of pexpr * branches

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


81

82
83
and label = U.t

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

and regexp =
  | Epsilon
  | Elem of ppat
117
  | Guard of ppat
118
119
120
121
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
122
  | SeqCapture of Location.loc * U.t * regexp
123

124

125
126
127
128
129
130
131
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))