From 0fcc61477137caa9eb036da6086a292d67e30c97 Mon Sep 17 00:00:00 2001 From: Bazaah Date: Fri, 13 Aug 2021 21:15:39 +0000 Subject: [PATCH] scanner/macros: add isDocumentIndicator! short hand for checking '--- ' or '... ' sequences --- src/scanner/macros.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/scanner/macros.rs b/src/scanner/macros.rs index 1796a57..5b75a6c 100644 --- a/src/scanner/macros.rs +++ b/src/scanner/macros.rs @@ -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: