ast.ml 3.02 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
12
  | LetDecl of ppat * pexpr
13
  | FunDecl of pexpr
14
  | Namespace of U.t * Ns.Uri.t
15
  | KeepNs of bool
16
  | Using of U.t * U.t
17
  | EvalStatement of pexpr
18
  | Directive of toplevel_directive
19 20
and debug_directive =
  [ `Filter of ppat * ppat
21
  | `Sample of ppat
22
  | `Accept of ppat
23
  | `Compile of ppat * ppat list 
24
  | `Subtype of ppat * ppat
25
  | `Single of ppat
26
  ]
27 28 29
and toplevel_directive =
  [ `Quit
  | `Env
30
  | `Reinit_ns
31
  | `Help
32
  | `Dump of pexpr
33
  | `Print_type of ppat
34
  | `Debug of debug_directive
35 36
  | `Verbose
  | `Silent
37
  | `Builtins
38
  ]
39

40

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

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

  (* Exceptions *)
  | Try of pexpr * branches

71
  (* Other *)
72
  | NamespaceIn of U.t * Ns.Uri.t * pexpr
73
  | KeepNsIn of bool * pexpr
74
  | Forget of pexpr * ppat    
75
  | Check of pexpr * ppat
76 77 78
  | Ref of pexpr * ppat


79 80
  (* CQL *)
  | SelectFW of pexpr * (ppat * pexpr) list * pexpr list
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
  | Cst of pexpr
98
  | NsT of U.t
99
  | Recurs of ppat * (Location.loc * U.t * ppat) list
100 101
  | Internal of Types.descr
  | Or of ppat * ppat
102
  | And of ppat * ppat
103 104
  | Diff of ppat * ppat
  | Prod of ppat * ppat
105
  | XmlT of ppat * ppat
106
  | Arrow of ppat * ppat
107
  | Optional of ppat
108
  | Record of bool * (label * (ppat * ppat option)) list
109
  | Constant of U.t * pexpr
110
  | Regexp of regexp
111
  | Concat of ppat * ppat
112
  | Merge of ppat * ppat
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))