~ubuntu-branches/ubuntu/hardy/pxp/hardy

« back to all changes in this revision

Viewing changes to src/pxp-lex/link_ocamllex.src

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2005-03-29 11:06:39 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050329110639-5p39hz1d4aq3r2ec
Tags: 1.1.95-6
* Rebuilt against ocaml 3.08.3
* No longer built with wlex support (since wlex is no longer supported
  upstream and corresponding package has been removed from the debian
  archive)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* $Id: link_ocamllex.src 675 2004-06-13 16:03:16Z gerd $
 
2
 * ----------------------------------------------------------------------
 
3
 *
 
4
 *)
 
5
 
 
6
(* This file is divided up into sections, marked by (* [SECTION] *).
 
7
 * Sections are processed by lexpp.
 
8
 *)
 
9
 
 
10
(* ---------------------------------------------------------------------- *)
 
11
(* [LINK] *)
 
12
 
 
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
 
18
 *   to the rule name.
 
19
 *)
 
20
 
 
21
open Pxp_types
 
22
open Pxp_lexer_types
 
23
open Pxp_reader
 
24
 
 
25
class lfactory : lexer_factory =
 
26
object(self)
 
27
  method encoding = `Enc_${encoding}
 
28
 
 
29
  method open_source src = 
 
30
    new lobj 
 
31
      (self : #lexer_factory :> lexer_factory) 
 
32
      (Lazy.force src.lsrc_lexbuf) false
 
33
 
 
34
  method open_string s =
 
35
    new lobj 
 
36
      (self : #lexer_factory :> lexer_factory) 
 
37
      (Lexing.from_string s) true
 
38
 
 
39
  method open_string_inplace s =
 
40
    new lobj 
 
41
      (self : #lexer_factory :> lexer_factory) 
 
42
      (Pxp_lexing.from_string_inplace s) true
 
43
end
 
44
 
 
45
and lobj factory _lexbuf _lexbuf_from_string : lexer_obj =
 
46
object(self)
 
47
  val mutable lexbuf = _lexbuf
 
48
  val mutable lexbuf_from_string = _lexbuf_from_string
 
49
 
 
50
  method factory = factory
 
51
 
 
52
  method encoding = `Enc_${encoding}
 
53
 
 
54
  method open_source src =
 
55
    lexbuf <- Lazy.force src.lsrc_lexbuf;
 
56
    lexbuf_from_string <- false
 
57
 
 
58
  method open_string s =
 
59
    lexbuf <- Lexing.from_string s;
 
60
    lexbuf_from_string <- true
 
61
 
 
62
  method open_string_inplace s =
 
63
    if lexbuf_from_string then (
 
64
      Pxp_lexing.from_another_string_inplace lexbuf s
 
65
    )
 
66
    else (
 
67
      lexbuf <- Pxp_lexing.from_string_inplace s;
 
68
      lexbuf_from_string <- true
 
69
    )
 
70
 
 
71
  method lexeme_length =
 
72
    if Netconversion.is_single_byte `Enc_${encoding} then
 
73
      Lexing.lexeme_end lexbuf - Lexing.lexeme_start lexbuf
 
74
    else (
 
75
      (* Very inefficient: *)
 
76
      let s = Lexing.lexeme lexbuf in
 
77
      Netconversion.ustring_length `Enc_${encoding} s
 
78
    )
 
79
 
 
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
 
86
 
 
87
  method lexeme =
 
88
    Lexing.lexeme lexbuf
 
89
 
 
90
  method lexeme_strlen =
 
91
    Pxp_lexing.lexeme_len lexbuf
 
92
 
 
93
  method sub_lexeme pos len =
 
94
    if Netconversion.is_single_byte `Enc_${encoding} then (
 
95
      Pxp_lexing.sub_lexeme lexbuf pos len
 
96
    )
 
97
    else (
 
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
 
102
    )
 
103
 
 
104
    
 
105
  method scan_document =
 
106
    fun () -> 
 
107
      ${scan_document}.scan_document (self : #lexer_obj :> lexer_obj) lexbuf
 
108
 
 
109
  method scan_content =
 
110
    fun () -> 
 
111
      ${scan_content}.scan_content (self : #lexer_obj :> lexer_obj) lexbuf
 
112
 
 
113
  method scan_within_tag = 
 
114
    fun () -> 
 
115
      ${scan_within_tag}.scan_within_tag
 
116
        (self : #lexer_obj :> lexer_obj) lexbuf
 
117
 
 
118
  method scan_document_type = 
 
119
    fun () -> 
 
120
      ${scan_document_type}.scan_document_type
 
121
        (self : #lexer_obj :> lexer_obj) lexbuf
 
122
    
 
123
  method scan_declaration = 
 
124
    fun () -> 
 
125
      ${scan_declaration}.scan_declaration 
 
126
        (self : #lexer_obj :> lexer_obj) lexbuf
 
127
    
 
128
  method scan_comment = 
 
129
    fun () -> 
 
130
      ${scan_comment}.scan_comment (self : #lexer_obj :> lexer_obj) lexbuf
 
131
 
 
132
  method scan_ignored_section = 
 
133
    fun () -> 
 
134
      ${scan_ignored_section}.scan_ignored_section
 
135
        (self : #lexer_obj :> lexer_obj) lexbuf
 
136
 
 
137
  method detect_xml_pi = 
 
138
    fun () -> 
 
139
      ${detect_xml_pi}.detect_xml_pi (self : #lexer_obj :> lexer_obj) lexbuf
 
140
 
 
141
  method scan_xml_pi = 
 
142
    fun () -> 
 
143
      ${scan_xml_pi}.scan_xml_pi (self : #lexer_obj :> lexer_obj) lexbuf
 
144
 
 
145
  method scan_pi_string = 
 
146
    fun () -> 
 
147
      ${scan_pi_string}.scan_pi_string (self : #lexer_obj :> lexer_obj) lexbuf
 
148
 
 
149
  method scan_dtd_string = 
 
150
    fun () -> 
 
151
      ${scan_dtd_string}.scan_dtd_string (self : #lexer_obj :> lexer_obj) lexbuf
 
152
 
 
153
  method scan_content_string = 
 
154
    fun () -> 
 
155
      ${scan_content_string}.scan_content_string
 
156
        (self : #lexer_obj :> lexer_obj) lexbuf
 
157
 
 
158
  method scan_name_string =
 
159
    fun () -> 
 
160
      ${scan_name_string}.scan_name_string
 
161
        (self : #lexer_obj :> lexer_obj) lexbuf
 
162
 
 
163
  method scan_for_crlf = 
 
164
    fun () -> 
 
165
      ${scan_for_crlf}.scan_for_crlf (self : #lexer_obj :> lexer_obj) lexbuf
 
166
 
 
167
  method scan_characters = 
 
168
    fun () -> 
 
169
      ${scan_characters}.scan_characters (self : #lexer_obj :> lexer_obj) lexbuf
 
170
 
 
171
  method scan_character = 
 
172
    fun () -> 
 
173
      ${scan_character}.scan_character (self : #lexer_obj :> lexer_obj) lexbuf
 
174
 
 
175
  method scan_tag_eb = 
 
176
    fun () -> 
 
177
      ${scan_tag_eb}.scan_tag_eb (self : #lexer_obj :> lexer_obj) lexbuf
 
178
 
 
179
  method scan_tag_eb_att = 
 
180
    fun () -> 
 
181
      ${scan_tag_eb_att}.scan_tag_eb_att (self : #lexer_obj :> lexer_obj) lexbuf
 
182
 
 
183
end
 
184
;;
 
185
 
 
186
 
 
187
Pxp_lexers.init (new lfactory)
 
188
;;
 
189
 
 
190
 
 
191
(* [END] *)
 
192