Skip to content

Commit 8a2934e

Browse files
dspinellissylvestre
authored andcommitted
Refactor struct + enum pair into a tagged enum
This removes invalid states and simplifies pattern matching. It also makes it easier to add further address extensions.
1 parent a0d82d6 commit 8a2934e

File tree

3 files changed

+127
-256
lines changed

3 files changed

+127
-256
lines changed

src/sed/command.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,13 @@ pub struct StringSpace {
8686
pub has_newline: bool, // True if \n-terminated
8787
}
8888

89-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
90-
/// Types of address specifications that precede commands
91-
pub enum AddressType {
92-
Re, // Line that matches regex
93-
Line, // Specific line
94-
RelLine, // Relative line
95-
Last, // Last line
96-
}
97-
9889
#[derive(Debug)]
99-
/// Format of an address
100-
pub struct Address {
101-
pub atype: AddressType, // Address type
102-
pub value: AddressValue, // Line number or regex
103-
}
104-
105-
#[derive(Debug)]
106-
pub enum AddressValue {
107-
LineNumber(usize),
108-
Regex(Option<Regex>),
90+
/// Types of address specifications that precede commands
91+
pub enum Address {
92+
Re(Option<Regex>), // Line that matches (optional) regex
93+
Line(usize), // Specific line
94+
RelLine(usize), // Relative line
95+
Last, // Last line
10996
}
11097

11198
#[derive(Debug)]

0 commit comments

Comments
 (0)