summaryrefslogtreecommitdiffstats
path: root/src/poem/read/parse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poem/read/parse.rs')
-rw-r--r--src/poem/read/parse.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/poem/read/parse.rs b/src/poem/read/parse.rs
index 0836eea..70367c4 100644
--- a/src/poem/read/parse.rs
+++ b/src/poem/read/parse.rs
@@ -63,7 +63,7 @@ macro_rules! remark {
/// Same as the [string!] macro, but don't `continue`
#[macro_export]
macro_rules! poem {
- ($chars:expr, $j:expr, $i:expr, $c:expr, $verse:expr, $word:expr) => {
+ ($chars:expr, $j:expr, $i:expr, $c:expr, $verse:expr, $word:expr, $env:expr) => {
let token = $c;
let mut poetry = Word::new();
loop {
@@ -76,7 +76,7 @@ macro_rules! poem {
}
}
}
- let sp = Poem::read(poetry.iter().collect());
+ let sp = Poem::read(poetry.iter().collect(), $env);
let sp = match sp {
Ok(sp) => sp,
Err(e) => return Err(e),
@@ -85,3 +85,31 @@ macro_rules! poem {
$word.push('\x0b');
};
}
+
+/// Append a verse to the poem
+///
+/// Append a verse to poem, first checking for aliases in the environment, and
+/// processing the alias first, if necessary.
+#[macro_export]
+macro_rules! append {
+ ($poem:expr, $last:expr, $meter:expr, $verse:expr, $env:expr) => {
+ if !$verse.is_empty() {
+ match $env.aliases.get(&$verse.verb()) {
+ Some(alias) => {
+ let alias = alias.to_string();
+ let mut poem = Poem::read(alias, $env)?;
+ let len = poem.len();
+ for (i, verse) in poem.iter_mut().enumerate() {
+ if $verse.clause().is_some() && i + 1 == len {
+ verse.stanza.append(&mut $verse.clause().unwrap());
+ }
+ $poem.push(verse.clone());
+ }
+ }
+ None => {
+ $poem.add(&mut $verse, $last, $meter);
+ }
+ }
+ }
+ };
+}