1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Introduce sgml_parser_type for specifying tree and streaming parsers

Mostly added for the future, since currently only one parser type is
supported.
This commit is contained in:
Jonas Fonseca 2005-12-05 11:19:13 +01:00 committed by Jonas Fonseca
parent 05a61cd16a
commit 4c8d871404
3 changed files with 19 additions and 3 deletions

View File

@ -700,7 +700,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
assert(document->options.plain);
parser = init_sgml_parser(cached, document);
parser = init_sgml_parser(SGML_PARSER_STREAM, cached, document);
if (!parser) return;
root = parse_sgml(parser, buffer);

View File

@ -297,7 +297,8 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
struct sgml_parser *
init_sgml_parser(struct cache_entry *cached, struct document *document)
init_sgml_parser(enum sgml_parser_type type, struct cache_entry *cached,
struct document *document)
{
size_t obj_size = sizeof(struct sgml_parser_state);
struct sgml_parser *parser;
@ -305,6 +306,7 @@ init_sgml_parser(struct cache_entry *cached, struct document *document)
parser = mem_calloc(1, sizeof(*parser));
if (!parser) return NULL;
parser->type = type;
parser->document = document;
parser->cache_entry = cached;
parser->info = &sgml_html_info;

View File

@ -11,11 +11,24 @@ struct cache_entry;
struct document;
struct string;
enum sgml_parser_type {
/* The first one is a DOM tree builder. */
SGML_PARSER_TREE,
/* The second one will simply push nodes on the stack, not building a
* DOM tree. This interface is similar to that of SAX (Simple API for
* XML) where events are fired when nodes are entered and exited. It is
* useful when you are not actually interested in the DOM tree, but can
* do all processing in a stream-like manner, such as when highlighting
* HTML code. */
SGML_PARSER_STREAM,
};
enum sgml_parser_flags {
SGML_PARSER_ADD_ELEMENT_ENDS = 1,
};
struct sgml_parser {
enum sgml_parser_type type;
/* The parser flags controls what gets added to the DOM tree */
enum sgml_parser_flags flags;
struct sgml_info *info;
@ -33,7 +46,8 @@ struct sgml_parser_state {
};
struct sgml_parser *
init_sgml_parser(struct cache_entry *cached, struct document *document);
init_sgml_parser(enum sgml_parser_type type,
struct cache_entry *cached, struct document *document);
void done_sgml_parser(struct sgml_parser *parser);