Skip to content
Snippets Groups Projects
Commit e107b53f authored by Per Lindgren's avatar Per Lindgren
Browse files

display for ast

parent 8637d12c
Branches
No related tags found
No related merge requests found
# Changelog for the repository # Changelog for the repository
## 2020-09-03
- Updated ast with Display
## 2020-09-03 ## 2020-09-03
- Added src/comment - Added src/comment
- single and multiline comments - single and multiline comments
......
use std::fmt;
// ast // ast
// println!("{:?}", ..)
#[derive(Debug)] #[derive(Debug)]
pub enum NumOrId { pub enum NumOrId {
Num(usize), Num(usize),
Id(String), Id(String),
} }
// println!("{}", ..)
impl fmt::Display for NumOrId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
NumOrId::Num(i) => write!(f, "{}", i)?,
NumOrId::Id(s) => write!(f, "{}", s)?,
};
Ok(())
}
}
\ No newline at end of file
...@@ -10,10 +10,13 @@ fn main() { ...@@ -10,10 +10,13 @@ fn main() {
println!("minimal"); println!("minimal");
println!("{:?}", NumOrIdParser::new().parse("123")); println!("{:?}", NumOrIdParser::new().parse("123"));
println!("{:?}", NumOrIdParser::new().parse("a1_a")); println!("{:?}", NumOrIdParser::new().parse("a1_a"));
println!("{}", NumOrIdParser::new().parse("123").unwrap());
println!("{}", NumOrIdParser::new().parse("a1_a").unwrap());
} }
#[test] #[test]
fn parse_num_or_id() { fn parse_num_or_id() {
// println!("{:?}", NumOrIdParser::new().parse("123")); assert_eq!(format!("{}", NumOrIdParser::new().parse("123").unwrap()), "123");
// println!("{:?}", NumOrIdParser::new().parse("a1_a")); assert_eq!(format!("{}", NumOrIdParser::new().parse("a1_a").unwrap()), "a1_a");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment