From bdfac80a3a4032e90246c0145759b60097574c31 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 14 Aug 2024 11:48:23 +0800 Subject: [PATCH] cleanup. [skip CI] --- Source/3rdParty/yuescript/parser.cpp | 10 ++-------- Source/3rdParty/yuescript/parser.hpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Source/3rdParty/yuescript/parser.cpp b/Source/3rdParty/yuescript/parser.cpp index 5e4caa21a..5d0773cce 100644 --- a/Source/3rdParty/yuescript/parser.cpp +++ b/Source/3rdParty/yuescript/parser.cpp @@ -15,15 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include #include -#include #include "yuescript/parser.hpp" -#define _DEFER(code, line) std::shared_ptr _defer_##line(nullptr, [&](auto) { \ - code; \ -}) -#define DEFER(code) _DEFER(code, __LINE__) - namespace parserlib { // internal private class that manages access to the public classes' internals. @@ -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; @@ -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; diff --git a/Source/3rdParty/yuescript/parser.hpp b/Source/3rdParty/yuescript/parser.hpp index 71bbc1abb..5ab327ff3 100644 --- a/Source/3rdParty/yuescript/parser.hpp +++ b/Source/3rdParty/yuescript/parser.hpp @@ -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;