Skip to content

Commit

Permalink
LibWeb: Use setter for HTMLToken::m_{start,end}_position
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxWipfli authored and alimpfard committed Jul 17, 2021
1 parent 8b31e41 commit f2e3c77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace Web::HTML {

class HTMLTokenizer;

class HTMLToken {
friend class HTMLDocumentParser;
friend class HTMLTokenizer;
Expand Down Expand Up @@ -282,6 +284,9 @@ class HTMLToken {
Position const& start_position() const { return m_start_position; }
Position const& end_position() const { return m_end_position; }

void set_start_position(Badge<HTMLTokenizer>, Position start_position) { m_start_position = start_position; }
void set_end_position(Badge<HTMLTokenizer>, Position end_position) { m_end_position = end_position; }

private:
Type m_type { Type::Invalid };

Expand Down
22 changes: 11 additions & 11 deletions Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token()
{
log_parse_error();
create_new_token(HTMLToken::Type::Comment);
m_current_token.m_start_position = nth_last_position(2);
m_current_token.set_start_position({}, nth_last_position(2));
RECONSUME_IN(BogusComment);
}
ON_EOF
Expand All @@ -306,44 +306,44 @@ Optional<HTMLToken> HTMLTokenizer::next_token()
ON_WHITESPACE
{
m_current_token.set_tag_name(consume_current_builder());
m_current_token.m_end_position = nth_last_position(1);
m_current_token.set_end_position({}, nth_last_position(1));
SWITCH_TO(BeforeAttributeName);
}
ON('/')
{
m_current_token.set_tag_name(consume_current_builder());
m_current_token.m_end_position = nth_last_position(0);
m_current_token.set_end_position({}, nth_last_position(0));
SWITCH_TO(SelfClosingStartTag);
}
ON('>')
{
m_current_token.set_tag_name(consume_current_builder());
m_current_token.m_end_position = nth_last_position(1);
m_current_token.set_end_position({}, nth_last_position(1));
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
}
ON_ASCII_UPPER_ALPHA
{
m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value()));
m_current_token.m_end_position = nth_last_position(0);
m_current_token.set_end_position({}, nth_last_position(0));
continue;
}
ON(0)
{
log_parse_error();
m_current_builder.append_code_point(0xFFFD);
m_current_token.m_end_position = nth_last_position(0);
m_current_token.set_end_position({}, nth_last_position(0));
continue;
}
ON_EOF
{
log_parse_error();
m_current_token.m_end_position = nth_last_position(0);
m_current_token.set_end_position({}, nth_last_position(0));
EMIT_EOF;
}
ANYTHING_ELSE
{
m_current_builder.append_code_point(current_input_character.value());
m_current_token.m_end_position = nth_last_position(0);
m_current_token.set_end_position({}, nth_last_position(0));
continue;
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token()
DONT_CONSUME_NEXT_INPUT_CHARACTER;
if (consume_next_if_match("--")) {
create_new_token(HTMLToken::Type::Comment);
m_current_token.m_start_position = nth_last_position(4);
m_current_token.set_start_position({}, nth_last_position(4));
SWITCH_TO(CommentStart);
}
if (consume_next_if_match("DOCTYPE", CaseSensitivity::CaseInsensitive)) {
Expand Down Expand Up @@ -2679,7 +2679,7 @@ void HTMLTokenizer::create_new_token(HTMLToken::Type type)
break;
}

m_current_token.m_start_position = nth_last_position(offset);
m_current_token.set_start_position({}, nth_last_position(offset));
}

HTMLTokenizer::HTMLTokenizer(StringView const& input, String const& encoding)
Expand Down Expand Up @@ -2712,7 +2712,7 @@ void HTMLTokenizer::will_emit(HTMLToken& token)
{
if (token.is_start_tag())
m_last_emitted_start_tag_name = token.tag_name();
token.m_end_position = nth_last_position(0);
token.set_end_position({}, nth_last_position(0));
}

bool HTMLTokenizer::current_end_tag_token_is_appropriate() const
Expand Down

0 comments on commit f2e3c77

Please sign in to comment.