ast.ml 3.5 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
  | `Typed of pexpr
  | `Lambda of pexpr
31
  ]
32 33 34
and toplevel_directive =
  [ `Quit
  | `Env
35
  | `Reinit_ns
36
  | `Help of string option
37
  | `Dump of pexpr
38
  | `Print_type of ppat
39
  | `Debug of debug_directive
40 41
  | `Verbose
  | `Silent
42
  | `Builtins
43
  ]
44

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

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

  (* Exceptions *)
  | Try of pexpr * branches

76
  (* Other *)
77
  | NamespaceIn of U.t * ns_expr * pexpr
78
  | KeepNsIn of bool * pexpr
79
  | Forget of pexpr * ppat    
80
  | Check of pexpr * ppat
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
  fun_iface : (ppat * ppat) list;
  fun_body : branches
92 93 94 95 96 97 98 99
  (* add deco : (sigma) symbolic representation of set type substitutions *)
  (* plus a flag that is true if interesection of the free varbialbes of S that are not intruduced 
   * by the lambda astractions are domain of sigma.
   * if oldvar(S) ^ dom(sigma) = empty then s < t else s[eval(sigma, env)] < t 
   * (biginter_{sigma_i \in eval} s (sigma_i) ) < t
   *
   * see Evaluation, section 5.3 Article part 1
   * *) 
100 101 102 103 104 105 106 107
}

and branches = (ppat * pexpr) list
    
(* A common syntactic class for patterns and types *) 

and ppat = ppat' located
and ppat' =
108
  | PatVar of U.t list
109
  | Cst of pexpr
110
  | NsT of U.t
111
  | Recurs of ppat * (Cduce_loc.loc * U.t * ppat) list
112 113
  | Internal of Types.descr
  | Or of ppat * ppat
114
  | And of ppat * ppat
115 116
  | Diff of ppat * ppat
  | Prod of ppat * ppat
117
  | XmlT of ppat * ppat
118
  | Arrow of ppat * ppat
119
  | Optional of ppat
120
  | Record of bool * (label * (ppat * ppat option)) list
121
  | Constant of U.t * pexpr
122
  | Regexp of regexp
123
  | Concat of ppat * ppat
124
  | Merge of ppat * ppat
125 126 127 128

and regexp =
  | Epsilon
  | Elem of ppat
129
  | Guard of ppat
130 131 132 133
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
134
  | SeqCapture of Cduce_loc.loc * U.t * regexp
135

136

137 138 139 140 141 142 143
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))