LibIDL: Begin parsing IDL namespaces

For example, the CSS namespace is defined via IDL, but we currently have
a manual implementation.
This commit is contained in:
Timothy Flynn 2023-03-15 09:55:49 -04:00 committed by Tim Flynn
parent 406a7ea577
commit 61ecdbca54
Notes: sideshowbarker 2024-07-17 08:36:27 +09:00
3 changed files with 33 additions and 1 deletions

View file

@ -599,6 +599,33 @@ void Parser::parse_interface(Interface& interface)
consume_whitespace();
}
void Parser::parse_namespace(Interface& interface)
{
consume_whitespace();
interface.name = lexer.consume_until([](auto ch) { return is_ascii_space(ch); });
interface.is_namespace = true;
consume_whitespace();
assert_specific('{');
for (;;) {
consume_whitespace();
if (lexer.consume_specific('}')) {
consume_whitespace();
assert_specific(';');
break;
}
HashMap<DeprecatedString, DeprecatedString> extended_attributes;
parse_function(extended_attributes, interface);
}
interface.namespace_class = DeprecatedString::formatted("{}Namespace", interface.name);
consume_whitespace();
}
void Parser::parse_enumeration(Interface& interface)
{
assert_string("enum"sv);
@ -802,7 +829,7 @@ void Parser::parse_non_interface_entities(bool allow_interface, Interface& inter
parse_interface_mixin(interface);
} else if (lexer.next_is("callback")) {
parse_callback_function(extended_attributes, interface);
} else if ((allow_interface && !lexer.next_is("interface")) || !allow_interface) {
} else if ((allow_interface && !lexer.next_is("interface") && !lexer.next_is("namespace")) || !allow_interface) {
auto current_offset = lexer.tell();
auto name = lexer.consume_until([](auto ch) { return is_ascii_space(ch); });
consume_whitespace();
@ -920,6 +947,8 @@ Interface& Parser::parse()
if (lexer.consume_specific("interface"))
parse_interface(interface);
else if (lexer.consume_specific("namespace"))
parse_namespace(interface);
parse_non_interface_entities(false, interface);

View file

@ -40,6 +40,7 @@ private:
HashMap<DeprecatedString, DeprecatedString> parse_extended_attributes();
void parse_attribute(HashMap<DeprecatedString, DeprecatedString>& extended_attributes, Interface&);
void parse_interface(Interface&);
void parse_namespace(Interface&);
void parse_non_interface_entities(bool allow_interface, Interface&);
void parse_enumeration(Interface&);
void parse_typedef(Interface&);

View file

@ -256,6 +256,7 @@ public:
DeprecatedString name;
DeprecatedString parent_name;
bool is_namespace { false };
bool is_mixin { false };
HashMap<DeprecatedString, DeprecatedString> extended_attributes;
@ -291,6 +292,7 @@ public:
DeprecatedString constructor_class;
DeprecatedString prototype_class;
DeprecatedString prototype_base_class;
DeprecatedString namespace_class;
DeprecatedString global_mixin_class;
HashMap<DeprecatedString, HashTable<DeprecatedString>> included_mixins;