use crate::{
Character,
TextInput
};
use pups_core::{
implement_modes,
Input,
Mode,
ModeResult::{
self,
Failure,
Success,
},
Parser
};
struct UnicodeIdentifier;
impl<'a, C, I> Parser<'a, I::Slice, (), (), I> for UnicodeIdentifier
where
C: Character,
I: Input<'a, Item = C> + TextInput,
{
fn apply<_Mode: Mode>(
&self,
input: &'a I
) -> ModeResult<I::Slice, (), (), _Mode> {
let start: usize = input.store_cursor();
if let Some (character) = input.peek() && character.is_unicode_identifier_start() {
input.advance();
loop {
let cursor: usize = input.store_cursor();
if let Some (character) = input.peek()
&& character.is_unicode_identifier_continuation() {
input.advance();
} else { break};
}
Success (
_Mode::convert_output(input.slice(start, input.store_cursor())),
_Mode::new_message_container()
)
} else { Failure (_Mode::convert_error(()), _Mode::new_message_container()) }
}
implement_modes!('a, I::Slice, (), (), I);
}
pub const fn unicode_identifier<'a, C, I>(
) -> impl Parser<'a, I::Slice, (), (), I>
where
C: Character,
I: Input<'a, Item = C> + TextInput,
{ UnicodeIdentifier }