IDLParser.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 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<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_typedef(Interface&);
  35. void parse_interface_mixin(Interface&);
  36. void parse_dictionary(Interface&);
  37. void parse_callback_function(HashMap<String, String>& extended_attributes, Interface&);
  38. void parse_constructor(Interface&);
  39. void parse_getter(HashMap<String, String>& extended_attributes, Interface&);
  40. void parse_setter(HashMap<String, String>& extended_attributes, Interface&);
  41. void parse_deleter(HashMap<String, String>& extended_attributes, Interface&);
  42. void parse_stringifier(HashMap<String, String>& extended_attributes, Interface&);
  43. void parse_iterable(Interface&);
  44. Function parse_function(HashMap<String, String>& extended_attributes, Interface&, IsSpecialOperation is_special_operation = IsSpecialOperation::No);
  45. Vector<Parameter> parse_parameters();
  46. NonnullRefPtr<Type> parse_type();
  47. void parse_constant(Interface&);
  48. static HashTable<NonnullOwnPtr<Interface>> s_interfaces;
  49. static HashMap<String, Interface*> s_resolved_imports;
  50. String import_base_path;
  51. String filename;
  52. StringView input;
  53. GenericLexer lexer;
  54. };
  55. }