diff options
Diffstat (limited to 'src/recite.rs')
-rw-r--r-- | src/recite.rs | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/recite.rs b/src/recite.rs index f75cd61..074f723 100644 --- a/src/recite.rs +++ b/src/recite.rs @@ -289,6 +289,28 @@ impl Verse { fn clause(&self) -> Vec<String> { self.stanza.clause.clone() } + + /// Check if this verse is piping output + fn couplet(verse: Option<&Verse>) -> bool { + match verse { + Some(verse) => match verse.meter { + Meter::Couplet | Meter::Quiet | Meter::And | Meter::String => true, + Meter::None => false, + }, + None => false, + } + } + + /// Check if this verse has a meter + fn cadence(verse: Option<&Verse>) -> bool { + match verse { + Some(verse) => match verse.meter { + Meter::Couplet | Meter::Quiet | Meter::And | Meter::String => true, + Meter::None => false, + }, + None => false, + } + } } /// An entire shell command parsed into [verse's][Verse] @@ -428,34 +450,13 @@ impl Poem { // Get the next character in the input string let char = chars.next(); - // Check if the previous verse is piping output to current - // TODO: Don't need to run this on each iteration of the loop, just when - // a stanza is pushed to a verse - let couplet = match prev { - Some(prev) => match prev.meter { - Meter::Couplet => true, - Meter::Quiet | Meter::And | Meter::String | Meter::None => false, - }, - None => false, - }; - - // Check if the previous verse was metered - // Need this to check for parse/input errors - let metered = match prev { - Some(prev) => match prev.meter { - Meter::Couplet | Meter::Quiet | Meter::And | Meter::String => true, - Meter::None => false, - }, - None => false, - }; - // Do something depending on what the character is match char { // Print an error, and return None if a Meter was used without // a Stanza before it Some(meter) if (meter == '|' || meter == '&' || meter == ';') - && metered + && Verse::cadence(prev) && stanza.is_empty() => { // TODO: Add more verbose error message @@ -475,7 +476,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::Couplet, - couplet, + Verse::couplet(prev), )); // Clear the stacks @@ -504,7 +505,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::And, - couplet, + Verse::couplet(prev), )); } @@ -514,7 +515,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::Quiet, - couplet, + Verse::couplet(prev), )); } @@ -525,7 +526,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::Quiet, - couplet, + Verse::couplet(prev), )); // We can break out of the loop here, since it's @@ -551,7 +552,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::String, - couplet, + Verse::couplet(prev), )); stanza.clear(); @@ -584,7 +585,7 @@ impl Poem { verses.push(Verse::new( Stanza::new(stanza.clone()), Meter::None, - couplet, + Verse::couplet(prev), )); } |