ast.ml 2.57 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 id * 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
  | Using of U.t * Types.CompUnit.t
18
  | EvalStatement of pexpr
19
  | Debug of debug_directive
20
  | Directive of toplevel_directive
21
22
and debug_directive =
  [ `Filter of ppat * ppat
23
  | `Sample of ppat
24
  | `Accept of ppat
25
  | `Compile of ppat * ppat list 
26
  | `Subtype of ppat * ppat
27
  | `Explain of ppat * pexpr
28
  ]
29
30
31
and toplevel_directive =
  [ `Quit
  | `Env
32
  | `Reinit_ns
33
  | `Help
34
  ]
35

36

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

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

  (* Exceptions *)
  | Try of pexpr * branches

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


73

74
75
and label = U.t

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

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

116