Debian Codegraph @

ide/rocqide/protocol/xml_parser.mli

raw symbols SCIP
1 (*
2 * Xml Light, an small Xml parser/printer with DTD support.
3 * Copyright (C) 2003 Nicolas Cannasse ([email protected])
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *)
19
20 (** Xml Light Parser
21
22 While basic parsing functions can be used in the {!Xml} module, this module
23 is providing a way to create, configure and run an Xml parser.
24
25 *)
26
27
28 (** An Xml node is either
29 [Element (tag-name, attributes, children)] or [PCData text] *)
30 type xml = Xml_datatype.xml
31
32 (** Abstract type for an Xml parser. *)
33 type t
34
35 (** {6:exc Xml Exceptions} *)
36
37 (** Several exceptions can be raised when parsing an Xml document :
38 {ul
39 {li {!Xml.Error} is raised when an xml parsing error occurs. the
40 {!Xml.error_msg} tells you which error occurred during parsing
41 and the {!Xml.error_pos} can be used to retrieve the document
42 location where the error occurred at.}
43 {li {!Xml.File_not_found} is raised when an error occurred while
44 opening a file with the {!Xml.parse_file} function.}
45 }
46 *)
47
48 type error_pos
49
50 type error_msg =
51 | UnterminatedComment
52 | UnterminatedString
53 | UnterminatedEntity
54 | IdentExpected
55 | CloseExpected
56 | NodeExpected
57 | AttributeNameExpected
58 | AttributeValueExpected
59 | EndOfTagExpected of string
60 | EOFExpected
61 | Empty
62
63 type error = error_msg * error_pos
64
65 exception Error of error
66
67 exception File_not_found of string
68
69 (** Get a full error message from an Xml error. *)
70 val error : error -> string
71
72 (** Get the Xml error message as a string. *)
73 val error_msg : error_msg -> string
74
75 (** Get the line the error occurred at. *)
76 val line : error_pos -> int
77
78 (** Get the relative character range (in current line) the error occurred at.*)
79 val range : error_pos -> int * int
80
81 (** Get the absolute character range the error occurred at. *)
82 val abs_range : error_pos -> int * int
83
84 val pos : Lexing.lexbuf -> error_pos
85
86 (** Several kind of resources can contain Xml documents. *)
87 type source =
88 | SChannel of in_channel
89 | SString of string
90 | SLexbuf of Lexing.lexbuf
91
92 (** This function returns a new parser with default options. *)
93 val make : source -> t
94
95 (** When a Xml document is parsed, the parser may check that the end of the
96 document is reached, so for example parsing ["<A/><B/>"] will fail instead
97 of returning only the A element. You can turn on this check by setting
98 [check_eof] to [true] {i (by default, check_eof is false, unlike
99 in the original Xmllight)}. *)
100 val check_eof : t -> bool -> unit
101
102 (** Once the parser is configured, you can run the parser on a any kind
103 of xml document source to parse its contents into an Xml data structure.
104
105 When [canonicalize] is set, the parser tries to remove blank PCDATA elements. *)
106 val parse : ?canonicalize:bool -> t -> xml