scanner/macros: add isDocumentIndicator!

short hand for checking '--- ' or '... ' sequences
This commit is contained in:
Paul Stemmet 2021-08-13 21:15:39 +00:00 committed by Paul Stemmet
parent 7d600cd29e
commit 0fcc614771

View file

@ -287,6 +287,35 @@ macro_rules! isWhiteSpaceZ {
};
}
/// Check if a YAML document indicator ('---', '...') exists
/// @.offset in the given .buffer.
///
/// You must provide the current .buffer .column (or .stats
/// object)
///
/// Modifiers:
/// ~ .buffer := .buffer.as_bytes()
///
/// Variants
/// /1 .buffer, .column
/// /2 .buffer, :.stats
macro_rules! isDocumentIndicator {
(~ $buffer:expr, :$stats:expr) => {
isDocumentIndicator!($buffer.as_bytes(), $stats.column)
};
($buffer:expr, :$stats:expr) => {
isDocumentIndicator!($buffer, $stats.column)
};
(~ $buffer:expr, $column:expr) => {
isDocumentIndicator!($buffer.as_bytes(), $column)
};
($buffer:expr, $column:expr) => {
$column == 0
&& check!($buffer => [b'-', b'-', b'-', ..] | [b'.', b'.', b'.', ..])
&& isWhiteSpaceZ!($buffer, 3)
};
}
/// Checks if byte (@ .offset) in .buffer is hexadecimal
///
/// Modifiers: