SpecParser.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include "AST/AST.h"
  9. #include "CompilationPipeline.h"
  10. #include "Forward.h"
  11. #include "Parser/ParseError.h"
  12. #include "Parser/Token.h"
  13. namespace JSSpecCompiler {
  14. class AlgorithmStepList {
  15. public:
  16. static ParseErrorOr<AlgorithmStepList> create(XML::Node::Element const& element);
  17. Vector<AlgorithmStep> m_steps;
  18. Tree m_expression = error_tree;
  19. };
  20. class AlgorithmStep {
  21. public:
  22. static ParseErrorOr<AlgorithmStep> create(XML::Node const* node);
  23. ParseErrorOr<Tree> parse();
  24. Tree m_expression = error_tree;
  25. Vector<Token> m_tokens;
  26. NullableTree m_substeps;
  27. XML::Node const* m_node;
  28. };
  29. class Algorithm {
  30. public:
  31. static ParseErrorOr<Algorithm> create(XML::Node const* node);
  32. AlgorithmStepList m_steps;
  33. Tree m_tree = error_tree;
  34. };
  35. class SpecFunction {
  36. public:
  37. struct Argument {
  38. StringView name;
  39. };
  40. static ParseErrorOr<SpecFunction> create(XML::Node const* element);
  41. ParseErrorOr<void> parse_definition(XML::Node const* element);
  42. StringView m_section_number;
  43. StringView m_id;
  44. StringView m_name;
  45. Vector<Argument> m_arguments;
  46. Algorithm m_algorithm;
  47. };
  48. class SpecParsingStep : public CompilationStep {
  49. public:
  50. SpecParsingStep();
  51. ~SpecParsingStep();
  52. void run(TranslationUnitRef translation_unit) override;
  53. private:
  54. OwnPtr<XML::Document> m_document;
  55. ByteBuffer m_input;
  56. };
  57. }