LibWeb/CSS: Move Token::Position into SourcePosition
There's nothing about this that's specific to Tokens, and moving it makes it easier to use for other types. We'll need this for the following commits.
This commit is contained in:
parent
18ac54a402
commit
df41e7a1cf
5 changed files with 29 additions and 19 deletions
|
|
@ -102,7 +102,7 @@ static Number::Type css_number_type_from_ffi(FFI::CssNumberType number_type)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
static Token::Position position_from_ffi(size_t line, size_t column)
|
||||
static SourcePosition position_from_ffi(size_t line, size_t column)
|
||||
{
|
||||
return { line, column };
|
||||
}
|
||||
|
|
|
|||
14
Libraries/LibWeb/CSS/Parser/SourcePosition.h
Normal file
14
Libraries/LibWeb/CSS/Parser/SourcePosition.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
struct SourcePosition {
|
||||
size_t line { 0 };
|
||||
size_t column { 0 };
|
||||
};
|
||||
|
|
@ -418,13 +418,13 @@ StringView Token::bracket_mirror_string() const
|
|||
return ""sv;
|
||||
}
|
||||
|
||||
void Token::set_position_range(Badge<Tokenizer>, Position start, Position end)
|
||||
void Token::set_position_range(Badge<Tokenizer>, SourcePosition start, SourcePosition end)
|
||||
{
|
||||
m_start_position = start;
|
||||
m_end_position = end;
|
||||
}
|
||||
|
||||
void Token::set_position_range(Badge<RustTokenizer>, Position start, Position end)
|
||||
void Token::set_position_range(Badge<RustTokenizer>, SourcePosition start, SourcePosition end)
|
||||
{
|
||||
m_start_position = start;
|
||||
m_end_position = end;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/CSS/Number.h>
|
||||
#include <LibWeb/CSS/Parser/SourcePosition.h>
|
||||
#include <LibWeb/Export.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
|
|
@ -61,11 +62,6 @@ public:
|
|||
Unrestricted,
|
||||
};
|
||||
|
||||
struct Position {
|
||||
size_t line { 0 };
|
||||
size_t column { 0 };
|
||||
};
|
||||
|
||||
// Use this only to create types that don't have their own create_foo() methods below.
|
||||
static Token create(Type, String original_source_text = {});
|
||||
|
||||
|
|
@ -184,10 +180,10 @@ public:
|
|||
String to_debug_string() const;
|
||||
|
||||
String const& original_source_text() const { return m_original_source_text; }
|
||||
Position const& start_position() const { return m_start_position; }
|
||||
Position const& end_position() const { return m_end_position; }
|
||||
void set_position_range(Badge<Tokenizer>, Position start, Position end);
|
||||
void set_position_range(Badge<RustTokenizer>, Position start, Position end);
|
||||
SourcePosition const& start_position() const { return m_start_position; }
|
||||
SourcePosition const& end_position() const { return m_end_position; }
|
||||
void set_position_range(Badge<Tokenizer>, SourcePosition start, SourcePosition end);
|
||||
void set_position_range(Badge<RustTokenizer>, SourcePosition start, SourcePosition end);
|
||||
|
||||
bool operator==(Token const& other) const
|
||||
{
|
||||
|
|
@ -202,8 +198,8 @@ private:
|
|||
HashType m_hash_type { HashType::Unrestricted };
|
||||
|
||||
String m_original_source_text;
|
||||
Position m_start_position;
|
||||
Position m_end_position;
|
||||
SourcePosition m_start_position;
|
||||
SourcePosition m_end_position;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2026, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -104,10 +104,10 @@ private:
|
|||
|
||||
String m_decoded_input;
|
||||
Utf8View m_utf8_view;
|
||||
AK::Utf8CodePointIterator m_utf8_iterator;
|
||||
AK::Utf8CodePointIterator m_prev_utf8_iterator;
|
||||
Token::Position m_position;
|
||||
Token::Position m_prev_position;
|
||||
Utf8CodePointIterator m_utf8_iterator;
|
||||
Utf8CodePointIterator m_prev_utf8_iterator;
|
||||
SourcePosition m_position;
|
||||
SourcePosition m_prev_position;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue