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 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
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
  | Ref of pexpr * ppat

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

84 85
and label = U.t

86
and abstr = { 
87
  fun_name : (Cduce_loc.loc * U.t) option; 
88 89
  fun_iface : (ppat * ppat) list;
  fun_body : branches
90 91 92 93 94 95 96 97
  (* 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
   * *) 
98 99 100 101 102 103 104 105
}

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

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

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

135

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