diff --git a/demo/demo.rpy b/demo/demo.rpy index 54b0d05..69be8ba 100644 --- a/demo/demo.rpy +++ b/demo/demo.rpy @@ -1,3 +1,3 @@ "Bob sat on the bench." "Bob" "Good morning!" -eat "apple" \ No newline at end of file +eat \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index a459740..775617b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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> { tokenize(&unparsed_file) } -fn describe_token_array(line: &Vec) -> String { +fn describe_line(line: &Vec) -> 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 { 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