SpecParser.h 1.2 KB

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