Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-html

Source of release 0.5.1

0.5.1 / src / html_syntax / html_tokenizer_3.lucb

#==============================================================================================
#
#   html_tokenizer_3 - HTMLTokenizer states: DOCTYPE public and system identifiers
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp (lines 706-1136): the states
#       AfterDOCTYPEPublicKeyword to BogusDOCTYPE of next_token, one function each (see
#       html_tokenizer_1 for how the macros map to TokenizerStep).
#
#==============================================================================================

# mark: Keywords ================================================================================

# 13.2.5.57 After DOCTYPE public keyword state, https://html.spec.whatwg.org/multipage/parsing.html#after-doctype-public-keyword-state
func html_tokenizer_after_doctype_public_keyword_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return tokenizer_switch_to(this, .before_doctype_public_identifier)
    if on(current_input_character, '"'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).missing_public_identifier = false
        return tokenizer_switch_to(this, .doctype_public_identifier_double_quoted)
    if on(current_input_character, '\''):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).missing_public_identifier = false
        return tokenizer_switch_to(this, .doctype_public_identifier_single_quoted)
    if on(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# 13.2.5.63 After DOCTYPE system keyword state, https://html.spec.whatwg.org/multipage/parsing.html#after-doctype-system-keyword-state
func html_tokenizer_after_doctype_system_keyword_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return tokenizer_switch_to(this, .before_doctype_system_identifier)
    if on(current_input_character, '"'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = ak.string_new()
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_double_quoted)
    if on(current_input_character, '\''):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = ak.string_new()
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_single_quoted)
    if on(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# mark: Before the identifiers ==================================================================

# 13.2.5.58 Before DOCTYPE public identifier state, https://html.spec.whatwg.org/multipage/parsing.html#before-doctype-public-identifier-state
func html_tokenizer_before_doctype_public_identifier_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return TokenizerStep.consume_next
    if on(current_input_character, '"'):
        html_token_ensure_doctype_data(&this.m_current_token).missing_public_identifier = false
        return tokenizer_switch_to(this, .doctype_public_identifier_double_quoted)
    if on(current_input_character, '\''):
        html_token_ensure_doctype_data(&this.m_current_token).missing_public_identifier = false
        return tokenizer_switch_to(this, .doctype_public_identifier_single_quoted)
    if on(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# 13.2.5.64 Before DOCTYPE system identifier state, https://html.spec.whatwg.org/multipage/parsing.html#before-doctype-system-identifier-state
func html_tokenizer_before_doctype_system_identifier_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return TokenizerStep.consume_next
    if on(current_input_character, '"'):
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_double_quoted)
    if on(current_input_character, '\''):
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_single_quoted)
    if on(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# mark: Quoted identifiers ======================================================================

# 13.2.5.59 DOCTYPE public identifier (double-quoted) state, https://html.spec.whatwg.org/multipage/parsing.html#doctype-public-identifier-(double-quoted)-state
func html_tokenizer_doctype_public_identifier_double_quoted_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '"'):
        html_token_ensure_doctype_data(&this.m_current_token).public_identifier = html_tokenizer_consume_current_builder(this)
        return tokenizer_switch_to(this, .after_doctype_public_identifier)
    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(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).public_identifier = html_tokenizer_consume_current_builder(this)
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
    return TokenizerStep.consume_next

# 13.2.5.60 DOCTYPE public identifier (single-quoted) state, https://html.spec.whatwg.org/multipage/parsing.html#doctype-public-identifier-(single-quoted)-state
func html_tokenizer_doctype_public_identifier_single_quoted_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '\''):
        html_token_ensure_doctype_data(&this.m_current_token).public_identifier = html_tokenizer_consume_current_builder(this)
        return tokenizer_switch_to(this, .after_doctype_public_identifier)
    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(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).public_identifier = html_tokenizer_consume_current_builder(this)
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
    return TokenizerStep.consume_next

# 13.2.5.65 DOCTYPE system identifier (double-quoted) state, https://html.spec.whatwg.org/multipage/parsing.html#doctype-system-identifier-(double-quoted)-state
func html_tokenizer_doctype_system_identifier_double_quoted_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '"'):
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = html_tokenizer_consume_current_builder(this)
        return tokenizer_switch_to(this, .after_doctype_system_identifier)
    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(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = html_tokenizer_consume_current_builder(this)
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
    return TokenizerStep.consume_next

# 13.2.5.66 DOCTYPE system identifier (single-quoted) state, https://html.spec.whatwg.org/multipage/parsing.html#doctype-system-identifier-(single-quoted)-state
func html_tokenizer_doctype_system_identifier_single_quoted_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '\''):
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = html_tokenizer_consume_current_builder(this)
        return tokenizer_switch_to(this, .after_doctype_system_identifier)
    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(current_input_character, '>'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).system_identifier = html_tokenizer_consume_current_builder(this)
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    ak.string_builder_append_code_point(&this.m_current_builder, input_value(current_input_character))
    return TokenizerStep.consume_next

# mark: After the identifiers ===================================================================

# 13.2.5.61 After DOCTYPE public identifier state, https://html.spec.whatwg.org/multipage/parsing.html#after-doctype-public-identifier-state
func html_tokenizer_after_doctype_public_identifier_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return tokenizer_switch_to(this, .between_doctype_public_and_system_identifiers)
    if on(current_input_character, '>'):
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on(current_input_character, '"'):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_double_quoted)
    if on(current_input_character, '\''):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_single_quoted)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# 13.2.5.62 Between DOCTYPE public and system identifiers state, https://html.spec.whatwg.org/multipage/parsing.html#between-doctype-public-and-system-identifiers-state
func html_tokenizer_between_doctype_public_and_system_identifiers_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return TokenizerStep.consume_next
    if on(current_input_character, '>'):
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on(current_input_character, '"'):
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_double_quoted)
    if on(current_input_character, '\''):
        html_token_ensure_doctype_data(&this.m_current_token).missing_system_identifier = false
        return tokenizer_switch_to(this, .doctype_system_identifier_single_quoted)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
    return tokenizer_reconsume_in(this, .bogus_doctype)

# 13.2.5.67 After DOCTYPE system identifier state, https://html.spec.whatwg.org/multipage/parsing.html#after-doctype-system-identifier-state
func html_tokenizer_after_doctype_system_identifier_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on_whitespace(current_input_character):
        return TokenizerStep.consume_next
    if on(current_input_character, '>'):
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on_eof(current_input_character):
        log_parse_error()
        html_token_ensure_doctype_data(&this.m_current_token).force_quirks = true
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    log_parse_error()
    return tokenizer_reconsume_in(this, .bogus_doctype)

# 13.2.5.68 Bogus DOCTYPE state, https://html.spec.whatwg.org/multipage/parsing.html#bogus-doctype-state
func html_tokenizer_bogus_doctype_state(this: HtmlTokenizer*, current_input_character: u32?, stop_at_insertion_point: HtmlTokenizerStopAtInsertionPoint) -> TokenizerStep:
    if on(current_input_character, '>'):
        return tokenizer_switch_to_and_emit_current_token(this, .data)
    if on(current_input_character, 0):
        log_parse_error()
        return TokenizerStep.consume_next
    if on_eof(current_input_character):
        ak.queue_enqueue(&this.m_queued_tokens, html_tokenizer_move_current_token(this))
        return tokenizer_emit_eof(this)
    return TokenizerStep.consume_next