i = 0;
string_lexer_init (&slex, s, strlen (s), SEG_MODE_INTERACTIVE, true);
while (string_lexer_next (&slex, &token))
- if (token.type != SCAN_SKIP)
- {
- bool match = lex_tokens_match (lex_next (lexer, i++), &token);
- token_uninit (&token);
- if (!match)
- return false;
- }
+ {
+ bool match = lex_tokens_match (lex_next (lexer, i++), &token);
+ token_uninit (&token);
+ if (!match)
+ return false;
+ }
while (i-- > 0)
lex_get (lexer);
/* Extract segments and pass them through the scanner until we obtain a
token. */
+ enum scan_result result;
for (;;)
{
/* Extract a segment. */
}
/* Pass the segment into the scanner and try to get a token out. */
- enum scan_result result = scanner_push (&scanner, type,
- ss_buffer (segment, seg_len),
- &token->token);
+ result = scanner_push (&scanner, type, ss_buffer (segment, seg_len),
+ &token->token);
if (result == SCAN_SAVE)
saved = state;
else if (result == SCAN_BACK)
state = saved;
break;
}
- else if (result == SCAN_DONE)
+ else if (result == SCAN_DONE
+ || result == SCAN_EMPTY
+ || result == SCAN_ERROR)
break;
}
src->line_pos = state.line_pos;
src->n_newlines += state.newlines;
- switch (token->token.type)
+ if (result == SCAN_EMPTY)
+ {
+ lex_source_pop_front (src);
+ return false;
+ }
+ else if (result == SCAN_ERROR)
+ {
+ lex_get_error (src, token->token.string.string);
+ return false;
+ }
+ else if (token->token.type == T_STOP)
{
- default:
- return true;
-
- case T_STOP:
token->token.type = T_ENDCMD;
src->eof = true;
return true;
-
- case SCAN_BAD_HEX_LENGTH:
- case SCAN_BAD_HEX_DIGIT:
- case SCAN_BAD_UNICODE_DIGIT:
- case SCAN_BAD_UNICODE_LENGTH:
- case SCAN_BAD_UNICODE_CODE_POINT:
- case SCAN_EXPECTED_QUOTE:
- case SCAN_EXPECTED_EXPONENT:
- case SCAN_UNEXPECTED_CHAR:
- {
- char *msg = scan_token_to_error (&token->token);
- lex_get_error (src, msg);
- free (msg);
- return false;
- }
-
- case SCAN_SKIP:
- lex_source_pop_front (src);
- return false;
}
-
- NOT_REACHED ();
+ else
+ return true;
}
/* Attempts to add a new token at the front of SRC. Returns true if