IDLParser.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020-2021, 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 "IDLTypes.h"
  11. #include <AK/CharacterTypes.h>
  12. #include <AK/GenericLexer.h>
  13. namespace IDL {
  14. class Parser {
  15. public:
  16. Parser(String filename, StringView contents, String import_base_path);
  17. NonnullOwnPtr<Interface> parse();
  18. private:
  19. // https://webidl.spec.whatwg.org/#dfn-special-operation
  20. // A special operation is a getter, setter or deleter.
  21. enum class IsSpecialOperation {
  22. No,
  23. Yes,
  24. };
  25. void assert_specific(char ch);
  26. void assert_string(StringView expected);
  27. void consume_whitespace();
  28. Optional<NonnullOwnPtr<Interface>> resolve_import(auto path);
  29. HashMap<String, String> parse_extended_attributes();
  30. void parse_attribute(HashMap<String, String>& extended_attributes, Interface&);
  31. void parse_interface(Interface&);
  32. void parse_non_interface_entities(bool allow_interface, Interface&);
  33. void parse_enumeration(Interface&);
  34. void parse_interface_mixin(Interface&);
  35. void parse_dictionary(Interface&);
  36. void parse_constructor(Interface&);
  37. void parse_getter(HashMap<String, String>& extended_attributes, Interface&);
  38. void parse_setter(HashMap<String, String>& extended_attributes, Interface&);
  39. void parse_deleter(HashMap<String, String>& extended_attributes, Interface&);
  40. void parse_stringifier(HashMap<String, String>& extended_attributes, Interface&);
  41. void parse_iterable(Interface&);
  42. Function parse_function(HashMap<String, String>& extended_attributes, Interface&, IsSpecialOperation is_special_operation = IsSpecialOperation::No);
  43. Vector<Parameter> parse_parameters();
  44. NonnullRefPtr<Type> parse_type();
  45. void parse_constant(Interface&);
  46. static HashTable<String> s_all_imported_paths;
  47. String import_base_path;
  48. String filename;
  49. StringView input;
  50. GenericLexer lexer;
  51. };
  52. }