ast.ml 2.49 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
36
and pexpr = 
  | LocatedExpr of loc * pexpr

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

  (* Exceptions *)
  | Try of pexpr * branches

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


70

71
72
and label = U.t

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

and regexp =
  | Epsilon
  | Elem of ppat
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
111
  | SeqCapture of id * regexp
112

113