ast.ml 2.48 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 30
and toplevel_directive =
  [ `Quit
  | `Env
  ]
31

32

33 34
and pconst =
  | Const_internal of Types.const
35
  | Const_atom of U.t
36

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

40
  | Forget of pexpr * ppat    
41
  | Op of string * pexpr list
42

43
  (* CDuce is a Lambda-calculus ... *)
44
  | Var of id
45 46 47 48
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
49
  | Cst of pconst
50
  | Pair of pexpr * pexpr
51
  | Xml of pexpr * pexpr
52
  | RecordLitt of pexpr label_map
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
and abstr = { 
71
  fun_name : id option; 
72 73 74 75 76 77 78 79 80 81
  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' =
82
  | PatVar of U.t
83 84
  | SchemaVar of  (* type/pattern schema variable *)
      schema_item_kind * string * string
85 86
  | AtomT of U.t
  | NsT of U.t
87
  | Recurs of ppat * (U.t * ppat) list
88 89
  | Internal of Types.descr
  | Or of ppat * ppat
90
  | And of ppat * ppat
91 92
  | Diff of ppat * ppat
  | Prod of ppat * ppat
93
  | XmlT of ppat * ppat
94
  | Arrow of ppat * ppat
95
  | Optional of ppat
96
  | Record of bool * ppat label_map
97
  | Capture of id
98
  | Constant of id * pconst
99
  | Regexp of regexp * ppat
100
      (* regular expression, continuation: [ re ; cont ], e.g: [ re ; nil ] *)
101 102 103 104 105 106 107 108

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

open Printf