context.hh 732 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef RUBY_PARSER_CONTEXT_HH
  2. #define RUBY_PARSER_CONTEXT_HH
  3. #include <optional>
  4. #include <set>
  5. #include <vector>
  6. namespace ruby_parser {
  7. class Context {
  8. public:
  9. enum class State {
  10. CLASS,
  11. SCLASS,
  12. DEF,
  13. DEFS,
  14. BLOCK,
  15. LAMBDA,
  16. };
  17. void push(State state);
  18. void pop();
  19. void reset();
  20. bool inClass();
  21. bool indirectlyInDef();
  22. bool classDefintinionAllowed();
  23. bool moduleDefintinionAllowed();
  24. bool dynamicConstDefintinionAllowed();
  25. private:
  26. std::vector<State> stack;
  27. std::optional<int> firstIndexOfState(State state);
  28. std::optional<int> lastIndexOfState(State state);
  29. bool contains(State state);
  30. };
  31. } // namespace ruby_parser
  32. #endif