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
|
use core::fmt;
/// Describes one or two characters from the input
///
/// [Rune]s are a way to mark special characters from the input string (i.e.
/// poetry). Some [Rune]s are special--as they denote the end of a [Verse]--
/// and are refered to as a Meter. For instance, `Addendum`, `Couplet`,
/// `Quiet`, and `And`, are all meters. Meters also determine how the
/// [Stanza][super::stanza::Stanza] should be interpreted. For instance, a
/// [Stanza][super::stanza::Stanza] that is piped needs to have
/// its `STDOUT` captured (rather than printing out to the terminal), and
/// subsequently sent to the next [Verse] in the [Poem][super::super::Poem].
///
/// # Values
/// * `None` - A shell command with no additional actions (the end of a poem)
/// * `Pause` - The space character, to dilineate words (` `)
/// * `Path` - The forward slash character, to dilineate paths (`/`)
/// * `Remark` - Indicates a single line comment (`#`)
/// * `String` - Interpret all character as one large
/// [Word][super::word::Word] (`'` or `"`)
/// * `Poem` - A subcommand to run first (`\``)
/// * `Read` - Read files into STDIN (`<`)
/// * `Write` - Write STDOUT to a file (`>`)
/// * `Addendum` - Append STDOUT to a file (`>>`)
/// * `Couplet` - Pipe the output of this command into the next (`|`)
/// * `Quiet` - Fork the called process into the background (`&`)
/// * `And` - Run the next command only if this one succeeds (`&&`)
/// * `Continue` - String commands together on a single line (`;`)
/// * `Home` - Interpret `~` as `$HOME`
/// * `Else` - Any other character
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum Rune {
None, // No meter (the end of a poem)
Pause, // A space
Path, // A forward slash
Remark, // A comment
String, // Interpret the following as one large [Word]
Poem, // Run a sub-poem before the main one
Read, // Read files into STDIN
Write, // Send STDOUT to a file
Write2, // Send STDERR to a file
WriteAll, // Send STDOUT and STDERR to a file
Addendum, // Append STDOUT to a file
Addendum2, // Append STDERR to a file
AddendumAll, // Append STDOUT and STDERR to a file
Couplet, // Pipe the output of this command into the next
Quiet, // Fork the command into the background
And, // Run the next command only if this succeeds
Continue, // Run the next command, even if this doesn't succeed
Home, // Interpret '~' as $HOME
Else, // Any other character
}
impl fmt::Display for Rune {
/// Determine how to print out a [Rune]
///
/// Each [Rune]'s symbol corresponds to its input.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let rune = match self {
Rune::None => "",
Rune::Pause => " ",
Rune::Path => "/",
Rune::Remark => "#",
Rune::String => "\"",
Rune::Poem => "`",
Rune::Read => "<",
Rune::Write => ">",
Rune::Write2 => "2>",
Rune::WriteAll => "&>",
Rune::Addendum => ">>",
Rune::Addendum2 => "2>>",
Rune::AddendumAll => "&>>",
Rune::Couplet => "|",
Rune::Quiet => "&",
Rune::And => "&&",
Rune::Continue => ";",
Rune::Home => "~",
Rune::Else => "_",
};
write!(f, "{}", rune)
}
}
|