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

open Location
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 (Location.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
  | EvalStatement of pexpr
20
  | Directive of toplevel_directive
21 22
and debug_directive =
  [ `Filter of ppat * ppat
23
  | `Sample of ppat
24
  | `Accept of ppat
25
  | `Compile of ppat * ppat list 
26
  | `Subtype of ppat * ppat
27
  | `Single of ppat
28
  ]
29 30 31
and toplevel_directive =
  [ `Quit
  | `Env
32
  | `Reinit_ns
33
  | `Help
34
  | `Dump of pexpr
35
  | `Print_type of ppat
36
  | `Debug of debug_directive
37 38
  | `Verbose
  | `Silent
39
  | `Builtins
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 67 68
  | Validate of pexpr * U.t list
  | Dot of pexpr * label
  | TyArgs of pexpr * ppat list
69
  | RemoveField of pexpr * label
70 71 72 73

  (* Exceptions *)
  | Try of pexpr * branches

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


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

85 86
and label = U.t

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

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

127

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