···1919}
20202121/// The peeking functionality of concrete parsers.
2222-pub trait PeekerOperator {
2222+pub trait Peeker {
2323 /// The type of the elements.
2424 type Item: PeekerItem;
2525···2828 fn peek_for_token(&self, parser: &mut Parser) -> Option<Token>;
29293030 /// Peek for the next element. Implemented based on
3131- /// [PeekerOperator::peek_for_token].
3131+ /// [Peeker::peek_for_token].
3232 fn peek_for(&self, parser: &mut Parser) -> Option<Self::Item> {
3333 Self::Item::from_tok(
3434 self.peek_for_token(parser)?
···3636 }
3737}
38383939-/// Marks container input types at the trait-level.
4040-pub trait IsContainerInput {}
4141-/// Marks container types at the trait-level.
3939+/// Marks [ContainerCp] input types at the trait-level.
4040+pub trait IsContainerCpInput {}
4141+/// Marks [ContainerCp] types at the trait-level.
4242pub trait ContainedType {}
43434444/// Interface for containing data in the concrete parser structs.
4545-pub trait Container {
4545+pub trait ContainerCp {
4646 /// The type the concrete parsers are constructed from.
4747- type Input: IsContainerInput;
4747+ type Input: IsContainerCpInput;
4848 /// The type the concrete parser structs contain.
4949 type ContainedType: ContainedType;
5050···5454 fn new(value: Self::Input) -> Self;
5555}
56565757-/// Along with [PeekerOperator], defines the core functionality
5757+/// Along with [Peeker], defines the core functionality
5858/// of concrete parsers.
5959///
6060/// Has blanket implementation for all concrete parsers.
6161-pub trait Operator: PeekerOperator + Container {
6161+pub trait ConcreteParser: Peeker + ContainerCp {
6262 /// Peek the next token in the [Parser] stream. If it
6363- /// satisfies the criteria as specified by the [PeekerOperator]
6363+ /// satisfies the criteria as specified by the [Peeker]
6464 /// implementation, consume and return the [Token].
6565 fn try_next_token(&self, parser: &mut Parser) -> Option<Token>;
6666 /// Try to advance to the next element. Implemented based on
6767- /// [Operator::try_next_token].
6767+ /// [ConcreteParser::try_next_token].
6868 ///
6969 /// If the inner `try_next_token` consumes and returns the token,
7070 /// constructs and returns the element from it.
7171 ///
7272- /// Return type is the same as that of [PeekerOperator::peek_for].
7272+ /// Return type is the same as that of [Peeker::peek_for].
7373 fn try_next(&self, parser: &mut Parser) -> Option<Self::Item> {
7474 Self::Item::from_tok(
7575 self.try_next_token(parser)?
···7777 }
7878}
79798080-impl<T> Operator for T
8080+impl<T> ConcreteParser for T
8181where
8282- T: PeekerOperator + Container
8282+ T: Peeker + ContainerCp
8383{
8484 fn try_next_token(&self, parser: &mut Parser) -> Option<Token> {
8585 if let Some(tok) = self.peek_for_token(parser) {
···9191 }
9292}
93939494-impl IsContainerInput for String {}
9494+impl IsContainerCpInput for String {}
9595impl ContainedType for String {}
96969797-impl IsContainerInput for () {}
9797+impl IsContainerCpInput for () {}
9898impl ContainedType for () {}
9999100100mod exact_match;
101101mod or_exact_match;
102102mod any_str_match;
103103mod is_newline;
104104-pub use {
105105- exact_match::ExactMatch,
106106- or_exact_match::OrExactMatch,
107107- any_str_match::AnyStrMatch,
108108- is_newline::IsNewline,
109109-};
104104+/// All concrete parsers.
105105+pub mod list {
106106+ pub use super::{
107107+ exact_match::ExactMatch,
108108+ or_exact_match::OrExactMatch,
109109+ any_str_match::AnyStrMatch,
110110+ is_newline::IsNewline,
111111+ };
112112+}
···55/// In particular, match the [Token::Str] variant of
66/// the [Token] enum, and return the inner [String].
77pub struct AnyStrMatch;
88-impl PeekerOperator for AnyStrMatch {
88+impl Peeker for AnyStrMatch {
99 type Item = String;
10101111 fn peek_for_token(&self, parser: &mut Parser) -> Option<Token> {
···1515 }
1616 }
1717}
1818-impl Container for AnyStrMatch {
1818+impl ContainerCp for AnyStrMatch {
1919 type Input = ();
2020 type ContainedType = ();
2121
···66pub struct OrExactMatch {
77 matches: HashSet<String>
88}
99-impl PeekerOperator for OrExactMatch {
99+impl Peeker for OrExactMatch {
1010 type Item = String;
11111212 fn peek_for_token(&self, parser: &mut Parser) -> Option<Token> {
···2222 }
2323}
24242525-impl IsContainerInput for Vec<&'static str> {}
2525+impl IsContainerCpInput for Vec<&'static str> {}
2626impl ContainedType for HashSet<String> {}
27272828-impl Container for OrExactMatch {
2828+impl ContainerCp for OrExactMatch {
2929 type ContainedType = HashSet<String>;
3030 type Input = Vec<&'static str>;
3131
+2-2
src/parser/subparser.rs
···77/// tokens based on some pattern.
88///
99/// The pattern depends on the generic `C`, which corresponds
1010-/// to a concrete parser. (See [parsers].)
1010+/// to a concrete parser. (See [concrete_parser].)
1111pub trait ConcreteSubparser<C> {
1212 /// Build the subparser based on the concrete parser.
1313 fn subparse
1414 (value: C::Input, parser: &mut Parser) -> Parser
1515 where
1616- C: Container;
1616+ C: concrete_parser::ContainerCp;
1717}
18181919mod collect_till;
+4-4
src/parser/subparser/collect_till.rs
···11-use super::*;
11+use crate::prelude::*;
2233/// Consume tokens into a new parser until the concrete
44/// parser returns something. Stops when it hits `Some(_)`.
55///
66/// Said concrete pattern here is provided by
77/// the generic parameter `Op`.
88-pub struct CollectTill<Op: parsers::Operator>(Op);
88+pub struct CollectTill<Op: ConcreteParser>(Op);
99impl<Op> ConcreteSubparser<Op> for CollectTill<Op>
1010where
1111- Op: parsers::Operator
1111+ Op: ConcreteParser
1212{
1313 fn subparse
1414 (value: Op::Input, parser: &mut Parser) -> Parser
1515 where
1616- Op: Container
1616+ Op: concrete_parser::ContainerCp
1717 {
1818 let op = Op::new(value);
1919
+4-4
src/parser/subparser/collect_while.rs
···11-use super::*;
11+use crate::prelude::*;
2233/// Consume tokens into a new parser while the concrete
44/// parser returns something. Stop consuming if it returns
···66///
77/// Said concrete pattern here is provided by
88/// the generic parameter `Op`.
99-pub struct CollectWhile<Op: parsers::Operator>(Op);
99+pub struct CollectWhile<Op: ConcreteParser>(Op);
1010impl<Op> ConcreteSubparser<Op> for CollectWhile<Op>
1111where
1212- Op: parsers::Operator
1212+ Op: ConcreteParser
1313{
1414 fn subparse
1515 (value: <Op>::Input, parser: &mut Parser) -> Parser
1616 where
1717- Op: Container
1717+ Op: concrete_parser::ContainerCp
1818 {
1919 let op = Op::new(value);
2020
+2-2
tests/test_parsers.rs
···77fn test_exact_match() {
88 let mut parser = setup_space_seps_parser("lorem ipsum");
991010- let ipsum_parser = parsers::ExactMatch{
1010+ let ipsum_parser = ExactMatch{
1111 matches: String::from("ipsum")
1212 };
1313 parser.next();
···1818fn test_exact_match_try_next_advance_token() {
1919 let mut parser = setup_space_seps_parser("lorem ipsum");
20202121- let ipsum_parser = parsers::ExactMatch{
2121+ let ipsum_parser = ExactMatch{
2222 matches: String::from("lorem")
2323 };
2424 ipsum_parser.try_next(&mut parser);