lib/scanner: add un/roll_indent functions

for handling the indent increment / decrement of the Scanner
This commit is contained in:
Paul Stemmet 2021-07-27 21:07:09 +00:00 committed by Paul Stemmet
parent 5ec3d0ae2b
commit 6b8965268c

View file

@ -730,6 +730,47 @@ fn check_is_key(buffer: &str, key_stats: &MStats, required: bool, extendable: bo
Ok(is_key)
}
fn roll_indent<'de>(
context: &mut Context,
tokens: &mut Tokens<'de>,
column: usize,
map: bool,
) -> Result<()>
{
if context.is_block() && context.indent() < column
{
context.indent_increment(column)?;
let token = match map
{
true => Token::BlockMappingStart,
false => Token::BlockSequenceStart,
};
tokens.push(token);
}
Ok(())
}
fn unroll_indent<'de>(context: &mut Context, tokens: &mut Tokens<'de>, column: usize)
-> Result<()>
{
if context.is_block()
{
let generator = |_| {
let token = Token::BlockEnd;
tokens.push(token);
Ok(())
};
context.indent_decrement(column, generator)?;
}
Ok(())
}
/// Vessel for tracking various stats about the underlying
/// buffer that are required for correct parsing of certain
/// elements, and when contextualizing an error.