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

Add code member to struct sgml_parser and simplify parsing state setup

parse_sgml() now just pushes a text node on the parsing state and the push
handler will now call parse_sgml_plain() and save the return code in
parser->code so parse_sgml() can return it. Much simpler.
This commit is contained in:
Jonas Fonseca 2006-01-14 12:09:17 +01:00 committed by Jonas Fonseca
parent b9316b3a9c
commit e70b779366
2 changed files with 7 additions and 27 deletions

View File

@ -29,10 +29,6 @@ struct sgml_parsing_state {
size_t depth;
};
static struct sgml_parsing_state *
init_sgml_parsing_state(struct sgml_parser *parser, struct dom_string *buffer);
/* When getting the sgml_parser struct it is _always_ assumed that the parser
* is the first to add it's context, which it is since it initializes the
* stack. */
@ -404,8 +400,7 @@ parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize,
int complete)
{
struct dom_string source = INIT_DOM_STRING(buf, bufsize);
struct sgml_parsing_state *parsing;
enum sgml_parser_code code;
struct dom_node *node;
if (complete)
parser->flags |= SGML_PARSER_COMPLETE;
@ -417,14 +412,13 @@ parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize,
get_dom_stack_top(&parser->stack)->immutable = 1;
}
parsing = init_sgml_parsing_state(parser, &source);
if (!parsing) return SGML_PARSER_CODE_MEM_ALLOC;
code = parse_sgml_plain(&parser->stack, &parsing->scanner);
node = init_dom_node(DOM_NODE_TEXT, &source);
if (!node || !push_dom_node(&parser->parsing, node))
return SGML_PARSER_CODE_MEM_ALLOC;
pop_dom_node(&parser->parsing);
return code;
return parser->code;
}
@ -450,6 +444,7 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
init_dom_scanner(&parsing->scanner, &sgml_scanner_info, &node->string,
SGML_STATE_TEXT, count_lines, complete, incremental,
detect_errors);
parser->code = parse_sgml_plain(&parser->stack, &parsing->scanner);
}
static void
@ -504,22 +499,6 @@ static struct dom_stack_context_info sgml_parsing_context_info = {
}
};
/* Create a new parsing state by pushing a new text node containing the*/
static struct sgml_parsing_state *
init_sgml_parsing_state(struct sgml_parser *parser, struct dom_string *buffer)
{
struct dom_stack_state *state;
struct dom_node *node;
node = init_dom_node(DOM_NODE_TEXT, buffer);
if (!node || !push_dom_node(&parser->parsing, node))
return NULL;
state = get_dom_stack_top(&parser->parsing);
return get_dom_stack_state_data(parser->parsing.contexts[0], state);
}
unsigned int
get_sgml_parser_line_number(struct sgml_parser *parser)
{

View File

@ -101,6 +101,7 @@ struct sgml_parser {
struct dom_string uri; /*: The URI of the DOM document */
struct dom_node *root; /*: The document root node */
enum sgml_parser_code code; /*: The latest (error) code */
sgml_error_T error_func; /*: Called for detected errors */
struct dom_stack stack; /*: A stack for tracking parsed nodes */