1#![cfg_attr(not(feature = "std"), no_std)]
2#![cfg_attr(feature = "unstable", feature(error_in_core))]
3
4use std::fmt::Display;
5
6pub mod error;
7mod slice;
8pub mod str;
9
10#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
17pub enum RuleResult<T> {
18 Matched(usize, T),
20
21 Failed,
23}
24
25#[allow(clippy::needless_lifetimes)]
27pub trait Parse {
28 type PositionRepr: Display;
29 fn start<'input>(&'input self) -> usize;
30 fn is_eof<'input>(&'input self, p: usize) -> bool;
31 fn position_repr<'input>(&'input self, p: usize) -> Self::PositionRepr;
32}
33
34pub trait ParseElem<'input>: Parse {
36 type Element: Copy;
38
39 fn parse_elem(&'input self, pos: usize) -> RuleResult<Self::Element>;
41}
42
43pub trait ParseLiteral: Parse {
45 fn parse_string_literal(&self, pos: usize, literal: &str) -> RuleResult<()>;
48}
49
50pub trait ParseSlice<'input>: Parse {
52 type Slice;
54
55 fn parse_slice(&'input self, p1: usize, p2: usize) -> Self::Slice;
57}
58
59#[cfg(not(feature = "std"))]
60extern crate alloc;
61#[cfg(not(feature = "std"))]
62extern crate core as std;
63
64#[doc(hidden)]
67pub fn call_custom_closure<I, T>(f: impl FnOnce(I, usize) -> RuleResult<T>, input: I, pos: usize) -> RuleResult<T> {
68 f(input, pos)
69}