diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index f2d15d7439eb30..6a7b1d617a70d6 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -3,6 +3,7 @@ * Copyright (c) 2021-2022, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur + * Copyright (c) 2024, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ @@ -738,6 +739,7 @@ void Parser::parse_namespace(Interface& interface) consume_whitespace(); } +// https://webidl.spec.whatwg.org/#prod-Enum void Parser::parse_enumeration(HashMap extended_attributes, Interface& interface) { assert_string("enum"sv); @@ -751,15 +753,10 @@ void Parser::parse_enumeration(HashMap 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('"'); @@ -771,10 +768,11 @@ void Parser::parse_enumeration(HashMap 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();