Skip to content

Commit

Permalink
cleanup. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Aug 14, 2024
1 parent 17802e4 commit bdfac80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 2 additions & 8 deletions Source/3rdParty/yuescript/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <memory>

#include "yuescript/parser.hpp"

#define _DEFER(code, line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto) { \
code; \
})
#define DEFER(code) _DEFER(code, __LINE__)

namespace parserlib {

// internal private class that manages access to the public classes' internals.
Expand Down Expand Up @@ -914,7 +908,7 @@ bool _context::parse_non_term(rule& r) {
// save the state of the rule
rule::_state old_state = r.m_state;
// restore the rule's state
DEFER(r.m_state = old_state);
rule::_state_guard quard(old_state, &r.m_state);

// success/failure result
bool ok = false;
Expand Down Expand Up @@ -1008,7 +1002,7 @@ bool _context::parse_term(rule& r) {
// save the state of the rule
rule::_state old_state = r.m_state;
// restore the rule's state
DEFER(r.m_state = old_state);
rule::_state_guard quard(old_state, &r.m_state);

// success/failure result
bool ok = false;
Expand Down
11 changes: 11 additions & 0 deletions Source/3rdParty/yuescript/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ class rule {
, m_mode(mode) { }
};

struct _state_guard {
_state m_old_state;
_state* m_current_state;
_state_guard(const _state& old, _state* new_)
: m_old_state(old)
, m_current_state(new_) { }
~_state_guard() {
*m_current_state = m_old_state;
}
};

// internal expression
_expr* m_expr;

Expand Down

0 comments on commit bdfac80

Please sign in to comment.