mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
AK: Use templates instead of Function for Conditions in the GenericLexer
Since commit 1ec59f28ce
turns the ctype macros
into functions we can now feed them directly to a GenericLexer! This will lead to
removing the ctype adapters that were kind-of excessive boilerplate, but needed as
the Kernel doesn't compile with the LibC.
This commit is contained in:
parent
eef794b8c6
commit
e4da2875c5
2 changed files with 61 additions and 56 deletions
|
@ -75,12 +75,6 @@ bool GenericLexer::next_is(const char* expected) const
|
|||
return true;
|
||||
}
|
||||
|
||||
// Tests the next character against a Condition
|
||||
bool GenericLexer::next_is(Condition condition) const
|
||||
{
|
||||
return condition(peek());
|
||||
}
|
||||
|
||||
// Consume a character and advance the parser index
|
||||
char GenericLexer::consume()
|
||||
{
|
||||
|
@ -154,19 +148,6 @@ StringView GenericLexer::consume_line()
|
|||
return m_input.substring_view(start, length);
|
||||
}
|
||||
|
||||
// Consume and return characters while `condition` returns true
|
||||
StringView GenericLexer::consume_while(Condition condition)
|
||||
{
|
||||
size_t start = m_index;
|
||||
while (!is_eof() && condition(peek()))
|
||||
m_index++;
|
||||
size_t length = m_index - start;
|
||||
|
||||
if (length == 0)
|
||||
return {};
|
||||
return m_input.substring_view(start, length);
|
||||
}
|
||||
|
||||
// Consume and return characters until `stop` is peek'd
|
||||
// The `stop` character is ignored, as it is user-defined
|
||||
StringView GenericLexer::consume_until(char stop)
|
||||
|
@ -199,19 +180,6 @@ StringView GenericLexer::consume_until(const char* stop)
|
|||
return m_input.substring_view(start, length);
|
||||
}
|
||||
|
||||
// Consume and return characters until `condition` return true
|
||||
StringView GenericLexer::consume_until(Condition condition)
|
||||
{
|
||||
size_t start = m_index;
|
||||
while (!is_eof() && !condition(peek()))
|
||||
m_index++;
|
||||
size_t length = m_index - start;
|
||||
|
||||
if (length == 0)
|
||||
return {};
|
||||
return m_input.substring_view(start, length);
|
||||
}
|
||||
|
||||
/*
|
||||
* Consume a string surrounded by single or double quotes. The returned
|
||||
* StringView does not include the quotes. An escape character can be provided
|
||||
|
@ -276,13 +244,6 @@ void GenericLexer::ignore(size_t count)
|
|||
m_index += count;
|
||||
}
|
||||
|
||||
// Ignore characters while `condition` returns true
|
||||
void GenericLexer::ignore_while(Condition condition)
|
||||
{
|
||||
while (!is_eof() && condition(peek()))
|
||||
m_index++;
|
||||
}
|
||||
|
||||
// Ignore characters until `stop` is peek'd
|
||||
// The `stop` character is ignored as it is user-defined
|
||||
void GenericLexer::ignore_until(char stop)
|
||||
|
@ -303,14 +264,6 @@ void GenericLexer::ignore_until(const char* stop)
|
|||
ignore(__builtin_strlen(stop));
|
||||
}
|
||||
|
||||
// Ignore characters until `condition` return true
|
||||
// We don't skip the stop character as it may not be a unique value
|
||||
void GenericLexer::ignore_until(Condition condition)
|
||||
{
|
||||
while (!is_eof() && !condition(peek()))
|
||||
m_index++;
|
||||
}
|
||||
|
||||
// CType adapters
|
||||
bool is_alpha(char c)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue