1
(* $Id: link_ocamllex.src 675 2004-06-13 16:03:16Z gerd $
2
* ----------------------------------------------------------------------
6
(* This file is divided up into sections, marked by (* [SECTION] *).
7
* Sections are processed by lexpp.
10
(* ---------------------------------------------------------------------- *)
13
(* This section contains code going into the link module. The patterns
14
* $ {name} (w/o space) are substituted by generated strings:
15
* - $ {encoding} is replaced by the name of the character encoding
16
* - all other names must be names of lexical rules, and $ {name} is
17
* replaced by Module.name, i.e. the correct module prefix is prepended
25
class lfactory : lexer_factory =
27
method encoding = `Enc_${encoding}
29
method open_source src =
31
(self : #lexer_factory :> lexer_factory)
32
(Lazy.force src.lsrc_lexbuf) false
34
method open_string s =
36
(self : #lexer_factory :> lexer_factory)
37
(Lexing.from_string s) true
39
method open_string_inplace s =
41
(self : #lexer_factory :> lexer_factory)
42
(Pxp_lexing.from_string_inplace s) true
45
and lobj factory _lexbuf _lexbuf_from_string : lexer_obj =
47
val mutable lexbuf = _lexbuf
48
val mutable lexbuf_from_string = _lexbuf_from_string
50
method factory = factory
52
method encoding = `Enc_${encoding}
54
method open_source src =
55
lexbuf <- Lazy.force src.lsrc_lexbuf;
56
lexbuf_from_string <- false
58
method open_string s =
59
lexbuf <- Lexing.from_string s;
60
lexbuf_from_string <- true
62
method open_string_inplace s =
63
if lexbuf_from_string then (
64
Pxp_lexing.from_another_string_inplace lexbuf s
67
lexbuf <- Pxp_lexing.from_string_inplace s;
68
lexbuf_from_string <- true
71
method lexeme_length =
72
if Netconversion.is_single_byte `Enc_${encoding} then
73
Lexing.lexeme_end lexbuf - Lexing.lexeme_start lexbuf
75
(* Very inefficient: *)
76
let s = Lexing.lexeme lexbuf in
77
Netconversion.ustring_length `Enc_${encoding} s
80
method lexeme_char pos =
81
(* Very inefficient: *)
82
let s = Lexing.lexeme lexbuf in
83
let cs = Netconversion.create_cursor `Enc_${encoding} s in
84
Netconversion.move ~num:pos cs;
85
Netconversion.uchar_at cs
90
method lexeme_strlen =
91
Pxp_lexing.lexeme_len lexbuf
93
method sub_lexeme pos len =
94
if Netconversion.is_single_byte `Enc_${encoding} then (
95
Pxp_lexing.sub_lexeme lexbuf pos len
98
(* Very inefficient: *)
99
let s = Lexing.lexeme lexbuf in
100
let ua = Netconversion.uarray_of_ustring `Enc_${encoding} s in
101
Netconversion.ustring_of_uarray `Enc_${encoding} ~pos ~len ua
105
method scan_document =
107
${scan_document}.scan_document (self : #lexer_obj :> lexer_obj) lexbuf
109
method scan_content =
111
${scan_content}.scan_content (self : #lexer_obj :> lexer_obj) lexbuf
113
method scan_within_tag =
115
${scan_within_tag}.scan_within_tag
116
(self : #lexer_obj :> lexer_obj) lexbuf
118
method scan_document_type =
120
${scan_document_type}.scan_document_type
121
(self : #lexer_obj :> lexer_obj) lexbuf
123
method scan_declaration =
125
${scan_declaration}.scan_declaration
126
(self : #lexer_obj :> lexer_obj) lexbuf
128
method scan_comment =
130
${scan_comment}.scan_comment (self : #lexer_obj :> lexer_obj) lexbuf
132
method scan_ignored_section =
134
${scan_ignored_section}.scan_ignored_section
135
(self : #lexer_obj :> lexer_obj) lexbuf
137
method detect_xml_pi =
139
${detect_xml_pi}.detect_xml_pi (self : #lexer_obj :> lexer_obj) lexbuf
143
${scan_xml_pi}.scan_xml_pi (self : #lexer_obj :> lexer_obj) lexbuf
145
method scan_pi_string =
147
${scan_pi_string}.scan_pi_string (self : #lexer_obj :> lexer_obj) lexbuf
149
method scan_dtd_string =
151
${scan_dtd_string}.scan_dtd_string (self : #lexer_obj :> lexer_obj) lexbuf
153
method scan_content_string =
155
${scan_content_string}.scan_content_string
156
(self : #lexer_obj :> lexer_obj) lexbuf
158
method scan_name_string =
160
${scan_name_string}.scan_name_string
161
(self : #lexer_obj :> lexer_obj) lexbuf
163
method scan_for_crlf =
165
${scan_for_crlf}.scan_for_crlf (self : #lexer_obj :> lexer_obj) lexbuf
167
method scan_characters =
169
${scan_characters}.scan_characters (self : #lexer_obj :> lexer_obj) lexbuf
171
method scan_character =
173
${scan_character}.scan_character (self : #lexer_obj :> lexer_obj) lexbuf
177
${scan_tag_eb}.scan_tag_eb (self : #lexer_obj :> lexer_obj) lexbuf
179
method scan_tag_eb_att =
181
${scan_tag_eb_att}.scan_tag_eb_att (self : #lexer_obj :> lexer_obj) lexbuf
187
Pxp_lexers.init (new lfactory)