lib/scanner: clippy, fmt
This commit is contained in:
parent
eee164caa1
commit
dd04944fe9
|
@ -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,20 +107,18 @@ 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
|
||||
{
|
||||
StreamState::Start =>
|
||||
if self.state == StreamState::Start
|
||||
{
|
||||
// A key is allowed at the beginning of the stream
|
||||
self.key.possible(!REQUIRED);
|
||||
|
@ -128,9 +128,6 @@ impl Scanner
|
|||
let token = Token::StreamStart(StreamEncoding::UTF8);
|
||||
|
||||
tokens.push(token)
|
||||
},
|
||||
_ =>
|
||||
{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -448,24 +445,23 @@ 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)?;
|
||||
}
|
||||
|
||||
if self.tokens.len() == 0
|
||||
{
|
||||
self.done = true;
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Ok(self.tokens.drain(0..1).next())
|
||||
}
|
||||
else
|
||||
{
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Iterator for ScanIter<'de>
|
||||
|
@ -478,6 +474,8 @@ impl<'de> Iterator for ScanIter<'de>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de> std::iter::FusedIterator for ScanIter<'de> {}
|
||||
|
||||
enum DirectiveKind
|
||||
{
|
||||
Version,
|
||||
|
|
|
@ -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::*;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue