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

« back to all changes in this revision

Viewing changes to src/pxp-engine/pxp_lexer_types.ml

  • 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: pxp_lexer_types.ml,v 1.6 2002/03/13 22:45:42 gerd Exp $
 
1
(* $Id: pxp_lexer_types.ml 707 2004-09-04 17:25:35Z gerd $
2
2
 * ----------------------------------------------------------------------
3
3
 * PXP: The polymorphic XML parser for Objective Caml.
4
4
 * Copyright by Gerd Stolpmann. See LICENSE for details.
9
9
  | Document_type
10
10
  | Content
11
11
  | Within_tag
 
12
  | Within_tag_entry
12
13
  | Declaration
13
 
  | Content_comment
14
 
  | Decl_comment
15
 
  | Document_comment
 
14
  | Comment of lexers
16
15
  | Ignored_section
 
16
  | Closed
 
17
  | Tag_eb
 
18
  | Tag_eb_att of bool
 
19
 
 
20
 
 
21
let rec string_of_lexers =
 
22
  function
 
23
      Document          -> "Document"
 
24
    | Document_type     -> "Document_type"
 
25
    | Content           -> "Content"
 
26
    | Within_tag        -> "Within_tag"
 
27
    | Within_tag_entry  -> "Within_tag_entry"
 
28
    | Declaration       -> "Declaration"
 
29
    | Comment lexid     -> ("Comment/" ^ string_of_lexers lexid)
 
30
    | Ignored_section   -> "Ignored_section"
 
31
    | Closed            -> "Closed"
 
32
    | Tag_eb            -> "Tag_eb"
 
33
    | Tag_eb_att b      -> "Tag_eb_att " ^ string_of_bool b
 
34
;;
17
35
 
18
36
 
19
37
type prolog_token =
72
90
  | Tag_beg of (string*entity_id)     (* <name *)
73
91
  | Tag_end of (string*entity_id)     (* </name *)
74
92
 
75
 
  | PI        of (string*string)      (* <?name ... ?> *)
 
93
  | PI        of (string*string*entity_id)      (* <?name ... ?> *)
76
94
  | PI_xml    of (prolog_token list)  (* <?xml ...?> *)
77
95
  | Cdata     of string               (* <![CDATA[...]]> *)
78
96
  | CRef      of int                  (* &#digits; *)
79
97
  | ERef      of string               (* &name; *)
80
98
  | PERef     of string               (* %name; *)
81
99
  | CharData  of string             (* any characters not otherwise matching *)
 
100
  | Lcurly                            (* { *)
 
101
  | LLcurly                           (* {{ *)
 
102
  | Rcurly                            (* } *)
 
103
  | RRcurly                           (* }} *)
82
104
  | LineEnd   of string
 
105
  | LineEnd_att   of string
83
106
  | Name      of string               (* name *)
84
107
  | Nametoken of string               (* nmtoken but not name *)
85
108
  | Attval    of string           (* attribute value; may contain entity refs *)
86
109
  | Attval_nl_normalized of string
87
110
  | Unparsed_string      of string    (* "data" or 'data' *)
88
 
      
 
111
  | SQuote                            (* Single quote *)
 
112
  | DQuote                            (* Double quote *)
 
113
  | ERef_att of string                (* &name; in attribute values *)
 
114
 
89
115
 
90
116
(**********************************************************************)
91
117
(* debugging *)
146
172
  | Attval_nl_normalized _ -> "Attval_nl_normalized"
147
173
  | Unparsed_string _ -> "Unparsed_string" 
148
174
  | LineEnd _ -> "LineEnd"
 
175
  | LineEnd_att _ -> "LineEnd_att"
 
176
  | Lcurly -> "Lcurly"
 
177
  | LLcurly -> "LLcurly"
 
178
  | Rcurly -> "Rcurly"
 
179
  | RRcurly -> "RRcurly"
 
180
  | SQuote -> "SQuote"
 
181
  | DQuote -> "DQuote"
 
182
  | ERef_att _ -> "ERef_att"
 
183
 
 
184
class type lexer_factory =
 
185
object
 
186
  method encoding : Pxp_core_types.rep_encoding
 
187
  method open_source : Pxp_reader.lexer_source -> lexer_obj
 
188
  method open_string : string -> lexer_obj
 
189
  method open_string_inplace : string -> lexer_obj
 
190
end
 
191
 
 
192
and lexer_obj =
 
193
object
 
194
  method factory : lexer_factory
 
195
  method encoding : Pxp_core_types.rep_encoding
 
196
  method open_source : Pxp_reader.lexer_source -> unit
 
197
  method open_string : string -> unit
 
198
  method open_string_inplace : string -> unit
 
199
 
 
200
  method scan_document        : unit -> (token * lexers)
 
201
  method scan_content         : unit -> (token * lexers)
 
202
  method scan_within_tag      : unit -> (token * lexers)
 
203
  method scan_document_type   : unit -> (token * lexers)
 
204
  method scan_declaration     : unit -> (token * lexers)
 
205
  method scan_comment         : unit -> lexers -> (token * lexers)
 
206
  method scan_ignored_section : unit -> (token * lexers)
 
207
  method detect_xml_pi        : unit -> bool
 
208
  method scan_xml_pi          : unit -> prolog_token
 
209
  method scan_pi_string       : unit -> string option
 
210
  method scan_dtd_string      : unit -> token
 
211
  method scan_content_string  : unit -> token
 
212
  method scan_name_string     : unit -> token
 
213
  method scan_for_crlf        : unit -> token
 
214
  method scan_characters      : unit -> unit
 
215
  method scan_character       : unit -> unit
 
216
  method scan_tag_eb          : unit -> (token * lexers)
 
217
  method scan_tag_eb_att      : unit -> bool -> (token * lexers)
 
218
 
 
219
  method lexeme_length : int
 
220
  method lexeme_char : int -> int
 
221
  method lexeme : string
 
222
  method lexeme_strlen : int
 
223
  method sub_lexeme : int -> int -> string
 
224
end
149
225
 
150
226
 
151
227
type lexer_set =
152
 
    { lex_encoding         : Pxp_types.rep_encoding;
153
 
      scan_document        : Lexing.lexbuf -> (token * lexers);
154
 
      scan_content         : Lexing.lexbuf -> (token * lexers);
155
 
      scan_within_tag      : Lexing.lexbuf -> (token * lexers);
156
 
      scan_document_type   : Lexing.lexbuf -> (token * lexers);
157
 
      scan_declaration     : Lexing.lexbuf -> (token * lexers);
158
 
      scan_content_comment : Lexing.lexbuf -> (token * lexers);
159
 
      scan_decl_comment    : Lexing.lexbuf -> (token * lexers);
160
 
      scan_document_comment: Lexing.lexbuf -> (token * lexers);
161
 
      scan_ignored_section : Lexing.lexbuf -> (token * lexers);
162
 
      scan_xml_pi          : Lexing.lexbuf -> prolog_token;
163
 
      scan_dtd_string      : Lexing.lexbuf -> token;
164
 
      scan_content_string  : Lexing.lexbuf -> token;
165
 
      scan_name_string     : Lexing.lexbuf -> token;
166
 
      scan_only_xml_decl   : Lexing.lexbuf -> token;
167
 
      scan_for_crlf        : Lexing.lexbuf -> token;
168
 
    }
169
 
 
170
 
(* ======================================================================
171
 
 * History:
172
 
 * 
173
 
 * $Log: pxp_lexer_types.ml,v $
174
 
 * Revision 1.6  2002/03/13 22:45:42  gerd
175
 
 *      Improved Pxp_lexing.
176
 
 *
177
 
 * Revision 1.5  2001/06/28 22:42:07  gerd
178
 
 *      Fixed minor problems:
179
 
 *      - Comments must be contained in one entity
180
 
 *      - Pxp_document.document is now initialized with encoding.
181
 
 *           the DTD encoding may be initialized too late.
182
 
 *
183
 
 * Revision 1.4  2000/10/01 19:47:53  gerd
184
 
 *      New functions: sub_lexeme, fast_lexing_from_string,
185
 
 * reuse_lexing_from_string.
186
 
 *
187
 
 * Revision 1.3  2000/09/21 21:28:16  gerd
188
 
 *      New token IgnoreLineEnd: simplifies line counting, and
189
 
 * corrects a bug.
190
 
 *
191
 
 * Revision 1.2  2000/08/18 20:14:31  gerd
192
 
 *      Comment -> Comment_begin, Comment_material, Comment_end.
193
 
 *
194
 
 * Revision 1.1  2000/05/29 23:48:38  gerd
195
 
 *      Changed module names:
196
 
 *              Markup_aux          into Pxp_aux
197
 
 *              Markup_codewriter   into Pxp_codewriter
198
 
 *              Markup_document     into Pxp_document
199
 
 *              Markup_dtd          into Pxp_dtd
200
 
 *              Markup_entity       into Pxp_entity
201
 
 *              Markup_lexer_types  into Pxp_lexer_types
202
 
 *              Markup_reader       into Pxp_reader
203
 
 *              Markup_types        into Pxp_types
204
 
 *              Markup_yacc         into Pxp_yacc
205
 
 * See directory "compatibility" for (almost) compatible wrappers emulating
206
 
 * Markup_document, Markup_dtd, Markup_reader, Markup_types, and Markup_yacc.
207
 
 *
208
 
 * ======================================================================
209
 
 * Old logs from markup_lexer_types.ml:
210
 
 *
211
 
 * Revision 1.6  2000/05/29 21:14:57  gerd
212
 
 *      Changed the type 'encoding' into a polymorphic variant.
213
 
 *
214
 
 * Revision 1.5  2000/05/20 20:31:40  gerd
215
 
 *      Big change: Added support for various encodings of the
216
 
 * internal representation.
217
 
 *
218
 
 * Revision 1.4  2000/05/14 17:45:36  gerd
219
 
 *      Bugfix.
220
 
 *
221
 
 * Revision 1.3  2000/05/14 17:35:12  gerd
222
 
 *      Conditional_begin, _end, and _body have an entity_id.
223
 
 *
224
 
 * Revision 1.2  2000/05/08 21:59:06  gerd
225
 
 *      New token Bof (beginning of file).
226
 
 *
227
 
 * Revision 1.1  2000/05/06 23:21:49  gerd
228
 
 *      Initial revision.
229
 
 *
230
 
 *
231
 
 * ======================================================================
232
 
 *
233
 
 * DERIVED FROM REVISION 1.4 of markup_lexer_types_shadow.ml
234
 
 *
235
 
 * Revision 1.4  2000/04/30 18:19:04  gerd
236
 
 *      Added new tokens.
237
 
 *
238
 
 * Revision 1.3  1999/08/31 19:13:31  gerd
239
 
 *      Added checks on proper PE nesting. The idea is that tokens such
240
 
 * as Decl_element and Decl_rangle carry an entity ID with them. This ID
241
 
 * is simply an object of type < >, i.e. you can only test on identity.
242
 
 * The lexer always produces tokens with a dummy ID because it does not
243
 
 * know which entity is the current one. The entity layer replaces the dummy
244
 
 * ID with the actual ID. The parser checks that the IDs of pairs such as
245
 
 * Decl_element and Decl_rangle are the same; otherwise a Validation_error
246
 
 * is produced.
247
 
 *
248
 
 * Revision 1.2  1999/08/10 21:35:08  gerd
249
 
 *      The XML/encoding declaration at the beginning of entities is
250
 
 * evaluated. In particular, entities have now a method "xml_declaration"
251
 
 * which returns the name/value pairs of such a declaration. The "encoding"
252
 
 * setting is interpreted by the entity itself; "version", and "standalone"
253
 
 * are interpreted by Markup_yacc.parse_document_entity. Other settings
254
 
 * are ignored (this does not conform to the standard; the standard prescribes
255
 
 * that "version" MUST be given in the declaration of document; "standalone"
256
 
 * and "encoding" CAN be declared; no other settings are allowed).
257
 
 *      TODO: The user should be warned if the standard is not exactly
258
 
 * fulfilled. -- The "standalone" property is not checked yet.
259
 
 *
260
 
 * Revision 1.1  1999/08/10 00:35:51  gerd
261
 
 *      Initial revision.
262
 
 *
263
 
 * 
264
 
 *)
 
228
    { scan_name_string : Lexing.lexbuf -> token }
 
229
  (* DEPRECATED. Only exists because WDialog needs it. *)