From ce313753f555061ed8140a0664e73a3e60857d9b Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Mon, 13 May 2024 00:06:23 -0600 Subject: Fix another regression with aliases The last commit (1415c8f9b89699000ef8d864ff8f0e1bebca4a5f) fixed the issue with pipes, however, it did not fix it for IO. This patch adds some logic for the aliased verse to inherit the properties of the original verse, so that recite works properly for all verse types (regardless of IO, couplet, or meter). --- src/poem/read.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/poem/read.rs') diff --git a/src/poem/read.rs b/src/poem/read.rs index 875bf76..e5cd25d 100644 --- a/src/poem/read.rs +++ b/src/poem/read.rs @@ -68,6 +68,12 @@ impl Appendable for Poem { return Ok(()); } + // Check the meter + verse.meter = meter; + if last == Rune::Couplet || meter == Rune::Couplet { + verse.couplet = true; + } + // Check for aliases match env.aliases.get(&verse.verb()) { Some(alias) => { @@ -80,32 +86,23 @@ impl Appendable for Poem { None => unreachable!(), // Should be caught by a Mishap above }; - // If the verse has a clause, add it to the last verse in - // the poem from the alias + // The last verse inherits the traits from the original + lv.couplet = verse.couplet; + lv.io = verse.io; + lv.poems = verse.poems.clone(); + lv.meter = verse.meter; if verse.clause().is_some() { for word in verse.clause().unwrap().iter() { lv.stanza.push(word.to_string()); } } - // Check the meter - lv.meter = meter; - if last == Rune::Couplet || meter == Rune::Couplet { - verse.couplet = true; - } - // Push verse(s) for v in poem.iter() { self.push(v.clone()); } } None => { - // Check the meter - verse.meter = meter; - if last == Rune::Couplet || meter == Rune::Couplet { - verse.couplet = true; - } - // Push verse(s) self.push(verse.clone()); } @@ -162,8 +159,6 @@ impl Readable for Poem { None => { // Check for IO parse errors if last == Rune::Read || last == Rune::Write || last == Rune::Addendum { - println!("err 0"); - println!("{:?}", verse); return Err(Mishap::IOMishap(j, i, ' ')); } @@ -173,7 +168,6 @@ impl Readable for Poem { // Throw an error if the verse is empty if verse.is_empty() && (last == Rune::Couplet || last == Rune::And) { - println!("err 1"); return Err(Mishap::ParseMishap(j, i, ' ')); } -- cgit v1.2.3