|
@ -1,14 +1,14 @@ |
|
|
pub fn parse_line(line: &str) -> (&str, Vec<&str>) {
|
|
|
pub fn parse_line(line: &str) -> (&str, Vec<&str>) {
|
|
|
let tokens = tokenize(line);
|
|
|
let tokens = tokenize(line);
|
|
|
|
|
|
|
|
|
let command = tokens[0];
|
|
|
|
|
|
|
|
|
let keyword = tokens[0];
|
|
|
let mut args: Vec<&str> = Vec::new();
|
|
|
let mut args: Vec<&str> = Vec::new();
|
|
|
|
|
|
|
|
|
if tokens.len() > 1 {
|
|
|
if tokens.len() > 1 {
|
|
|
args = tokens[1..].to_vec();
|
|
|
args = tokens[1..].to_vec();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
(command, args)
|
|
|
|
|
|
|
|
|
(keyword, args)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn tokenize(line: &str) -> Vec<&str> {
|
|
|
fn tokenize(line: &str) -> Vec<&str> {
|
|
@ -22,16 +22,16 @@ mod tests { |
|
|
#[test]
|
|
|
#[test]
|
|
|
fn test_tokenize() {
|
|
|
fn test_tokenize() {
|
|
|
assert_eq!(
|
|
|
assert_eq!(
|
|
|
tokenize("test arg1 arg2 arg3"),
|
|
|
|
|
|
vec!["test", "arg1", "arg2", "arg3"]
|
|
|
|
|
|
|
|
|
tokenize("keyword arg1 arg2 arg3"),
|
|
|
|
|
|
vec!["keyword", "arg1", "arg2", "arg3"]
|
|
|
);
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn test_parse_line() {
|
|
|
fn test_parse_line() {
|
|
|
assert_eq!(
|
|
|
assert_eq!(
|
|
|
parse_line("test arg1 arg2 arg3"),
|
|
|
|
|
|
("test", vec!["arg1", "arg2", "arg3"])
|
|
|
|
|
|
|
|
|
parse_line("keyword arg1 arg2 arg3"),
|
|
|
|
|
|
("keyword", vec!["arg1", "arg2", "arg3"])
|
|
|
);
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|