ast.ml 2.64 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 12
type pprog = pmodule_item list

and pmodule_item = pmodule_item' located
and pmodule_item' =
  | TypeDecl of string * ppat
13
  | SchemaDecl of string * Schema_types.schema  (* name, schema *)
14
  | LetDecl of ppat * pexpr
15
  | FunDecl of pexpr
16
  | EvalStatement of pexpr
17
  | Debug of debug_directive
18
  | Directive of toplevel_directive
19 20
and debug_directive =
  [ `Filter of ppat * ppat
21
  | `Sample of ppat
22
  | `Accept of ppat
23
  | `Compile of ppat * ppat list 
24
  | `Subtype of ppat * ppat
25
  ]
26 27 28 29
and toplevel_directive =
  [ `Quit
  | `Env
  ]
30

31

32 33 34
and pexpr = 
  | LocatedExpr of loc * pexpr

35
  | Forget of pexpr * ppat    
36
  | Op of string * pexpr list
37

38
  (* CDuce is a Lambda-calculus ... *)
39
  | Var of id
40 41 42 43 44 45
  | Apply of pexpr * pexpr
  | Abstraction of abstr
      
  (* Data constructors *)
  | Cst of Types.const
  | Pair of pexpr * pexpr
46
  | Xml of pexpr * pexpr
47
  | RecordLitt of pexpr label_map
48 49 50
      
  (* Data destructors *)
  | Match of pexpr * branches
51 52
  | Map of pexpr * branches
  | Transform of pexpr * branches
53
  | Xtrans of pexpr * branches
54 55
  | Validate of pexpr * string * string (* exp, schema name, element name *)
  | Dot of pexpr * label
56
  | RemoveField of pexpr * label
57 58 59 60

  (* Exceptions *)
  | Try of pexpr * branches

61
and abstr = { 
62
  fun_name : id option; 
63 64 65 66 67 68 69 70 71 72 73
  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
74 75
  | SchemaVar of  (* type/pattern schema variable *)
      schema_item_kind * string * string
76 77 78
  | Recurs of ppat * (string * ppat) list
  | Internal of Types.descr
  | Or of ppat * ppat
79
  | And of ppat * ppat
80 81
  | Diff of ppat * ppat
  | Prod of ppat * ppat
82
  | XmlT of ppat * ppat
83
  | Arrow of ppat * ppat
84
  | Optional of ppat
85
  | Record of bool * ppat label_map
86 87
  | Capture of id
  | Constant of id * Types.const
88
  | Regexp of regexp * ppat
89
      (* regular expression, continuation: [ re ; cont ], e.g: [ re ; nil ] *)
90 91 92 93 94 95 96 97

and regexp =
  | Epsilon
  | Elem of ppat
  | Seq of regexp * regexp
  | Alt of regexp * regexp
  | Star of regexp
  | WeakStar of regexp
98
  | SeqCapture of id * regexp
99 100 101 102 103 104 105 106 107 108 109 110 111

open Printf

(*
let rec string_of_regexp = function
  | Epsilon -> "e"
  | Elem _ -> "ELEM"
  | Seq (re1, re2) -> sprintf "(%s),(%s)" (string_of_regexp re1) (string_of_regexp re2)
  | Alt (re1, re2) -> sprintf "(%s)|(%s)" (string_of_regexp re1) (string_of_regexp re2)
  | Star re -> sprintf "(%s)*" (string_of_regexp re)
  | WeakStar _ -> assert false
  | SeqCapture _ -> assert false
*)