pub use errors::{DefaultContainer, Errors};
pub use hex_escape::*;
pub use incomplete_syntax::*;
pub use incomplete_token::*;
pub use invalid::*;
pub use invalid_hex_digits::*;
pub use malformed::*;
pub use missing::*;
pub use unclosed::*;
pub use undelimited::*;
pub use unexpected_end::*;
pub use unexpected_identifier::*;
pub use unexpected_keyword::*;
pub use unexpected_lexeme::*;
pub use unexpected_prefix::*;
pub use unexpected_suffix::*;
pub use unicode_escape::*;
pub use unknown_lexeme::*;
pub use unopened::*;
pub use unterminated::*;
use generic_arraydeque::{ArrayLength, GenericArrayDeque};
use crate::utils::SimpleSpan;
mod errors;
pub mod token;
pub mod lexer;
pub mod syntax;
mod hex_escape;
mod incomplete_syntax;
mod incomplete_token;
mod invalid;
mod malformed;
mod missing;
mod unclosed;
mod undelimited;
mod unexpected_end;
mod unexpected_identifier;
mod unexpected_keyword;
mod unexpected_lexeme;
mod unexpected_prefix;
mod unexpected_suffix;
mod unknown_lexeme;
mod unopened;
mod unterminated;
mod invalid_hex_digits;
mod unicode_escape;
pub trait ErrorNode<S = SimpleSpan> {
fn error(span: S) -> Self;
fn missing(span: S) -> Self;
}
impl ErrorNode for &str {
#[cfg_attr(not(tarpaulin), inline(always))]
fn error(_span: SimpleSpan) -> Self {
"<error>"
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn missing(_span: SimpleSpan) -> Self {
"<missing>"
}
}
impl ErrorNode for &[u8] {
#[cfg_attr(not(tarpaulin), inline(always))]
fn error(_span: SimpleSpan) -> Self {
b"<error>"
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn missing(_span: SimpleSpan) -> Self {
b"<missing>"
}
}
#[cfg(feature = "bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bytes")))]
impl ErrorNode for bytes::Bytes {
#[cfg_attr(not(tarpaulin), inline(always))]
fn error(_span: SimpleSpan) -> Self {
bytes::Bytes::from_static(b"<error>")
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn missing(_span: SimpleSpan) -> Self {
bytes::Bytes::from_static(b"<missing>")
}
}
#[cfg(feature = "hipstr")]
#[cfg_attr(docsrs, doc(cfg(feature = "hipstr")))]
const _: () = {
use hipstr::{HipByt, HipStr};
impl ErrorNode for HipStr<'_> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn error(_span: SimpleSpan) -> Self {
HipStr::borrowed("<error>")
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn missing(_span: SimpleSpan) -> Self {
HipStr::borrowed("<missing>")
}
}
impl ErrorNode for HipByt<'_> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn error(_span: SimpleSpan) -> Self {
HipByt::borrowed(b"<error>")
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn missing(_span: SimpleSpan) -> Self {
HipByt::borrowed(b"<missing>")
}
}
};
pub trait ErrorContainer<E> {
type IntoIter: Iterator<Item = E>;
type Iter<'a>: Iterator<Item = &'a E>
where
Self: 'a,
E: 'a;
fn new() -> Self;
#[cfg_attr(not(tarpaulin), inline(always))]
fn with_capacity(_: usize) -> Self
where
Self: Sized,
{
Self::new()
}
fn push(&mut self, error: E);
#[cfg_attr(not(tarpaulin), inline(always))]
fn try_push(&mut self, error: E) -> Result<(), E>
where
Self: Sized,
{
self.push(error);
Ok(())
}
fn pop(&mut self) -> Option<E>;
#[cfg_attr(not(tarpaulin), inline(always))]
fn is_empty(&self) -> bool {
self.len() == 0
}
fn len(&self) -> usize;
fn iter(&self) -> Self::Iter<'_>;
fn into_iter(self) -> Self::IntoIter;
#[cfg_attr(not(tarpaulin), inline(always))]
fn remaining_capacity(&self) -> Option<usize> {
None
}
}
impl<E> ErrorContainer<E> for Option<E> {
type IntoIter = core::option::IntoIter<E>;
type Iter<'a>
= core::option::Iter<'a, E>
where
E: 'a;
#[cfg_attr(not(tarpaulin), inline(always))]
fn new() -> Self {
None
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn push(&mut self, error: E) {
self.get_or_insert(error);
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn try_push(&mut self, error: E) -> Result<(), E> {
if self.is_some() {
Err(error)
} else {
self.push(error);
Ok(())
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn pop(&mut self) -> Option<E> {
self.take()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn len(&self) -> usize {
if self.is_some() { 1 } else { 0 }
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn iter(&self) -> Self::Iter<'_> {
Self::iter(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn into_iter(self) -> Self::IntoIter {
<Self as IntoIterator>::into_iter(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn remaining_capacity(&self) -> Option<usize> {
Some(if self.is_some() { 0 } else { 1 })
}
}
impl<E, N: ArrayLength> ErrorContainer<E> for GenericArrayDeque<E, N> {
type IntoIter = generic_arraydeque::IntoIter<E, N>;
type Iter<'a>
= generic_arraydeque::Iter<'a, E>
where
Self: 'a,
E: 'a;
#[cfg_attr(not(tarpaulin), inline(always))]
fn new() -> Self {
Self::new()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn push(&mut self, error: E) {
self.push_back(error);
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn try_push(&mut self, error: E) -> Result<(), E> {
match self.push_back(error) {
None => Ok(()),
Some(e) => Err(e),
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn pop(&mut self) -> Option<E> {
self.pop_front()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn len(&self) -> usize {
self.len()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn iter(&self) -> Self::Iter<'_> {
Self::iter(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn into_iter(self) -> Self::IntoIter {
IntoIterator::into_iter(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn remaining_capacity(&self) -> Option<usize> {
Some(self.remaining_capacity())
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
const _: () = {
use std::{
collections::{VecDeque, vec_deque},
vec::{self, Vec},
};
impl<E> ErrorContainer<E> for Vec<E> {
type IntoIter = vec::IntoIter<E>;
type Iter<'a>
= core::slice::Iter<'a, E>
where
E: 'a;
#[cfg_attr(not(tarpaulin), inline(always))]
fn new() -> Self {
Self::new()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn with_capacity(capacity: usize) -> Self {
Self::with_capacity(capacity)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn push(&mut self, error: E) {
self.push(error);
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn pop(&mut self) -> Option<E> {
if self.is_empty() {
None
} else {
Some(self.remove(0))
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn len(&self) -> usize {
self.len()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn iter(&self) -> Self::Iter<'_> {
self.as_slice().iter()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn into_iter(self) -> Self::IntoIter {
<Self as IntoIterator>::into_iter(self)
}
}
impl<E> ErrorContainer<E> for VecDeque<E> {
type IntoIter = vec_deque::IntoIter<E>;
type Iter<'a>
= vec_deque::Iter<'a, E>
where
E: 'a,
Self: 'a;
#[cfg_attr(not(tarpaulin), inline(always))]
fn new() -> Self {
Self::new()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn with_capacity(capacity: usize) -> Self {
Self::with_capacity(capacity)
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn push(&mut self, error: E) {
self.push_back(error);
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn pop(&mut self) -> Option<E> {
self.pop_front()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn len(&self) -> usize {
self.len()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn iter(&self) -> Self::Iter<'_> {
self.iter()
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn into_iter(self) -> Self::IntoIter {
<Self as IntoIterator>::into_iter(self)
}
}
};