Feature/directive/version #6

Closed
bazaah wants to merge 11 commits from feature/directive/version into master
2 changed files with 55 additions and 6 deletions
Showing only changes of commit 90e45604a7 - Show all commits

View File

@ -5,4 +5,59 @@ macro_rules! advance {
$buffer = rest
};
(<- $buffer:expr, $amount:expr) => {{
let (cut, rest) = $buffer.split_at($amount);
$buffer = rest;
cut
}};
}
/// New cow pointer from the given expr
macro_rules! cow {
($from:expr) => {
std::borrow::Cow::from($from)
};
}
/// Check the buffer for $byte matches at $pos, optionally
/// returning an error Note that the error path is special
/// cased to return an UnexpectedEOF if it encounters an
/// empty slice
macro_rules! check {
($buffer:expr, $(@$pos:expr,)? is $( $byte:pat )|+ $(, else $error:expr)? ) => {
{
let b = match $buffer$([$pos..])? {
[] => Err(false),
$([$byte, ..])|+ => Ok(true),
_ => Ok(false)
};
check!(@priv b $(=> $error)? )
}
};
($buffer:expr, $(@$pos:expr,)? not $( $byte:pat )|+ $(, else $error:expr)? ) => {
{
let b = match $buffer$([$pos..])? {
[] => Err(true),
$([$byte, ..])|+ => Ok(false),
_ => Ok(true)
};
check!(@priv b $(=> $error)? )
}
};
(@priv $bool:expr) => {
match $bool {
Ok(b) | Err(b) => b
}
};
(@priv $bool:expr => $error:expr) => {
match $bool {
Ok(true) => Ok(()),
Ok(false) => Err($error),
Err(_) => Err($crate::scanner::error::ScanError::UnexpectedEOF),
}
}
}

View File

@ -63,9 +63,3 @@ macro_rules! tokens {
assert_eq!(event, $expected, $msg)
};
}
macro_rules! cow {
($literal:expr) => {
std::borrow::Cow::from($literal)
};
}