1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

Make parse_sgml() return the sgml_parser_code enum

It is mostly just ignored for now. The SGML parser test tool will however
return parser code.
This commit is contained in:
Jonas Fonseca 2006-01-02 17:40:42 +01:00 committed by Jonas Fonseca
parent 29279e71b7
commit af72dd8435
4 changed files with 27 additions and 21 deletions

View File

@ -665,7 +665,6 @@ render_dom_document(struct cache_entry *cached, struct document *document,
struct string *buffer) struct string *buffer)
{ {
unsigned char *head = empty_string_or_(cached->head); unsigned char *head = empty_string_or_(cached->head);
struct dom_node *root;
struct dom_renderer renderer; struct dom_renderer renderer;
struct conv_table *convert_table; struct conv_table *convert_table;
struct sgml_parser *parser; struct sgml_parser *parser;
@ -674,6 +673,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
size_t length = strlen(string); size_t length = strlen(string);
struct dom_string uri = INIT_DOM_STRING(string, length); struct dom_string uri = INIT_DOM_STRING(string, length);
struct dom_string source = INIT_DOM_STRING(buffer->source, buffer->length); struct dom_string source = INIT_DOM_STRING(buffer->source, buffer->length);
enum sgml_parser_code code;
assert(document->options.plain); assert(document->options.plain);
@ -713,8 +713,12 @@ render_dom_document(struct cache_entry *cached, struct document *document,
add_dom_stack_context(&parser->stack, &renderer, add_dom_stack_context(&parser->stack, &renderer,
&dom_source_renderer_context_info); &dom_source_renderer_context_info);
root = parse_sgml(parser, &source, 1); /* FIXME: When rendering this way we don't really care about the code.
if (root) { * However, it will be useful when we will be able to also
* incrementally parse new data. This will require the parser to live
* during the fetching of data. */
code = parse_sgml(parser, &source, 1);
if (parser->root) {
assert(parser->stack.depth == 1); assert(parser->stack.depth == 1);
get_dom_stack_top(&parser->stack)->immutable = 0; get_dom_stack_top(&parser->stack)->immutable = 0;

View File

@ -154,15 +154,6 @@ add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scann
/* SGML parser main handling: */ /* SGML parser main handling: */
enum sgml_parser_code {
SGML_PARSER_CODE_OK, /* The parsing was successful */
SGML_PARSER_CODE_INCOMPLETE, /* The parsing could not be completed */
/* FIXME: For when we will add support for requiring stricter parsing
* or even a validator. */
SGML_PARSER_CODE_ERROR,
};
static inline enum sgml_parser_code static inline enum sgml_parser_code
parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
{ {
@ -361,7 +352,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
return SGML_PARSER_CODE_OK; return SGML_PARSER_CODE_OK;
} }
struct dom_node * enum sgml_parser_code
parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete) parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete)
{ {
struct sgml_parsing_state *parsing; struct sgml_parsing_state *parsing;
@ -373,18 +364,18 @@ parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete)
if (!parser->root) { if (!parser->root) {
parser->root = add_sgml_document(&parser->stack, &parser->uri); parser->root = add_sgml_document(&parser->stack, &parser->uri);
if (!parser->root) if (!parser->root)
return NULL; return SGML_PARSER_CODE_MEM_ALLOC;
get_dom_stack_top(&parser->stack)->immutable = 1; get_dom_stack_top(&parser->stack)->immutable = 1;
} }
parsing = init_sgml_parsing_state(parser, buffer); parsing = init_sgml_parsing_state(parser, buffer);
if (!parsing) return NULL; if (!parsing) return SGML_PARSER_CODE_MEM_ALLOC;
code = parse_sgml_plain(&parser->stack, &parsing->scanner); code = parse_sgml_plain(&parser->stack, &parsing->scanner);
pop_dom_node(&parser->parsing); pop_dom_node(&parser->parsing);
return parser->root; return code;
} }

View File

@ -25,6 +25,7 @@ enum sgml_parser_type {
enum sgml_parser_flag { enum sgml_parser_flag {
SGML_PARSER_COUNT_LINES = 1, SGML_PARSER_COUNT_LINES = 1,
SGML_PARSER_COMPLETE = 2, SGML_PARSER_COMPLETE = 2,
SGML_PARSER_INCREMENTAL = 4,
}; };
struct sgml_parser_state { struct sgml_parser_state {
@ -56,7 +57,17 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
void done_sgml_parser(struct sgml_parser *parser); void done_sgml_parser(struct sgml_parser *parser);
struct dom_node * enum sgml_parser_code {
SGML_PARSER_CODE_OK, /* The parsing was successful */
SGML_PARSER_CODE_INCOMPLETE, /* The parsing could not be completed */
SGML_PARSER_CODE_MEM_ALLOC, /* Failed to allocate memory */
/* FIXME: For when we will add support for requiring stricter parsing
* or even a validator. */
SGML_PARSER_CODE_ERROR,
};
enum sgml_parser_code
parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete); parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete);
unsigned int get_sgml_parser_line_number(struct sgml_parser *parser); unsigned int get_sgml_parser_line_number(struct sgml_parser *parser);

View File

@ -236,10 +236,10 @@ void die(const char *msg, ...)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct dom_node *root;
struct sgml_parser *parser; struct sgml_parser *parser;
enum sgml_document_type doctype = SGML_DOCTYPE_HTML; enum sgml_document_type doctype = SGML_DOCTYPE_HTML;
enum sgml_parser_flag flags = 0; enum sgml_parser_flag flags = 0;
enum sgml_parser_code code = 0;
struct dom_string uri = INIT_DOM_STRING("dom://test", -1); struct dom_string uri = INIT_DOM_STRING("dom://test", -1);
struct dom_string source = INIT_DOM_STRING("(no source)", -1); struct dom_string source = INIT_DOM_STRING("(no source)", -1);
int i; int i;
@ -292,8 +292,8 @@ main(int argc, char *argv[])
add_dom_stack_context(&parser->stack, NULL, &sgml_parser_test_context_info); add_dom_stack_context(&parser->stack, NULL, &sgml_parser_test_context_info);
root = parse_sgml(parser, &source, 1); code = parse_sgml(parser, &source, 1);
if (root) { if (parser->root) {
assert(parser->stack.depth == 1); assert(parser->stack.depth == 1);
get_dom_stack_top(&parser->stack)->immutable = 0; get_dom_stack_top(&parser->stack)->immutable = 0;
@ -304,5 +304,5 @@ main(int argc, char *argv[])
done_sgml_parser(parser); done_sgml_parser(parser);
return 0; return code;
} }