@@ -27,7 +27,7 @@ using namespace OpenVic::NodeTools;
2727
2828template <typename T>
2929static NodeCallback auto _expect_type (Callback<T const *> auto && callback) {
30- return [callback = FWD (callback)](ast::NodeCPtr node) -> bool {
30+ return [callback = FWD (callback)](ast::NodeCPtr node) mutable -> bool {
3131 if (node != nullptr ) {
3232 T const * cast_node = dryad::node_try_cast<T>(node);
3333 if (cast_node != nullptr ) {
@@ -45,7 +45,7 @@ using _NodeIterator = typename decltype(std::declval<ast::NodeCPtr>()->children(
4545using _NodeStatementRange = dryad::node_range<_NodeIterator, ast::Statement>;
4646
4747static NodeCallback auto _abstract_statement_node_callback (Callback<_NodeStatementRange> auto && callback) {
48- return [callback = FWD (callback)](ast::NodeCPtr node) -> bool {
48+ return [callback = FWD (callback)](ast::NodeCPtr node) mutable -> bool {
4949 if (node != nullptr ) {
5050 if (auto const * file_tree = dryad::node_try_cast<ast::FileTree>(node)) {
5151 return callback (file_tree->statements ());
@@ -68,7 +68,7 @@ static NodeCallback auto _abstract_statement_node_callback(Callback<_NodeStateme
6868
6969template <std::derived_from<ast::FlatValue> T>
7070static Callback<T const *> auto _abstract_symbol_node_callback (Callback<ovdl::symbol<char >> auto && callback, bool allow_empty) {
71- return [callback = FWD (callback), allow_empty](T const * node) -> bool {
71+ return [callback = FWD (callback), allow_empty](T const * node) mutable -> bool {
7272 if (allow_empty) {
7373 return callback (node->value ());
7474 } else {
@@ -83,9 +83,9 @@ static Callback<T const*> auto _abstract_symbol_node_callback(Callback<ovdl::sym
8383}
8484
8585template <std::derived_from<ast::FlatValue> T>
86- static Callback<T const *> auto _abstract_string_node_callback (Callback<std::string_view> auto callback, bool allow_empty) {
86+ static Callback<T const *> auto _abstract_string_node_callback (Callback<std::string_view> auto && callback, bool allow_empty) {
8787 return _abstract_symbol_node_callback<T>(
88- [callback](ovdl::symbol<char > symbol) -> bool {
88+ [callback = FWD (callback) ](ovdl::symbol<char > symbol) mutable -> bool {
8989 return callback (symbol.view ());
9090 },
9191 allow_empty
@@ -96,24 +96,24 @@ node_callback_t NodeTools::expect_identifier(callback_t<std::string_view> callba
9696 return _expect_type<ast::IdentifierValue>(_abstract_string_node_callback<ast::IdentifierValue>(callback, false ));
9797}
9898
99- static NodeCallback auto _expect_identifier (Callback<ovdl::symbol<char >> auto callback) {
100- return _expect_type<ast::IdentifierValue>(_abstract_symbol_node_callback<ast::IdentifierValue>(callback, false ));
99+ static NodeCallback auto _expect_identifier (Callback<ovdl::symbol<char >> auto && callback) {
100+ return _expect_type<ast::IdentifierValue>(_abstract_symbol_node_callback<ast::IdentifierValue>(FWD ( callback) , false ));
101101}
102102
103103node_callback_t NodeTools::expect_string (callback_t <std::string_view> callback, bool allow_empty) {
104104 return _expect_type<ast::StringValue>(_abstract_string_node_callback<ast::StringValue>(callback, allow_empty));
105105}
106106
107- static NodeCallback auto _expect_string (Callback<ovdl::symbol<char >> auto callback, bool allow_empty) {
108- return _expect_type<ast::StringValue>(_abstract_symbol_node_callback<ast::StringValue>(callback, allow_empty));
107+ static NodeCallback auto _expect_string (Callback<ovdl::symbol<char >> auto && callback, bool allow_empty) {
108+ return _expect_type<ast::StringValue>(_abstract_symbol_node_callback<ast::StringValue>(FWD ( callback) , allow_empty));
109109}
110110
111111node_callback_t NodeTools::expect_identifier_or_string (callback_t <std::string_view> callback, bool allow_empty) {
112112 return [callback, allow_empty](ast::NodeCPtr node) -> bool {
113113 if (node != nullptr ) {
114114 auto const * cast_node = dryad::node_try_cast<ast::FlatValue>(node);
115115 if (cast_node != nullptr ) {
116- return _abstract_string_node_callback<ast::FlatValue>(callback, allow_empty)(cast_node);
116+ return _abstract_string_node_callback<ast::FlatValue>(FWD ( callback) , allow_empty)(cast_node);
117117 }
118118 Logger::error (
119119 " Invalid node type " , ast::get_type_name (node->kind ()), " when expecting " , utility::type_name<ast::IdentifierValue>(), " or " ,
@@ -134,7 +134,7 @@ node_callback_t NodeTools::expect_bool(callback_t<bool> callback) {
134134}
135135
136136node_callback_t NodeTools::expect_int_bool (callback_t <bool > callback) {
137- return expect_uint64 ([callback](uint64_t num) -> bool {
137+ return expect_uint64 ([callback](uint64_t num) mutable -> bool {
138138 if (num > 1 ) {
139139 Logger::warning (" Found int bool with value >1: " , num);
140140 }
@@ -143,7 +143,7 @@ node_callback_t NodeTools::expect_int_bool(callback_t<bool> callback) {
143143}
144144
145145node_callback_t NodeTools::expect_int64 (callback_t <int64_t > callback, int base) {
146- return expect_identifier ([callback, base](std::string_view identifier) -> bool {
146+ return expect_identifier ([callback, base](std::string_view identifier) mutable -> bool {
147147 int64_t val;
148148 std::from_chars_result result = StringUtils::string_to_int64 (identifier, val, base);
149149 if (result.ec == std::errc{}) {
@@ -155,7 +155,7 @@ node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback, int base)
155155}
156156
157157node_callback_t NodeTools::expect_uint64 (callback_t <uint64_t > callback, int base) {
158- return expect_identifier ([callback, base](std::string_view identifier) -> bool {
158+ return expect_identifier ([callback, base](std::string_view identifier) mutable -> bool {
159159 uint64_t val;
160160 std::from_chars_result result = StringUtils::string_to_uint64 (identifier, val, base);
161161 if (result.ec == std::errc{}) {
@@ -167,7 +167,7 @@ node_callback_t NodeTools::expect_uint64(callback_t<uint64_t> callback, int base
167167}
168168
169169callback_t <std::string_view> NodeTools::expect_fixed_point_str (callback_t <fixed_point_t > callback) {
170- return [callback](std::string_view identifier) -> bool {
170+ return [callback](std::string_view identifier) mutable -> bool {
171171 bool successful = false ;
172172 const fixed_point_t val = fixed_point_t::parse (identifier.data (), identifier.length (), &successful);
173173 if (successful) {
@@ -183,7 +183,7 @@ node_callback_t NodeTools::expect_fixed_point(callback_t<fixed_point_t> callback
183183}
184184
185185node_callback_t NodeTools::expect_colour (callback_t <colour_t > callback) {
186- return [callback](ast::NodeCPtr node) -> bool {
186+ return [callback](ast::NodeCPtr node) mutable -> bool {
187187 colour_t col = colour_t::null ();
188188 int32_t components = 0 ;
189189 bool ret = expect_list_of_length (3 , expect_fixed_point (
@@ -208,13 +208,13 @@ node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) {
208208}
209209
210210node_callback_t NodeTools::expect_colour_hex (callback_t <colour_argb_t > callback) {
211- return expect_uint<colour_argb_t ::integer_type>([callback](colour_argb_t ::integer_type val) -> bool {
211+ return expect_uint<colour_argb_t ::integer_type>([callback](colour_argb_t ::integer_type val) mutable -> bool {
212212 return callback (colour_argb_t::from_argb (val));
213213 }, 16 );
214214}
215215
216216callback_t <std::string_view> NodeTools::expect_date_str (callback_t <Date> callback) {
217- return [callback](std::string_view identifier) -> bool {
217+ return [callback](std::string_view identifier) mutable -> bool {
218218 Date::from_chars_result result;
219219 const Date date = Date::from_string_log (identifier, &result);
220220 if (result.ec == std::errc{}) {
@@ -238,26 +238,26 @@ node_callback_t NodeTools::expect_date_identifier_or_string(callback_t<Date> cal
238238}
239239
240240node_callback_t NodeTools::expect_years (callback_t <Timespan> callback) {
241- return expect_int<Timespan::day_t >([callback](Timespan::day_t val) -> bool {
241+ return expect_int<Timespan::day_t >([callback](Timespan::day_t val) mutable -> bool {
242242 return callback (Timespan::from_years (val));
243243 });
244244}
245245
246246node_callback_t NodeTools::expect_months (callback_t <Timespan> callback) {
247- return expect_int<Timespan::day_t >([callback](Timespan::day_t val) -> bool {
247+ return expect_int<Timespan::day_t >([callback](Timespan::day_t val) mutable -> bool {
248248 return callback (Timespan::from_months (val));
249249 });
250250}
251251
252252node_callback_t NodeTools::expect_days (callback_t <Timespan> callback) {
253- return expect_int<Timespan::day_t >([callback](Timespan::day_t val) -> bool {
253+ return expect_int<Timespan::day_t >([callback](Timespan::day_t val) mutable -> bool {
254254 return callback (Timespan::from_days (val));
255255 });
256256}
257257
258258template <typename T, node_callback_t (*expect_func)(callback_t <T>)>
259259NodeCallback auto _expect_vec2 (Callback<vec2_t <T>> auto && callback) {
260- return [callback = FWD (callback)](ast::NodeCPtr node) -> bool {
260+ return [callback = FWD (callback)](ast::NodeCPtr node) mutable -> bool {
261261 vec2_t <T> vec;
262262 bool ret = expect_dictionary_keys (
263263 " x" , ONE_EXACTLY, expect_func (assign_variable_callback (vec.x )),
@@ -297,7 +297,7 @@ node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) {
297297// seen in some gfx files, these vectors don't have x,y,z,w labels, so are loaded similarly to colours.
298298
299299node_callback_t NodeTools::expect_fvec3 (callback_t <fvec3_t > callback) {
300- return [callback](ast::NodeCPtr node) -> bool {
300+ return [callback](ast::NodeCPtr node) mutable -> bool {
301301 fvec3_t vec;
302302 int32_t components = 0 ;
303303 bool ret = expect_list_of_length (3 , expect_fixed_point (
@@ -312,7 +312,7 @@ node_callback_t NodeTools::expect_fvec3(callback_t<fvec3_t> callback) {
312312}
313313
314314node_callback_t NodeTools::expect_fvec4 (callback_t <fvec4_t > callback) {
315- return [callback](ast::NodeCPtr node) -> bool {
315+ return [callback](ast::NodeCPtr node) mutable -> bool {
316316 fvec4_t vec;
317317 int32_t components = 0 ;
318318 bool ret = expect_list_of_length (4 , expect_fixed_point (
@@ -327,7 +327,7 @@ node_callback_t NodeTools::expect_fvec4(callback_t<fvec4_t> callback) {
327327}
328328
329329node_callback_t NodeTools::expect_assign (key_value_callback_t callback) {
330- return _expect_type<ast::AssignStatement>([callback](ast::AssignStatement const * assign_node) -> bool {
330+ return _expect_type<ast::AssignStatement>([callback](ast::AssignStatement const * assign_node) mutable -> bool {
331331 std::string_view left;
332332 bool ret = expect_identifier (assign_variable_callback (left))(assign_node->left ());
333333 if (ret) {
@@ -343,7 +343,7 @@ node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
343343}
344344
345345node_callback_t NodeTools::expect_list_and_length (length_callback_t length_callback, node_callback_t callback) {
346- return _abstract_statement_node_callback ([length_callback, callback](_NodeStatementRange list) -> bool {
346+ return _abstract_statement_node_callback ([length_callback, callback](_NodeStatementRange list) mutable -> bool {
347347 bool ret = true ;
348348 auto dist = ranges::distance (list);
349349 size_t size = length_callback (dist);
@@ -392,10 +392,10 @@ node_callback_t NodeTools::expect_list(node_callback_t callback) {
392392}
393393
394394node_callback_t NodeTools::expect_length (callback_t <size_t > callback) {
395- return [callback](ast::NodeCPtr node) -> bool {
395+ return [callback](ast::NodeCPtr node) mutable -> bool {
396396 bool ret = true ;
397397 ret &= expect_list_and_length (
398- [callback, &ret](size_t size) -> size_t {
398+ [callback, &ret](size_t size) mutable -> size_t {
399399 ret &= callback (size);
400400 return 0 ;
401401 },
@@ -406,7 +406,7 @@ node_callback_t NodeTools::expect_length(callback_t<size_t> callback) {
406406}
407407
408408template <typename Key>
409- static node_callback_t _expect_key (Key key, NodeCallback auto callback, bool * key_found, bool allow_duplicates) {
409+ static node_callback_t _expect_key (Key key, NodeCallback auto && callback, bool * key_found, bool allow_duplicates) {
410410 if constexpr (std::same_as<Key, ovdl::symbol<char >>) {
411411 if (!key) {
412412 if (key_found != nullptr ) {
@@ -427,7 +427,7 @@ static node_callback_t _expect_key(Key key, NodeCallback auto callback, bool* ke
427427 }
428428 };
429429
430- return _abstract_statement_node_callback ([key, callback, key_found, allow_duplicates](_NodeStatementRange list) -> bool {
430+ return _abstract_statement_node_callback ([key, callback = FWD (callback) , key_found, allow_duplicates](_NodeStatementRange list) mutable -> bool {
431431 bool ret = true ;
432432 size_t keys_found = 0 ;
433433 for (auto sub_node : list) {
@@ -493,7 +493,7 @@ node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) {
493493}
494494
495495node_callback_t NodeTools::name_list_callback (callback_t <name_list_t &&> callback) {
496- return [callback](ast::NodeCPtr node) -> bool {
496+ return [callback](ast::NodeCPtr node) mutable -> bool {
497497 name_list_t list;
498498 bool ret = expect_list_reserve_length (
499499 list, expect_identifier_or_string (vector_callback<std::string_view>(list))
0 commit comments