| 1 |
#![cfg_attr(not(feature = "std"), no_std)] |
| 2 |
#![cfg_attr(feature = "unstable", feature(error_in_core))] |
| 3 |
|
| 4 |
use std::fmt::Display; |
| 5 |
|
| 6 |
pub mod error; |
| 7 |
mod slice; |
| 8 |
pub mod str; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] |
| 17 |
pub enum RuleResult<T> { |
| 18 |
|
| 19 |
Matched(usize, T), |
| 20 |
|
| 21 |
|
| 22 |
Failed, |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
#[allow(clippy::needless_lifetimes)] |
| 27 |
pub 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 |
|
| 34 |
|
| 35 |
pub trait ParseElem<'input>: Parse { |
| 36 |
|
| 37 |
type Element: Copy; |
| 38 |
|
| 39 |
|
| 40 |
fn parse_elem(&'input self, pos: usize) -> RuleResult<Self::Element>; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
pub trait ParseLiteral: Parse { |
| 45 |
|
| 46 |
|
| 47 |
fn parse_string_literal(&self, pos: usize, literal: &str) -> RuleResult<()>; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
pub trait ParseSlice<'input>: Parse { |
| 52 |
|
| 53 |
type Slice; |
| 54 |
|
| 55 |
|
| 56 |
fn parse_slice(&'input self, p1: usize, p2: usize) -> Self::Slice; |
| 57 |
} |
| 58 |
|
| 59 |
#[cfg(not(feature = "std"))] |
| 60 |
extern crate alloc; |
| 61 |
#[cfg(not(feature = "std"))] |
| 62 |
extern crate core as std; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#[doc(hidden)] |
| 67 |
pub fn call_custom_closure<I, T>(f: impl FnOnce(I, usize) -> RuleResult<T>, input: I, pos: usize) -> RuleResult<T> { |
| 68 |
f(input, pos) |
| 69 |
} |