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

open Location
4
open Ident
5

6 7
type schema_item_kind = [ `Type | `Element | `Attribute | `Any ]

8 9 10 11
type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
12
  | TypeDecl of U.t * ppat
13
  | SchemaDecl of string * Schema_types.schema  (* name, schema *)
14
  | LetDecl of ppat * pexpr
15
  | FunDecl of pexpr
16
  | Namespace of U.t * Ns.t
17
  | EvalStatement of pexpr
18
  | Debug of debug_directive
19
  | Directive of toplevel_directive
20 21
and debug_directive =
  [ `Filter of ppat * ppat
22
  | `Sample of ppat
23
  | `Accept of ppat
24
  | `Compile of ppat * ppat list 
25
  | `Subtype of ppat * ppat
26
  ]
27 28 29
and toplevel_directive =
  [ `Quit
  | `Env
30
  | `Reinit_ns
31
  ]
32

33

34 35
and pconst =
  | Const_internal of Types.const
36
  | Const_atom of U.t
37

38 39 40
and pexpr = 
  | LocatedExpr of loc * pexpr

41
  (* CDuce is a Lambda-calculus ... *)
42
  | Var of id
43 44 45 46
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
47
  | Cst of pconst
48
  | Pair of pexpr * pexpr
49
  | Xml of pexpr * pexpr
50
  | RecordLitt of (label * pexpr) list
51
  | String of U.uindex * U.uindex * U.t * pexpr
52 53 54
      
  (* Data destructors *)
  | Match of pexpr * branches
55 56
  | Map of pexpr * branches
  | Transform of pexpr * branches
57
  | Xtrans of pexpr * branches
58 59
  | Validate of pexpr * string * string (* exp, schema name, element name *)
  | Dot of pexpr * label
60
  | RemoveField of pexpr * label
61 62 63 64

  (* Exceptions *)
  | Try of pexpr * branches

65
  (* Other *)
66
  | NamespaceIn of U.t * Ns.t * pexpr
67 68 69 70 71
  | Forget of pexpr * ppat    
  | Op of string * pexpr list
  | Ref of pexpr * ppat


72

73 74
and label = U.t

75
and abstr = { 
76
  fun_name : id option; 
77 78 79 80 81 82 83 84 85 86
  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' =
87
  | PatVar of U.t
88 89
  | SchemaVar of  (* type/pattern schema variable *)
      schema_item_kind * string * string
90 91
  | AtomT of U.t
  | NsT of U.t
92
  | Recurs of ppat * (U.t * ppat) list
93 94
  | Internal of Types.descr
  | Or of ppat * ppat
95
  | And of ppat * ppat
96 97
  | Diff of ppat * ppat
  | Prod of ppat * ppat
98
  | XmlT of ppat * ppat
99
  | Arrow of ppat * ppat
100
  | Optional of ppat
101
  | Record of bool * (label * ppat) list
102
  | Constant of id * pconst
103
  | Regexp of regexp * ppat
104
      (* regular expression, continuation: [ re ; cont ], e.g: [ re ; nil ] *)
105 106 107 108 109 110 111 112

and regexp =
  | Epsilon
  | Elem of ppat
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
113
  | SeqCapture of id * regexp
114 115

open Printf