ast.ml 2.65 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 | `Attribute_group | `Model_group ] option
8

9
10
11
12
type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
13
  | TypeDecl of id * ppat
14
  | SchemaDecl of string * Schema_types.schema  (* name, schema *)
15
  | LetDecl of ppat * pexpr
16
  | FunDecl of pexpr
17
  | Namespace of U.t * Ns.t
18
  | Using of U.t * Types.CompUnit.t
19
  | EvalStatement of pexpr
20
  | Debug of debug_directive
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
  | `Explain of ppat * pexpr
29
  ]
30
31
32
and toplevel_directive =
  [ `Quit
  | `Env
33
  | `Reinit_ns
34
  | `Help
35
  | `Dump of pexpr
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 * string * string (* exp, schema name, element name *)
  | Dot of pexpr * label
64
  | RemoveField of pexpr * label
65
66
67
68

  (* Exceptions *)
  | Try of pexpr * branches

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


76

77
78
and label = U.t

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

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

119