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

open Location
4
open Ident
5
6
7
8
9

type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
10
  | TypeDecl of id * ppat
11
  | SchemaDecl of string * Schema_types.schema  (* name, schema *)
12
  | LetDecl of ppat * pexpr
13
  | FunDecl of pexpr
14
  | Namespace of U.t * Ns.t
15
  | Using of U.t * Types.CompUnit.t
16
  | EvalStatement of pexpr
17
  | Debug of debug_directive
18
  | Directive of toplevel_directive
19
20
and debug_directive =
  [ `Filter of ppat * ppat
21
  | `Sample of ppat
22
  | `Accept of ppat
23
  | `Compile of ppat * ppat list 
24
  | `Subtype of ppat * ppat
25
  | `Explain of ppat * pexpr
26
  ]
27
28
29
and toplevel_directive =
  [ `Quit
  | `Env
30
  | `Reinit_ns
31
  | `Help
32
  | `Dump of pexpr
33
34
35
  | `Print_schema of string
  | `Print_schema_type of Schema_types.component_kind * string * string
  | `Print_type of string
36
  ]
37

38

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

42
  (* CDuce is a Lambda-calculus ... *)
43
  | Var of U.t
44
45
46
47
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
48
  | Const of Types.Const.t
49
50
  | Integer of Intervals.V.t
  | Char of Chars.V.t
51
  | Pair of pexpr * pexpr
52
  | Atom of U.t
53
  | Xml of pexpr * pexpr
54
  | RecordLitt of (label * pexpr) list
55
  | String of U.uindex * U.uindex * U.t * pexpr
56
57
58
      
  (* Data destructors *)
  | Match of pexpr * branches
59
60
  | Map of pexpr * branches
  | Transform of pexpr * branches
61
  | Xtrans of pexpr * branches
62
63
  | Validate of pexpr * Schema_types.component_kind * string * string
      (* exp, schema component kind, schema name, element name *)
64
  | Dot of pexpr * label
65
  | RemoveField of pexpr * label
66
67
68
69

  (* Exceptions *)
  | Try of pexpr * branches

70
  (* Other *)
71
  | NamespaceIn of U.t * Ns.t * pexpr
72
73
74
75
76
  | Forget of pexpr * ppat    
  | Op of string * pexpr list
  | Ref of pexpr * ppat


77

78
79
and label = U.t

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

and regexp =
  | Epsilon
  | Elem of ppat
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
118
  | SeqCapture of id * regexp
119

120