/* * Copyright (c) 2020-2023, Andreas Kling * Copyright (c) 2021, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace IDL { class Parser { public: Parser(ByteString filename, StringView contents, Vector import_base_paths); Interface& parse(); Vector imported_files() const; private: // https://webidl.spec.whatwg.org/#dfn-special-operation // A special operation is a getter, setter or deleter. enum class IsSpecialOperation { No, Yes, }; enum class IsStatic { No, Yes, }; Parser(Parser* parent, ByteString filename, StringView contents, Vector import_base_path); void assert_specific(char ch); void assert_string(StringView expected); void consume_whitespace(); Optional resolve_import(auto path); HashMap parse_extended_attributes(); void parse_attribute(HashMap& extended_attributes, Interface&, IsStatic is_static = IsStatic::No); void parse_interface(Interface&); void parse_namespace(Interface&); void parse_non_interface_entities(bool allow_interface, Interface&); void parse_enumeration(HashMap, Interface&); void parse_typedef(Interface&); void parse_interface_mixin(Interface&); void parse_dictionary(Interface&); void parse_callback_function(HashMap& extended_attributes, Interface&); void parse_constructor(HashMap& extended_attributes, Interface&); void parse_getter(HashMap& extended_attributes, Interface&); void parse_setter(HashMap& extended_attributes, Interface&); void parse_deleter(HashMap& extended_attributes, Interface&); void parse_stringifier(HashMap& extended_attributes, Interface&); void parse_iterable(Interface&); void parse_setlike(Interface&, bool is_readonly); Function parse_function(HashMap& extended_attributes, Interface&, IsStatic is_static = IsStatic::No, IsSpecialOperation is_special_operation = IsSpecialOperation::No); Vector parse_parameters(); NonnullRefPtr parse_type(); void parse_constant(Interface&); ByteString parse_identifier_until(AK::Function predicate); ByteString parse_identifier_ending_with(auto... possible_terminating_characters); ByteString parse_identifier_ending_with_space(); ByteString parse_identifier_ending_with_space_or(auto... possible_terminating_characters); Vector import_base_paths; ByteString filename; StringView input; LineTrackingLexer lexer; HashTable>& top_level_interfaces(); HashTable> interfaces; HashMap& top_level_resolved_imports(); HashMap resolved_imports; Parser* top_level_parser(); Parser* parent = nullptr; }; }