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

3
open Cduce_loc
4
open Ident
5

6
7
type ns_expr = [ `Uri of Ns.Uri.t | `Path of U.t list ]

8
9
10
11
type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
12
  | TypeDecl of (Cduce_loc.loc * U.t) * ppat
13
  | SchemaDecl of U.t * string
14
  | LetDecl of ppat * pexpr
15
  | FunDecl of pexpr
16
  | Namespace of U.t * ns_expr
17
  | KeepNs of bool
18
  | Using of U.t * U.t
19
  | Open of U.t list
20
  | EvalStatement of pexpr
21
  | Directive of toplevel_directive
22
23
and debug_directive =
  [ `Filter of ppat * ppat
24
  | `Sample of ppat
25
  | `Accept of ppat
26
  | `Compile of ppat * ppat list 
27
  | `Subtype of ppat * ppat
28
  | `Single of ppat
29
  ]
30
31
32
and toplevel_directive =
  [ `Quit
  | `Env
33
  | `Reinit_ns
34
  | `Help
35
  | `Dump of pexpr
36
  | `Print_type of ppat
37
  | `Debug of debug_directive
38
39
  | `Verbose
  | `Silent
40
  | `Builtins
41
  ]
42

43

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

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

  (* Exceptions *)
  | Try of pexpr * branches

75
  (* Other *)
76
  | NamespaceIn of U.t * ns_expr * pexpr
77
  | KeepNsIn of bool * pexpr
78
  | Forget of pexpr * ppat    
79
  | Check of pexpr * ppat
80
81
82
  | Ref of pexpr * ppat


83
84
  (* CQL *)
  | SelectFW of pexpr * (ppat * pexpr) list * pexpr list
85

86
87
and label = U.t

88
and abstr = { 
89
  fun_name : (Cduce_loc.loc * U.t) option; 
90
91
92
93
94
95
96
97
98
99
  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' =
100
  | PatVar of U.t list
101
  | Cst of pexpr
102
  | NsT of U.t
103
  | Recurs of ppat * (Cduce_loc.loc * U.t * 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 U.t * pexpr
114
  | Regexp of regexp
115
  | Concat of ppat * ppat
116
  | Merge of ppat * ppat
117
118
119
120

and regexp =
  | Epsilon
  | Elem of ppat
121
  | Guard of ppat
122
123
124
125
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
126
  | SeqCapture of Cduce_loc.loc * U.t * regexp
127

128

129
130
131
132
133
134
135
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))