forked from ermine/sulci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv_xml.ml
66 lines (54 loc) · 1.29 KB
/
conv_xml.ml
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
(*
* (c) 2004-2012 Anastasia Gornostaeva
*)
open Hooks
module StringStream =
struct
type 'a t = 'a
let return x = x
let fail = raise
type stream = {
mutable i : int;
len : int;
buf : string
}
let of_string str =
{ buf = str; len = String.length str; i = 0}
let get s =
if s.i < s.len then (
let c = s.buf.[s.i] in
s.i <- s.i + 1;
Some c
)
else
None
open Encoding
exception IllegalCharacter
let make_decoder encname =
let decoder = decoder encname in
fun strm ->
if strm.i < strm.len then
match decode decoder strm.buf strm.i (strm.len - strm.i) with
| Dec_ok (ucs4, j) ->
strm.i <- strm.i + j;
return (Some ucs4)
| Dec_need_more -> fail IllegalCharacter
| Dec_error -> fail IllegalCharacter
else
return None
end
open Xmllexer
module LS = LocatedStream (UnitMonad) (StringStream)
module M = Xmllexer_generic.Make
(LS)
(Encoding)
(XmlStanza (UnitMonad))
let parse_document content =
let strm = StringStream.of_string content in
let strm = LS.make_stream strm in
let next_token = M.make_lexer strm in
Light_xml.parse next_token
let plugin _opts =
()
let _ =
Plugin.add_plugin "conversion" plugin