mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Change the IDL parser entry point to a static factory returning an IDL::Module. Modules now own the parsed file identity and import graph, with an optional reference to the file's real interface when one exists. This is a step towards running the IDL generator on files without an interface defined.
89 lines
3.7 KiB
C++
89 lines
3.7 KiB
C++
/*
|
|
* Copyright (c) 2020-2023, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/GenericLexer.h>
|
|
#include <LibIDL/Types.h>
|
|
|
|
namespace IDL {
|
|
|
|
class Parser {
|
|
public:
|
|
static Module parse(ByteString filename, StringView contents, Vector<ByteString> import_base_paths, Context& context);
|
|
|
|
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<ByteString> import_base_path, Context&);
|
|
Parser(ByteString filename, StringView contents, Vector<ByteString> import_base_paths, Context& context);
|
|
|
|
Module& parse();
|
|
Vector<ByteString> imported_files() const;
|
|
void assert_specific(char ch);
|
|
void assert_string(StringView expected);
|
|
void consume_whitespace();
|
|
Module& resolve_import(auto path);
|
|
|
|
HashMap<ByteString, ByteString> parse_extended_attributes();
|
|
void parse_attribute(HashMap<ByteString, ByteString>& extended_attributes, Interface&, IsStatic is_static = IsStatic::No);
|
|
void parse_interface(Interface&);
|
|
void parse_partial_interface(HashMap<ByteString, ByteString> extended_attributes, Interface& parent);
|
|
void parse_namespace(Interface&);
|
|
void parse_partial_namespace(Interface& parent);
|
|
void parse_non_interface_entities(bool allow_interface, Interface&);
|
|
void parse_enumeration(HashMap<ByteString, ByteString>, Interface&);
|
|
void parse_typedef(Interface&);
|
|
void parse_callback_interface(HashMap<ByteString, ByteString> extended_attributes, Interface&);
|
|
void parse_interface_mixin(Interface&);
|
|
void parse_partial_interface_mixin(Interface&);
|
|
void parse_dictionary(HashMap<ByteString, ByteString> extended_attributes, Interface&);
|
|
void parse_callback_function(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_constructor(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_getter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_setter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_deleter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_stringifier(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
|
|
void parse_iterable(Interface&);
|
|
void parse_async_iterable(Interface&);
|
|
void parse_setlike(Interface&, bool is_readonly);
|
|
void parse_maplike(Interface&, bool is_readonly);
|
|
Function parse_function(HashMap<ByteString, ByteString>& extended_attributes, Interface&, IsStatic is_static = IsStatic::No, IsSpecialOperation is_special_operation = IsSpecialOperation::No);
|
|
Vector<Parameter> parse_parameters();
|
|
NonnullRefPtr<Type const> parse_type();
|
|
void parse_constant(Interface&);
|
|
ByteString parse_identifier_until(AK::Function<bool(char)> 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<ByteString> import_base_paths;
|
|
ByteString filename;
|
|
StringView input;
|
|
LineTrackingLexer lexer;
|
|
Context& context;
|
|
|
|
HashMap<ByteString, Module*>& top_level_resolved_modules();
|
|
HashMap<ByteString, Module*> resolved_modules;
|
|
Parser* top_level_parser();
|
|
Parser* parent = nullptr;
|
|
};
|
|
|
|
}
|