ast.ml 2.59 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
  | Const of Types.Const.t
47 48
  | Integer of Intervals.V.t
  | Char of Chars.V.t
49
  | Pair of pexpr * pexpr
50
  | Atom of U.t
51
  | Xml of pexpr * pexpr
52
  | RecordLitt of (label * pexpr) list
53
  | String of U.uindex * U.uindex * U.t * pexpr
54 55 56
      
  (* Data destructors *)
  | Match of pexpr * branches
57 58
  | Map of pexpr * branches
  | Transform of pexpr * branches
59
  | Xtrans of pexpr * branches
60 61
  | Validate of pexpr * string * string (* exp, schema name, element name *)
  | Dot of pexpr * label
62
  | RemoveField of pexpr * label
63 64 65 66

  (* Exceptions *)
  | Try of pexpr * branches

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


74

75 76
and label = U.t

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

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

117