mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
LibWeb: Move CSS TokenStream to its own file
This lets us use TokenStream in StyleComputer without every user of StyleComputer pulling in the entire CSS Parser.
This commit is contained in:
parent
bf6d5fce18
commit
8ce38fddd9
Notes:
sideshowbarker
2024-07-17 06:35:08 +09:00
Author: https://github.com/AtkinsSJ
Commit: 8ce38fddd9
Pull-request: https://github.com/SerenityOS/serenity/pull/15378
3 changed files with 140 additions and 146 deletions
|
@ -81,87 +81,6 @@ AK::URL ParsingContext::complete_url(String const& addr) const
|
|||
return m_url.complete_url(addr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
TokenStream<T>::TokenStream(Vector<T> const& tokens)
|
||||
: m_tokens(tokens)
|
||||
, m_eof(make_eof())
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool TokenStream<T>::has_next_token()
|
||||
{
|
||||
return (size_t)(m_iterator_offset + 1) < m_tokens.size();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T const& TokenStream<T>::peek_token(int offset)
|
||||
{
|
||||
if (!has_next_token())
|
||||
return m_eof;
|
||||
|
||||
return m_tokens.at(m_iterator_offset + offset + 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T const& TokenStream<T>::next_token()
|
||||
{
|
||||
if (!has_next_token())
|
||||
return m_eof;
|
||||
|
||||
++m_iterator_offset;
|
||||
|
||||
return m_tokens.at(m_iterator_offset);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T const& TokenStream<T>::current_token()
|
||||
{
|
||||
if ((size_t)m_iterator_offset >= m_tokens.size())
|
||||
return m_eof;
|
||||
|
||||
return m_tokens.at(m_iterator_offset);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TokenStream<T>::reconsume_current_input_token()
|
||||
{
|
||||
if (m_iterator_offset >= 0)
|
||||
--m_iterator_offset;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TokenStream<T>::skip_whitespace()
|
||||
{
|
||||
while (peek_token().is(Token::Type::Whitespace))
|
||||
next_token();
|
||||
}
|
||||
|
||||
template<>
|
||||
Token TokenStream<Token>::make_eof()
|
||||
{
|
||||
return Tokenizer::create_eof_token();
|
||||
}
|
||||
|
||||
template<>
|
||||
ComponentValue TokenStream<ComponentValue>::make_eof()
|
||||
{
|
||||
return ComponentValue(Tokenizer::create_eof_token());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TokenStream<T>::dump_all_tokens()
|
||||
{
|
||||
dbgln("Dumping all tokens:");
|
||||
for (size_t i = 0; i < m_tokens.size(); ++i) {
|
||||
auto& token = m_tokens[i];
|
||||
if ((i - 1) == (size_t)m_iterator_offset)
|
||||
dbgln("-> {}", token.to_debug_string());
|
||||
else
|
||||
dbgln(" {}", token.to_debug_string());
|
||||
}
|
||||
}
|
||||
|
||||
Parser::Parser(ParsingContext const& context, StringView input, String const& encoding)
|
||||
: m_context(context)
|
||||
, m_tokenizer(input, encoding)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue