|
|
|
@ -16,11 +16,11 @@ pub enum Token {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Token {
|
|
|
|
|
fn print(&self) -> String {
|
|
|
|
|
fn print(&self) -> &str {
|
|
|
|
|
match &self {
|
|
|
|
|
Keyword(keyword) => keyword.to_owned(),
|
|
|
|
|
Str(string) => "String".to_owned(),
|
|
|
|
|
Array(tokens) => describe_token_array(&tokens),
|
|
|
|
|
Keyword(keyword) => keyword,
|
|
|
|
|
Str(_) => "String",
|
|
|
|
|
Array(_) => "Array",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -99,7 +99,7 @@ fn tokenize_file(file_path: &str) -> Vec<Vec<Token>> {
|
|
|
|
|
tokenize(&unparsed_file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn describe_token_array(line: &Vec<Token>) -> String {
|
|
|
|
|
fn describe_line(line: &Vec<Token>) -> String {
|
|
|
|
|
let mut description = "[".to_owned();
|
|
|
|
|
let mut iter = line.iter();
|
|
|
|
|
description.push_str(&format!("{}", iter.next().unwrap().print()));
|
|
|
|
@ -115,16 +115,17 @@ pub fn parse_file(file_path: &str) -> Vec<Command> {
|
|
|
|
|
let token_lines = tokenize_file(file_path);
|
|
|
|
|
let mut commands = Vec::new();
|
|
|
|
|
for line in token_lines {
|
|
|
|
|
println!("{:?}", line);
|
|
|
|
|
commands.push(match line.as_slice() {
|
|
|
|
|
[Str(text)] => Say {
|
|
|
|
|
name: None,
|
|
|
|
|
text: text.to_owned()
|
|
|
|
|
text: text.to_owned(),
|
|
|
|
|
},
|
|
|
|
|
[Str(name), Str(text)] => Say {
|
|
|
|
|
name: Some(name.to_owned()),
|
|
|
|
|
text: text.to_owned()
|
|
|
|
|
text: text.to_owned(),
|
|
|
|
|
},
|
|
|
|
|
_ => panic!("Unknown command {}", describe_token_array(&line)),
|
|
|
|
|
_ => panic!("Unknown command {}", describe_line(&line)),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
commands
|
|
|
|
|