state_stack.cc 517 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <ruby_parser/state_stack.hh>
  2. using namespace ruby_parser;
  3. void state_stack::push(bool state) {
  4. stack.emplace_back(state);
  5. }
  6. bool state_stack::pop() {
  7. if (stack.empty()) {
  8. return false;
  9. } else {
  10. bool state = stack.back();
  11. stack.pop_back();
  12. return state;
  13. }
  14. }
  15. void state_stack::lexpop() {
  16. push(pop() || pop());
  17. }
  18. void state_stack::clear() {
  19. stack.clear();
  20. }
  21. bool state_stack::active() const {
  22. if (stack.empty()) {
  23. return false;
  24. } else {
  25. return stack.back();
  26. }
  27. }