Skip to content

Commit

Permalink
LibIDL: Allow trailing comma in enumerations
Browse files Browse the repository at this point in the history
IDL enumerations are one of the rare list types in the IDL spec that
allow for a trailing comma:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=17508
(cherry picked from commit 47597d0fb83d78eaf43be549cd7fe23e9b239b78)
  • Loading branch information
gmta authored and nico committed Nov 1, 2024
1 parent 5067a04 commit ba128fc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Userland/Libraries/LibIDL/IDLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (c) 2021-2022, Linus Groh <[email protected]>
* Copyright (c) 2021, Luke Wilde <[email protected]>
* Copyright (c) 2022, Ali Mohammad Pur <[email protected]>
* Copyright (c) 2024, Jelle Raaijmakers <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand Down Expand Up @@ -738,6 +739,7 @@ void Parser::parse_namespace(Interface& interface)
consume_whitespace();
}

// https://webidl.spec.whatwg.org/#prod-Enum
void Parser::parse_enumeration(HashMap<ByteString, ByteString> extended_attributes, Interface& interface)
{
assert_string("enum"sv);
Expand All @@ -751,15 +753,10 @@ void Parser::parse_enumeration(HashMap<ByteString, ByteString> extended_attribut

assert_specific('{');

bool first = true;
for (; !lexer.is_eof();) {
consume_whitespace();
if (lexer.next_is('}'))
break;
if (!first) {
assert_specific(',');
consume_whitespace();
}

assert_specific('"');
auto string = lexer.consume_until('"');
Expand All @@ -771,10 +768,11 @@ void Parser::parse_enumeration(HashMap<ByteString, ByteString> extended_attribut
else
enumeration.values.set(string);

if (first)
if (enumeration.first_member.is_empty())
enumeration.first_member = move(string);

first = false;
if (!lexer.next_is('}'))
assert_specific(',');
}

consume_whitespace();
Expand Down

0 comments on commit ba128fc

Please sign in to comment.