lib/scanner: clippy, fmt

This commit is contained in:
Paul Stemmet 2021-07-25 09:58:22 +00:00 committed by Paul Stemmet
parent eee164caa1
commit dd04944fe9
3 changed files with 32 additions and 34 deletions

View File

@ -47,7 +47,9 @@ impl Scanner
}
}
fn scan_tokens<'de>(&mut self, base: &'de str, tokens: &mut Tokens<'de>) -> Result<usize>
/// Scan some tokens from the given .base into .tokens
/// returning the number added.
pub fn scan_tokens<'de>(&mut self, base: &'de str, tokens: &mut Tokens<'de>) -> Result<usize>
{
if let Some(mut buffer) = base
.get(self.offset..)
@ -105,32 +107,27 @@ impl Scanner
*/
match base.as_bytes()
{
[DIRECTIVE, ..] => return self.directive(base, tokens),
[ANCHOR, ..] | [ALIAS, ..] => return self.anchor(base, tokens),
[TAG, ..] => return self.tag(base, tokens),
[SINGLE, ..] | [DOUBLE, ..] => return self.flow_scalar(base, tokens),
[VALUE, ..] if isWhiteSpaceZ!(~base, 1) => return self.value(base, tokens),
[DIRECTIVE, ..] => self.directive(base, tokens),
[ANCHOR, ..] | [ALIAS, ..] => self.anchor(base, tokens),
[TAG, ..] => self.tag(base, tokens),
[SINGLE, ..] | [DOUBLE, ..] => self.flow_scalar(base, tokens),
[VALUE, ..] if isWhiteSpaceZ!(~base, 1) => self.value(base, tokens),
_ => unreachable!(),
}
}
fn start_stream(&mut self, tokens: &mut Tokens)
{
match self.state
if self.state == StreamState::Start
{
StreamState::Start =>
{
// A key is allowed at the beginning of the stream
self.key.possible(!REQUIRED);
// A key is allowed at the beginning of the stream
self.key.possible(!REQUIRED);
self.state = StreamState::Stream;
self.state = StreamState::Stream;
let token = Token::StreamStart(StreamEncoding::UTF8);
let token = Token::StreamStart(StreamEncoding::UTF8);
tokens.push(token)
},
_ =>
{},
tokens.push(token)
}
}
@ -448,23 +445,22 @@ impl<'de> ScanIter<'de>
pub fn next_token(&mut self) -> Result<Option<Token<'de>>>
{
if self.done
if (!self.done) && self.tokens.is_empty()
{
return Ok(None);
if let 0 = self.scan.scan_tokens(self.data, &mut self.tokens)?
{
self.done = true
}
}
if self.tokens.is_empty()
if !self.done
{
self.scan.scan_tokens(self.data, &mut self.tokens)?;
Ok(self.tokens.drain(0..1).next())
}
if self.tokens.len() == 0
else
{
self.done = true;
return Ok(None);
Ok(None)
}
Ok(self.tokens.drain(0..1).next())
}
}
@ -478,6 +474,8 @@ impl<'de> Iterator for ScanIter<'de>
}
}
impl<'de> std::iter::FusedIterator for ScanIter<'de> {}
enum DirectiveKind
{
Version,

View File

@ -244,7 +244,7 @@ enum ScalarRangeInner
impl ScalarRange
{
pub fn into_token<'de>(self, base: &'de str) -> Result<Token<'de>>
pub fn into_token(self, base: &str) -> Result<Token<'_>>
{
use ScalarRangeInner::*;

View File

@ -78,10 +78,10 @@ use crate::{
/// This function will attempt to borrow from .base where
/// possible, but may also copy the directive's handle and
/// prefix into .scratch if borrowing is not possible.
pub(in crate::scanner) fn scan_tag_directive<'b, 'c>(
base: &'b str,
pub(in crate::scanner) fn scan_tag_directive<'de>(
base: &'de str,
stats: &mut MStats,
) -> Result<(Token<'b>, usize)>
) -> Result<(Token<'de>, usize)>
{
let mut buffer = base;
let mut can_borrow = true;
@ -145,10 +145,10 @@ pub(in crate::scanner) fn scan_tag_directive<'b, 'c>(
/// ("", suffix) => A verbatim tag
/// ("!", "") => A non resolving tag
/// (handle, suffix) => A primary, secondary or named tag
pub(in crate::scanner) fn scan_node_tag<'b, 'c>(
base: &'b str,
pub(in crate::scanner) fn scan_node_tag<'de>(
base: &'de str,
stats: &mut MStats,
) -> Result<(Token<'b>, usize)>
) -> Result<(Token<'de>, usize)>
{
let mut buffer = base;
let mut can_borrow = true;