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

Propone updating the scanner->state until incompleteness has been checked

That way the scanner state is meaningful when resuming during incremental
parsing.
This commit is contained in:
Jonas Fonseca 2006-01-27 07:41:42 +01:00 committed by Jonas Fonseca
parent c18740b30d
commit 9d91994f3c

View File

@ -439,6 +439,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
enum sgml_token_type type = SGML_TOKEN_GARBAGE; enum sgml_token_type type = SGML_TOKEN_GARBAGE;
int real_length = -1; int real_length = -1;
int possibly_incomplete = 1; int possibly_incomplete = 1;
enum sgml_scanner_state scanner_state = scanner->state;
token->string.string = string++; token->string.string = string++;
@ -451,7 +452,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
string--; string--;
real_length = 0; real_length = 0;
type = SGML_TOKEN_TAG_END; type = SGML_TOKEN_TAG_END;
scanner->state = SGML_STATE_TEXT; scanner_state = SGML_STATE_TEXT;
/* We are creating a 'virtual' that has no source. */ /* We are creating a 'virtual' that has no source. */
possibly_incomplete = 0; possibly_incomplete = 0;
@ -476,8 +477,8 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
/* We found the end. */ /* We found the end. */
possibly_incomplete = 0; possibly_incomplete = 0;
} }
scanner->state = SGML_STATE_ELEMENT;
type = SGML_TOKEN_ELEMENT_BEGIN; type = SGML_TOKEN_ELEMENT_BEGIN;
scanner_state = SGML_STATE_ELEMENT;
} }
} else if (*string == '!') { } else if (*string == '!') {
@ -527,7 +528,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
type = map_dom_scanner_string(scanner, pos, string, base); type = map_dom_scanner_string(scanner, pos, string, base);
scanner->state = SGML_STATE_PROC_INST; scanner_state = SGML_STATE_PROC_INST;
real_length = string - token->string.string; real_length = string - token->string.string;
skip_sgml_space(scanner, &string); skip_sgml_space(scanner, &string);
@ -563,8 +564,9 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
possibly_incomplete = 0; possibly_incomplete = 0;
} }
if (type != SGML_TOKEN_GARBAGE) if (type != SGML_TOKEN_GARBAGE) {
scanner->state = SGML_STATE_TEXT; scanner_state = SGML_STATE_TEXT;
}
} else { } else {
/* Alien < > stuff so ignore it */ /* Alien < > stuff so ignore it */
@ -594,7 +596,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
type = SGML_TOKEN_TAG_END; type = SGML_TOKEN_TAG_END;
assert(scanner->state == SGML_STATE_ELEMENT); assert(scanner->state == SGML_STATE_ELEMENT);
scanner->state = SGML_STATE_TEXT; scanner_state = SGML_STATE_TEXT;
} else if (first_char == '/') { } else if (first_char == '/') {
/* We allow '/' inside elements and only consider it as an end /* We allow '/' inside elements and only consider it as an end
@ -611,7 +613,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
real_length = 0; real_length = 0;
type = SGML_TOKEN_ELEMENT_EMPTY_END; type = SGML_TOKEN_ELEMENT_EMPTY_END;
assert(scanner->state == SGML_STATE_ELEMENT); assert(scanner->state == SGML_STATE_ELEMENT);
scanner->state = SGML_STATE_TEXT; scanner_state = SGML_STATE_TEXT;
/* We found the end. */ /* We found the end. */
possibly_incomplete = 0; possibly_incomplete = 0;
@ -678,6 +680,10 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
} }
} }
/* Only apply the state change if the token was not abandoned because
* it was incomplete. */
scanner->state = scanner_state;
token->type = type; token->type = type;
token->string.length = real_length >= 0 ? real_length : string - token->string.string; token->string.length = real_length >= 0 ? real_length : string - token->string.string;
token->precedence = get_sgml_precedence(type); token->precedence = get_sgml_precedence(type);