IDLParser.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  5. * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <AK/CharacterTypes.h>
  11. #include <AK/GenericLexer.h>
  12. #include <LibIDL/Types.h>
  13. namespace IDL {
  14. class Parser {
  15. public:
  16. Parser(ByteString filename, StringView contents, ByteString import_base_path);
  17. Interface& parse();
  18. Vector<ByteString> imported_files() const;
  19. private:
  20. // https://webidl.spec.whatwg.org/#dfn-special-operation
  21. // A special operation is a getter, setter or deleter.
  22. enum class IsSpecialOperation {
  23. No,
  24. Yes,
  25. };
  26. Parser(Parser* parent, ByteString filename, StringView contents, ByteString import_base_path);
  27. void assert_specific(char ch);
  28. void assert_string(StringView expected);
  29. void consume_whitespace();
  30. Optional<Interface&> resolve_import(auto path);
  31. HashMap<ByteString, ByteString> parse_extended_attributes();
  32. void parse_attribute(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  33. void parse_interface(Interface&);
  34. void parse_namespace(Interface&);
  35. void parse_non_interface_entities(bool allow_interface, Interface&);
  36. void parse_enumeration(HashMap<ByteString, ByteString>, Interface&);
  37. void parse_typedef(Interface&);
  38. void parse_interface_mixin(Interface&);
  39. void parse_dictionary(Interface&);
  40. void parse_callback_function(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  41. void parse_constructor(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  42. void parse_getter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  43. void parse_setter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  44. void parse_deleter(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  45. void parse_stringifier(HashMap<ByteString, ByteString>& extended_attributes, Interface&);
  46. void parse_iterable(Interface&);
  47. Function parse_function(HashMap<ByteString, ByteString>& extended_attributes, Interface&, IsSpecialOperation is_special_operation = IsSpecialOperation::No);
  48. Vector<Parameter> parse_parameters();
  49. NonnullRefPtr<Type const> parse_type();
  50. void parse_constant(Interface&);
  51. ByteString import_base_path;
  52. ByteString filename;
  53. StringView input;
  54. LineTrackingLexer lexer;
  55. HashTable<NonnullOwnPtr<Interface>>& top_level_interfaces();
  56. HashTable<NonnullOwnPtr<Interface>> interfaces;
  57. HashMap<ByteString, Interface*>& top_level_resolved_imports();
  58. HashMap<ByteString, Interface*> resolved_imports;
  59. Parser* top_level_parser();
  60. Parser* parent = nullptr;
  61. };
  62. }