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

open Location
4
open Ident
5 6 7 8 9 10 11

type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
  | TypeDecl of string * ppat
  | LetDecl of ppat * pexpr
12
  | FunDecl of pexpr
13
  | EvalStatement of pexpr
14
  | Debug of debug_directive
15
  | Directive of toplevel_directive
16 17
and debug_directive =
  [ `Filter of ppat * ppat
18
  | `Sample of ppat
19
  | `Accept of ppat
20
  | `Compile of ppat * ppat list 
21
  | `Subtype of ppat * ppat
22
  ]
23 24 25 26
and toplevel_directive =
  [ `Quit
  | `Env
  ]
27

28

29 30 31
and pexpr = 
  | LocatedExpr of loc * pexpr

32
  | Forget of pexpr * ppat    
33
  | Op of string * pexpr list
34

35
  (* CDuce is a Lambda-calculus ... *)
36
  | Var of id
37 38 39 40 41 42
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
  | Cst of Types.const
  | Pair of pexpr * pexpr
43
  | Xml of pexpr * pexpr
44
  | RecordLitt of pexpr label_map
45 46 47
      
  (* Data destructors *)
  | Match of pexpr * branches
48 49
  | Map of pexpr * branches
  | Transform of pexpr * branches
50
  | Xtrans of pexpr * branches
51 52
  | Dot of pexpr* label
  | RemoveField of pexpr * label
53 54 55 56

  (* Exceptions *)
  | Try of pexpr * branches

57
and abstr = { 
58
  fun_name : id option; 
59 60 61 62 63 64 65 66 67 68 69 70 71 72
  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' =
  | PatVar of string
  | Recurs of ppat * (string * ppat) list
  | Internal of Types.descr
  | Or of ppat * ppat
73
  | And of ppat * ppat
74 75
  | Diff of ppat * ppat
  | Prod of ppat * ppat
76
  | XmlT of ppat * ppat
77
  | Arrow of ppat * ppat
78
  | Optional of ppat
79
  | Record of bool * ppat label_map
80 81
  | Capture of id
  | Constant of id * Types.const
82 83 84 85 86 87 88 89 90
  | Regexp of regexp * ppat

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