You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
891 B

  1. #pragma once
  2. #include "molasses/lexer.h"
  3. #include "molasses/parser_primitives.h"
  4. #include <memory>
  5. #include <span>
  6. #include <vector>
  7. struct parser {
  8. /**
  9. *
  10. * @param ctx
  11. * @param lexer_data
  12. * @param current
  13. * @return a span of the tokens left before reaching the target, assuming the parser is as greedy as possible
  14. */
  15. virtual std::span<molasses::symbol> identify(molasses::parser_context& ctx, const molasses::lexed_output& lexer_data, std::span<molasses::symbol> current) = 0;
  16. };
  17. struct ast_node {
  18. virtual std::vector<molasses::symbol> apply(molasses::parser_context& ctx, const molasses::lexed_output& lexer_data, std::span<molasses::symbol> current) = 0;
  19. };
  20. struct parser_branch : public parser {
  21. std::vector<std::shared_ptr<parser>> choice;
  22. };
  23. struct parser_sequence : public parser {
  24. std::vector<std::shared_ptr<parser>> sequence;
  25. };