Skip to content

Commit

Permalink
LibXML: Shift some rule acceptances to make errors nicer
Browse files Browse the repository at this point in the history
Instead of saying "expected />", make the parser output the real cause
for the following ("unknown reference"):
    <foo>&unknown;</foo>
  • Loading branch information
alimpfard authored and tcl3 committed Oct 10, 2024
1 parent 70e769a commit 202bfab
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Userland/Libraries/LibXML/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ ErrorOr<void, ParseError> Parser::parse_element()
return {};
}

auto accept = accept_rule();
auto start_tag = TRY(parse_start_tag());
auto& node = *start_tag;
auto& tag = node.content.get<Node::Element>();
Expand Down Expand Up @@ -649,7 +650,6 @@ ErrorOr<NonnullOwnPtr<Node>, ParseError> Parser::parse_empty_element_tag()
// EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
auto tag_start = m_lexer.tell();
TRY(expect("<"sv));
auto accept = accept_rule();

auto name = TRY(parse_name());
HashMap<Name, ByteString> attributes;
Expand All @@ -669,6 +669,8 @@ ErrorOr<NonnullOwnPtr<Node>, ParseError> Parser::parse_empty_element_tag()
TRY(skip_whitespace());
TRY(expect("/>"sv));

auto accept = accept_rule();

rollback.disarm();
return make<Node>(m_lexer.position_for(tag_start), Node::Element { move(name), move(attributes), {} });
}
Expand Down Expand Up @@ -848,6 +850,7 @@ ErrorOr<void, ParseError> Parser::parse_content()
{
auto rollback = rollback_point();
auto rule = enter_rule();
auto accept = accept_rule();

// content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
auto content_start = m_lexer.tell();
Expand Down

0 comments on commit 202bfab

Please sign in to comment.