1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::fmt::Display;
use std::fmt::Debug;
use std::fmt::Formatter;

use crate::*;

/// Parses a `String` of one or more alphabetic characters.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Letters;

impl Expect for Letters {

	type Target = String;

	fn expect_from(parser: &mut Parser) -> Result<Self::Target> {
			
		let string: String = parser.clone().take_while(|character| character.is_alphabetic()).collect();

		if string.is_empty() { Err(Unexpected::from(parser.clone())) }

		else {

			parser.advance_by(string.len());

			Ok(string)

		}
	
	}

}