add multi address with ,

This commit is contained in:
rick 2023-04-14 14:42:04 +02:00
parent 276cad9f09
commit cec3beaf90
Signed by: Rick
GPG key ID: 5CBE8779CD27BCBA
2 changed files with 27 additions and 13 deletions

View file

@ -6,8 +6,9 @@ pub enum Address {
Last,
Line(usize),
FromStartTo(usize),
FromToEnd(usize),
FromToEnd(usize), // pas sur ?
FromTo(usize, usize),
All,
Null,
}
@ -27,6 +28,8 @@ pub fn parse_address(addr: &str) -> Address {
if addr.is_empty() {
Address::Actual
} else if addr.contains(',') {
parse_multi_addr(addr)
} else if let Ok(l) = usize::from_str(addr) {
Address::Line(l)
} else {
@ -38,6 +41,29 @@ pub fn parse_address(addr: &str) -> Address {
}
}
fn parse_multi_addr(addr: &str) -> Address {
// garde con ou pas ?
let tmp: Vec<&str> = addr.split(",").collect();
if tmp.len() != 2 {
Address::Null
} else {
let start = usize::from_str(tmp[0]);
let end = usize::from_str(tmp[1]);
if let Ok(a) = start {
if let Ok(b) = end {
Address::FromTo(a, b)
} else {
Address::Line(a)
}
} else if let Ok(a) = end {
Address::FromStartTo(a)
} else {
Address::All
}
}
}
#[derive(Debug)]
pub enum Command {
Append(Address),

View file

@ -17,18 +17,6 @@ use nom::Err::Error;
const FILE : &'static str = "test";
/*
* .
* $
* [:digit:]
* '[:alpha:]
* /BRE/
* +[:digit:]
* -[:digit:]
* [:digit:],[:digit:]
* [:digit:];[:digit:]
*/
// TODO juste $ pour l'instant dans l'adresse
// TODO faire les commandes mais juste p pour l'instant
// TODO faire un système de retour d'erreur pour afficher ? et l'erreur si l'utilisateur le demande