ast.ml 2.69 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
  | String of U.uindex * U.uindex * U.t * pexpr
49
50
51
      
  (* Data destructors *)
  | Match of pexpr * branches
52
53
  | Map of pexpr * branches
  | Transform of pexpr * branches
54
  | Xtrans of pexpr * branches
55
56
  | Validate of pexpr * string * string (* exp, schema name, element name *)
  | Dot of pexpr * label
57
  | RemoveField of pexpr * label
58
59
60
61

  (* Exceptions *)
  | Try of pexpr * branches

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

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

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
*)