Commit e107b53f authored by Per Lindgren's avatar Per Lindgren
Browse files

display for ast

parent 8637d12c
# Changelog for the repository
## 2020-09-03
- Updated ast with Display
## 2020-09-03
- Added src/comment
- single and multiline comments
......
use std::fmt;
// ast
#[derive(Debug)]
// println!("{:?}", ..)
#[derive(Debug)]
pub enum NumOrId {
Num(usize),
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() {
println!("minimal");
println!("{:?}", NumOrIdParser::new().parse("123"));
println!("{:?}", NumOrIdParser::new().parse("a1_a"));
println!("{}", NumOrIdParser::new().parse("123").unwrap());
println!("{}", NumOrIdParser::new().parse("a1_a").unwrap());
}
#[test]
fn parse_num_or_id() {
// println!("{:?}", NumOrIdParser::new().parse("123"));
// println!("{:?}", NumOrIdParser::new().parse("a1_a"));
assert_eq!(format!("{}", NumOrIdParser::new().parse("123").unwrap()), "123");
assert_eq!(format!("{}", NumOrIdParser::new().parse("a1_a").unwrap()), "a1_a");
}
......@@ -4,7 +4,7 @@ use crate::ast::*;
grammar;
pub NumOrId : NumOrId = {
pub NumOrId: NumOrId = {
Num => NumOrId::Num(<>),
Id => NumOrId::Id(<>),
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment