Skip to content

Commit

Permalink
feat: add new() for Tree and TreeMap (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Jan 31, 2023
1 parent eadc682 commit e797abf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn parse_map(map: &SourceMap) -> Result<TreeMap, Box<Report>> {
)),
}))
} else {
Ok(TreeMap { trees })
Ok(TreeMap::new(trees))
}
}

Expand All @@ -69,8 +69,5 @@ pub fn construct(source: &Source, tokens: &[Token]) -> Result<Tree, Box<Report>>

let definitions = definition::tree(&mut state)?;

state.finish(Tree {
source: source.name().to_string(),
definitions,
})
state.finish(Tree::new(source.name(), definitions))
}
15 changes: 15 additions & 0 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ pub struct TreeMap {
pub trees: Vec<Tree>,
}

impl TreeMap {
pub fn new(trees: Vec<Tree>) -> Self {
Self { trees }
}
}

#[derive(Debug)]
pub struct Tree {
pub source: String,
pub definitions: DefinitionTree,
}

impl Tree {
pub fn new<S: Into<String>>(source: S, definitions: DefinitionTree) -> Self {
Self {
source: source.into(),
definitions,
}
}
}

pub trait Node: Any {
/// The comments associated with the node.
fn comments(&self) -> Option<&CommentGroup> {
Expand Down

0 comments on commit e797abf

Please sign in to comment.