Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-html

Source of release 0.5.1

0.5.1 / src / html_syntax / html_tokenizer_5.lucb

#==============================================================================================
#
#   html_tokenizer_5 - HTMLTokenizer states: comments
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp (lines 1486-1708): the states
#       CommentStart to CommentLessThanSignBangDashDash of next_token, one function each (see
#       html_tokenizer_1 for how the macros map to TokenizerStep).
#
#==============================================================================================

# mark: Comment start and body ==================================================================

# 13.2.5.43 Comment start state, https://html.spec.whatwg.org/multipage/parsing.html#comment-start-state
func html_tokenizer_comment_start_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        return tokenizer_switch_to(this, .comment_start_dash)
    if on(current_input_character, '>'):
        log_parse_error()
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.44 Comment start dash state, https://html.spec.whatwg.org/multipage/parsing.html#comment-start-dash-state
func html_tokenizer_comment_start_dash_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        return tokenizer_switch_to(this, .comment_end)
    if on(current_input_character, '>'):
        log_parse_error()
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        return tokenizer_emit_current_token_followed_by_eof(this)
    ak.string_builder_append_u8(&this.m_current_builder, '-')
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.45 Comment state, https://html.spec.whatwg.org/multipage/parsing.html#comment-state
func html_tokenizer_comment_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '<'):
        ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
        return tokenizer_switch_to_with_unclean_builder(this, .comment_less_than_sign)
    if on(current_input_character, '-'):
        return tokenizer_switch_to_with_unclean_builder(this, .comment_end_dash)
    if on(current_input_character, 0):
        log_parse_error()
        ak.string_builder_append_code_point(&this.m_current_builder, 0xFFFD)
        return TokenizerStep.consume_next
    if on_eof(current_input_character):
        log_parse_error()
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_emit_current_token_followed_by_eof(this)
    ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
    return TokenizerStep.consume_next

# mark: Comment end =============================================================================

# 13.2.5.51 Comment end state, https://html.spec.whatwg.org/multipage/parsing.html#comment-end-state
func html_tokenizer_comment_end_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '>'):
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on(current_input_character, '!'):
        return tokenizer_switch_to_with_unclean_builder(this, .comment_end_bang)
    if on(current_input_character, '-'):
        ak.string_builder_append_u8(&this.m_current_builder, '-')
        return TokenizerStep.consume_next
    if on_eof(current_input_character):
        log_parse_error()
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_emit_current_token_followed_by_eof(this)
    ak.string_builder_append(&this.m_current_builder, "--")
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.52 Comment end bang state, https://html.spec.whatwg.org/multipage/parsing.html#comment-end-bang-state
func html_tokenizer_comment_end_bang_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        ak.string_builder_append(&this.m_current_builder, "--!")
        return tokenizer_switch_to_with_unclean_builder(this, .comment_end_dash)
    if on(current_input_character, '>'):
        log_parse_error()
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_emit_current_token_followed_by_eof(this)
    ak.string_builder_append(&this.m_current_builder, "--!")
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.50 Comment end dash state, https://html.spec.whatwg.org/multipage/parsing.html#comment-end-dash-state
func html_tokenizer_comment_end_dash_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        return tokenizer_switch_to_with_unclean_builder(this, .comment_end)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_set_comment(&this.m_current_token, html_tokenizer_consume_current_builder(this))
        return tokenizer_emit_current_token_followed_by_eof(this)
    ak.string_builder_append_u8(&this.m_current_builder, '-')
    return tokenizer_reconsume_in(this, .comment)

# mark: Comment less-than signs =================================================================

# 13.2.5.46 Comment less-than sign state, https://html.spec.whatwg.org/multipage/parsing.html#comment-less-than-sign-state
func html_tokenizer_comment_less_than_sign_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '!'):
        ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
        return tokenizer_switch_to_with_unclean_builder(this, .comment_less_than_sign_bang)
    if on(current_input_character, '<'):
        ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
        return TokenizerStep.consume_next
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.47 Comment less-than sign bang state, https://html.spec.whatwg.org/multipage/parsing.html#comment-less-than-sign-bang-state
func html_tokenizer_comment_less_than_sign_bang_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        return tokenizer_switch_to_with_unclean_builder(this, .comment_less_than_sign_bang_dash)
    return tokenizer_reconsume_in(this, .comment)

# 13.2.5.48 Comment less-than sign bang dash state, https://html.spec.whatwg.org/multipage/parsing.html#comment-less-than-sign-bang-dash-state
func html_tokenizer_comment_less_than_sign_bang_dash_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '-'):
        return tokenizer_switch_to_with_unclean_builder(this, .comment_less_than_sign_bang_dash_dash)
    return tokenizer_reconsume_in(this, .comment_end_dash)

# 13.2.5.49 Comment less-than sign bang dash dash state, https://html.spec.whatwg.org/multipage/parsing.html#comment-less-than-sign-bang-dash-dash-state
func html_tokenizer_comment_less_than_sign_bang_dash_dash_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '>'):
        return tokenizer_reconsume_in(this, .comment_end)
    if on_eof(current_input_character):
        return tokenizer_reconsume_in(this, .comment_end)
    log_parse_error()
    return tokenizer_reconsume_in(this, .comment_end)