mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:34:57 +00:00
AK: Add GenericLexer::retreat()
This allows going back one character at a time, and then re-consume previously consumed chars. The code I need this for looks something like this: ASSERT(lexer.consume_specific('\\')); if (lexer.next_is("foo")) ... lexer.retreat(); lexer.consume_escaped_character(); // This expects lexer.peek() == '\\'
This commit is contained in:
parent
ffd1e4831e
commit
1daa5158eb
2 changed files with 9 additions and 0 deletions
|
@ -76,6 +76,13 @@ bool GenericLexer::next_is(const char* expected) const
|
|||
return true;
|
||||
}
|
||||
|
||||
// Go back to the previous character
|
||||
void GenericLexer::retreat()
|
||||
{
|
||||
ASSERT(m_index > 0);
|
||||
m_index--;
|
||||
}
|
||||
|
||||
// Consume a character and advance the parser index
|
||||
char GenericLexer::consume()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue