scanner/macros: allow advance! to update a var with $amount consumed
This commit is contained in:
parent
aa2dec094e
commit
3526cd29c4
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue