1extern crate honeycomb;
2use honeycomb::{
3 atoms::{opt, seq_no_ws, space, sym},
4 language::alpha,
5 transform::collect,
6 Parser,
7};
8
9#[derive(Clone, PartialEq, Debug)]
10struct Word(String);
11
12#[derive(Clone, PartialEq, Debug)]
13enum Punctuation {
14 Period,
15 QuestionMark,
16 ExclamationPoint,
17}
18
19#[derive(Clone, PartialEq, Debug)]
20struct Sentence {
21 words: Vec<Word>,
22 punctuation: Punctuation,
23}
24
25fn word() -> Parser<Word> {
26 (space() >> (alpha() * (1..)) << space()) - collect - Word
27}
28
29fn punctuation() -> Parser<Punctuation> {
30 ((sym('.') * (1..)) - |_| Punctuation::Period)
31 | ((sym('?') * (1..)) - |_| Punctuation::QuestionMark)
32 | ((sym('!') * (1..)) - |_| Punctuation::ExclamationPoint)
33}
34
35fn sentence() -> Parser<Sentence> {
36 (word().is() >> (((word() << opt(seq_no_ws(","))) * (1..)) & punctuation()))
37 - |phrase: (Vec<Word>, Punctuation)| Sentence {
38 words: phrase.0,
39 punctuation: phrase.1,
40 }
41}
42
43fn paragraph() -> Parser<Vec<Sentence>> {
44 sentence() * (1..)
45}
46
47fn main() {
48 println!(
49 "{:#?}",
50 paragraph().parse(
51 r#"
52
53I look at you all see the love there thats sleeping,
54While my guitar gently weeps.
55I look at the floor and I see it needs sweeping
56Still my guitar gently weeps.
57I dont know why nobody told you
58How to unfold your love.
59I dont know how someone controlled you.
60They bought and sold you.
61I look at the world and I notice its turning
62While my guitar gently weeps.
63With every mistake we must surely be learning,
64Still my guitar gently weeps.
65"#
66 )
67 );
68}