#![allow(clippy::needless_lifetimes)]
use crate::refs_impl::error::{OFCode, ParseOFError};
use nom::Offset;
use nom_locate::LocatedSpan;
use std::slice;
pub(crate) mod ast;
pub(crate) mod parser;
#[allow(unreachable_pub)]
#[allow(unused)]
pub(crate) mod conv;
#[allow(unused)]
#[allow(unreachable_pub)]
pub(crate) mod error;
#[allow(unused)]
#[allow(unreachable_pub)]
pub(crate) mod format;
#[allow(unused)]
#[allow(unreachable_pub)]
pub(crate) mod tokens;
pub(crate) type Span<'a> = LocatedSpan<&'a str>;
pub(crate) type ParseResult<'s, O> = Result<(Span<'s>, O), ParseOFError<'s>>;
pub(crate) unsafe fn span_union<'a>(span0: Span<'a>, span1: Span<'a>) -> Span<'a> {
let ptr = span0.as_ptr();
let size = span0.offset(&span1) + span1.len();
unsafe {
let slice = slice::from_raw_parts(ptr, size);
let str = std::str::from_utf8_unchecked(slice);
Span::new_from_raw_offset(span0.location_offset(), span0.location_line(), str, ())
}
}
pub(crate) fn check_eof<'s>(i: Span<'s>, code: OFCode) -> Result<(), ParseOFError<'s>> {
if (*i).is_empty() {
Ok(())
} else {
Err(ParseOFError::new(code, i))
}
}
pub(crate) fn map_err<'s, O>(mut err: ParseOFError<'s>, code: OFCode) -> ParseResult<'s, O> {
if err.code != OFCode::OFCNomError
&& err.code != OFCode::OFCNomFailure
&& err.code != OFCode::OFCUnexpected
&& err.code != OFCode::OFCParseIncomplete
{
err.cause.push(err.code);
err.code = code;
}
Err(err)
}
pub(crate) trait TrackParseResult<'s, 't, O> {
fn trace(self, code: OFCode) -> Self;
}
impl<'s, 't, O> TrackParseResult<'s, 't, O> for ParseResult<'s, O> {
fn trace(self, code: OFCode) -> Self {
match self {
Ok(_) => self,
Err(e) => map_err(e, code),
}
}
}