From 3526cd29c4c3686eef47665d83c3707b2e1cc620 Mon Sep 17 00:00:00 2001 From: Bazaah Date: Wed, 16 Jun 2021 15:24:44 +0000 Subject: [PATCH] scanner/macros: allow advance! to update a var with $amount consumed --- src/scanner/macros.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/scanner/macros.rs b/src/scanner/macros.rs index 4a51a91..f65a12e 100644 --- a/src/scanner/macros.rs +++ b/src/scanner/macros.rs @@ -1,17 +1,25 @@ /// Moves head in $buffer $amount forward macro_rules! advance { - ($buffer:expr, $amount:expr) => { + ($buffer:expr, $amount:expr $(, $var:ident )? ) => { let (_, rest) = $buffer.split_at($amount); + $( advance!(@update $var, $amount); )? + $buffer = rest }; - (<- $buffer:expr, $amount:expr) => {{ + (<- $buffer:expr, $amount:expr $(, $var:ident )? ) => {{ let (cut, rest) = $buffer.split_at($amount); $buffer = rest; + $( advance!(@update $var, $amount) )? + cut }}; + + (@update $( $var:ident, $amount:expr)? ) => { + $({ $var += $amount } )? + }; } /// New cow pointer from the given expr