schema_types.ml 4.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

(** Types used by all the Schema modules.
    This module comes in .mli part only, hence no value and/or exceptions are
    available here. See Schema_common.
*)

(**
  Glossary:
    XSD   XML Schema Document
    PSV   Post Schema Validation
    PSVI  Post Schema Validation Infoset
*)

open Encodings

(** {2 XSD representation} *)

type xs_nonNegativeInteger = Intervals.V.t  (* = Big_int.big_int *)
(* type xs_positiveInteger = Intervals.V.t *)

type derivation_type = [ `Extension | `Restriction ]
type value_constraint = [ `Fixed of Value.t | `Default of Value.t ]
type white_space_handling = [ `Preserve | `Replace | `Collapse ]

type facets = {
  length: (xs_nonNegativeInteger * bool) option;      (* length, fixed *)
  minLength: (xs_nonNegativeInteger * bool) option;   (* length, fixed *)
  maxLength: (xs_nonNegativeInteger * bool) option;   (* length, fixed *)
(*   pattern: Schema_regexp.regexp list;           (* list of ANDed patterns *) *)
  enumeration: Value.ValueSet.t option;
  whiteSpace: white_space_handling * bool;           (* handling, fixed *)
  maxInclusive: (Value.t * bool) option;        (* max, fixed *)
  maxExclusive: (Value.t * bool) option;        (* max, fixed *)
  minInclusive: (Value.t * bool) option;        (* min, fixed *)
  minExclusive: (Value.t * bool) option;        (* min, fixed *)
(*
  totalDigits: (xs_positiveInteger * bool) option;     (* digits, fixed *)
  fractionDigits: (xs_nonNegativeInteger * bool) option;  (* digits, fixed *)
*)
}

type simple_type_definition =
  | Primitive of Utf8.t
  | Derived of
      Utf8.t option * (* name *)
      variety *
      facets *
      simple_type_definition (* base *)

and variety =
  | Atomic of simple_type_definition  (* a Primitive _ *)
  | List of simple_type_definition    (* Variety (simple_type_definition) =
                                              Atomic || Union (of atomic) *)
  | Union of simple_type_definition list

type attribute_declaration =
  Utf8.t *                  (* name *)
  simple_type_definition *  (* type *)
  value_constraint option

type attribute_use =
  bool *                    (* required *)
  attribute_declaration *
  value_constraint option

  (* first construction as per predictive parsing. None stands for epsilon, Some
   * Utf8.t stands for a start tag of identical name *)
type first = Utf8.t option list

type term =
  | Elt of element_declaration ref
  | Model of model_group

and model_group =
  | All of particle list
  | Choice of particle list
  | Sequence of particle list

and content_type =
  | CT_empty
  | CT_simple of simple_type_definition
  | CT_model of
      particle *
      bool        (* mixed *)

and particle =
  xs_nonNegativeInteger *           (* minOccurs *)
  xs_nonNegativeInteger option *    (* maxOccurs (None = "unbounded") *)
  term *
  first

and element_declaration =
  int *                   (* unique id *)
  Utf8.t *                  (* name *)
  type_definition ref *   (* type *)
  value_constraint option

and complex_type_definition =
  int *               (* unique id *)
  Utf8.t option *     (* name *)
  type_definition *   (* base *)
  derivation_type *
  attribute_use list *
  content_type

and type_definition =
  | AnyType
  | Simple of simple_type_definition
  | Complex of complex_type_definition

type model_group_definition =
  Utf8.t *              (* name *)
  model_group

type attribute_group_definition =
  Utf8.t *              (* name *)
  attribute_use list

type schema = {
  targetNamespace: Ns.t;
  types: type_definition list;
  attributes: attribute_declaration list;
  elements: element_declaration list;
  attribute_groups: attribute_group_definition list;
  model_groups: model_group_definition list;
}

(** {2 Events} see Schema_events module *)

type event =
  | E_start_tag of Ns.qname
  | E_end_tag of Ns.qname
  | E_attribute of Ns.qname * Encodings.Utf8.t  (* qualified name, value *)
  | E_char_data of Encodings.Utf8.t

(** {2 Misc} *)

  (* kind of a schema component *)
type component_kind =
  [ `Type | `Element | `Attribute | `Attribute_group | `Model_group ] option

type component =
  | Type of type_definition
  | Element of element_declaration
  | Attribute of attribute_declaration
  | Attribute_group of attribute_group_definition
  | Model_group of model_group_definition