mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibWeb: Add TokenStream::rewind_to_position()
Parsing media queries sometimes requires significant back-tracking, so `reconsume_current_input_token()` was not good enough. `rewind_to_position()` lets you reconsume an erbitrary number of tokens to return to an earlier point in the stream, which you previously saved from `TokenStream::position()`.
This commit is contained in:
parent
c7cd489689
commit
2ed0f880ee
2 changed files with 10 additions and 0 deletions
|
@ -106,6 +106,13 @@ void TokenStream<T>::reconsume_current_input_token()
|
|||
--m_iterator_offset;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TokenStream<T>::rewind_to_position(int position)
|
||||
{
|
||||
VERIFY(position <= m_iterator_offset);
|
||||
m_iterator_offset = position;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TokenStream<T>::skip_whitespace()
|
||||
{
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
T const& current_token();
|
||||
void reconsume_current_input_token();
|
||||
|
||||
int position() const { return m_iterator_offset; }
|
||||
void rewind_to_position(int);
|
||||
|
||||
void skip_whitespace();
|
||||
|
||||
void dump_all_tokens();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue