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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//!The crate provides a basic mechanism to parse grammars using Logo as a lexer
//! and a simple recursive descendant LL(1) parser with a backtracking function.
//!
//! # Example
//!```
//!     use crate::parsit::token;
//!     use crate::parsit::step::Step;
//!     use crate::parsit::parser::EmptyToken;
//!     use crate::parsit::parser::Parsit;
//!     use crate::parsit::error::ParseError;
//!     use logos::Logos;
//!
//!
//!     #[derive(Logos, Debug, Copy, Clone, PartialEq)]
//!     pub enum Token<'a> {
//!         #[regex(r"[a-zA-Z-]+")]
//!         Word(&'a str),
//!
//!         #[token(",")]
//!         Comma,
//!         #[token(".")]
//!         Dot,
//!
//!         #[token("!")]
//!         Bang,
//!         #[token("?")]
//!         Question,
//!
//!         #[regex(r"[ \t\r\n]+", logos::skip)]
//!         Whitespace,
//!     }
//!
//!     #[derive(Debug, Copy, Clone, PartialEq)]
//!     enum Item<'a> {
//!         Word(&'a str),
//!         Comma,
//!     }
//!     #[derive(Debug, Clone, PartialEq)]
//!     enum Sentence<'a> {
//!         Sentence(Vec<Item<'a>>),
//!         Question(Vec<Item<'a>>),
//!         Exclamation(Vec<Item<'a>>),
//!     }
//!
//!     struct Parser<'a> {
//!         inner: Parsit<'a, Token<'a>>,
//!     }
//!
//!     impl<'a> Parser<'a> {
//!         fn new(text: &'a str) -> Parser<'a> {
//!             let delegate: Parsit<Token> = Parsit::new(text).unwrap();
//!             Parser { inner: delegate }
//!         }
//!
//!         fn sentence(&self, pos: usize) -> Step<'a,Sentence<'a>> {
//!             let items = |p| self.inner.one_or_more(p, |p| self.word(p));
//!
//!             let sentence = |p| items(p)
//!                 .then_zip(|p| token!(self.inner.token(p) => Token::Dot))
//!                 .take_left()
//!                 .map(Sentence::Sentence);
//!
//!             let exclamation = |p| items(p)
//!                 .then_zip(|p| token!(self.inner.token(p) => Token::Bang))
//!                 .take_left()
//!                 .map(Sentence::Exclamation);
//!             let question = |p| items(p)
//!                 .then_zip(|p| token!(self.inner.token(p) => Token::Question))
//!                 .take_left()
//!                 .map(Sentence::Question);
//!
//!             sentence(pos)
//!                 .or_from(pos)
//!                 .or(exclamation)
//!                 .or(question).into()
//!         }
//!         fn word(&self, pos: usize) -> Step<'a,Item<'a>> {
//!             token!(self.inner.token(pos) =>
//!                      Token::Word(v) => Item::Word(v),
//!                      Token::Comma => Item::Comma
//!             )
//!         }
//!         fn text(&self) -> Result<Vec<Sentence<'a>>, ParseError<'a>> {
//!             self.inner.zero_or_more(0, |p| self.sentence(p)).into()
//!         }
//!     }
//!
//!
//!         let parser = Parser::new(r#"
//!             I have a strange addiction,
//!             It often sets off sparks!
//!             I really cannot seem to stop,
//!             Using exclamation marks!
//!             Anyone heard of the interrobang?
//!             The poem is for kids.
//!         "#);
//!
//!         let result = parser.text();
//!         println!("{:?}",result);
//!
//! ```
//!
//!

pub mod lexer;
pub mod step;
pub mod parser;
pub mod error;
pub mod test;