ast.ml 3.13 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 ]

Pietro Abate's avatar
Pietro Abate committed
8 9 10
(* located ident *)
type lident = (Cduce_loc.loc * U.t)

11 12 13 14
type pprog = pmodule_item list

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

48 49 50
and pexpr = 
  | LocatedExpr of loc * pexpr

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

  (* Exceptions *)
  | Try of pexpr * branches

79
  (* Other *)
80
  | NamespaceIn of U.t * ns_expr * pexpr
81
  | KeepNsIn of bool * pexpr
82
  | Forget of pexpr * ppat    
83
  | Check of pexpr * ppat
84 85
  | Ref of pexpr * ppat

86 87
  (* CQL *)
  | SelectFW of pexpr * (ppat * pexpr) list * pexpr list
88

89 90
and label = U.t

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

and regexp =
  | Epsilon
  | Elem of ppat
124
  | Guard of ppat
125 126 127 128
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
Pietro Abate's avatar
Pietro Abate committed
129
  | SeqCapture of lident * regexp
130

131 132 133 134 135 136 137
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))