1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

AK+LibXML+JSSpecCompiler: Move LineTrackingLexer to AK

This is a simple extension of GenericLexer, and is used in more than
just LibXML, so let's move it into AK.
The move also resolves a FIXME, which is removed in this commit.
This commit is contained in:
Ali Mohammad Pur 2024-02-16 04:55:17 +03:30 committed by Andreas Kling
parent 08c02ad888
commit bc301b6f40
8 changed files with 79 additions and 78 deletions

View file

@ -234,6 +234,34 @@ private:
#endif
};
class LineTrackingLexer : public GenericLexer {
public:
using GenericLexer::GenericLexer;
struct Position {
size_t offset { 0 };
size_t line { 0 };
size_t column { 0 };
};
LineTrackingLexer(StringView input, Position start_position)
: GenericLexer(input)
, m_cached_position {
.line = start_position.line,
.column = start_position.column,
}
{
}
Position cached_position() const { return m_cached_position; }
void restore_cached_offset(Position cached_position) { m_cached_position = cached_position; }
Position position_for(size_t) const;
Position current_position() const { return position_for(m_index); }
protected:
mutable Position m_cached_position;
};
constexpr auto is_any_of(StringView values)
{
return [values](auto c) { return values.contains(c); };
@ -254,4 +282,5 @@ using AK::GenericLexer;
using AK::is_any_of;
using AK::is_path_separator;
using AK::is_quote;
using AK::LineTrackingLexer;
#endif