Skip to content

Commit

Permalink
syntest constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Jun 9, 2024
1 parent 1bfda3d commit a17d021
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
24 changes: 24 additions & 0 deletions crates/syntest/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::rc::Rc;

/// Helper functions for macros
#[derive(Debug)]
pub struct Const {
file: Rc<syn::File>,
}

impl Const {
pub fn new(file: Rc<syn::File>) -> Self {
Self { file }
}

pub fn constants(&self) -> Vec<syn::ItemConst> {
self.file
.items
.iter()
.filter_map(|item| match item {
syn::Item::Const(item) => Some(item.clone()),
_ => None,
})
.collect()
}
}
4 changes: 4 additions & 0 deletions crates/syntest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
mod constants;
mod func;
mod mac;
mod mutation;
mod syn;
mod syntest;
mod var;

pub use constants::Const;
pub use mutation::Mutation;
pub use syn::*;
pub use syntest::Syntest;
pub use var::{LocalVariable, Value};
2 changes: 2 additions & 0 deletions crates/syntest/src/syn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub use syn::parse_quote;
pub use syn::Type;
7 changes: 5 additions & 2 deletions crates/syntest/src/syntest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use syn::{
parse_file, punctuated::Punctuated, token::PathSep, BinOp, Expr, Lit, Pat, PathSegment, Stmt,
};

use crate::{func::Func, mac::Mac, var::LocalVariable, Value};
use crate::{constants::Const, func::Func, mac::Mac, var::LocalVariable, Value};

pub struct Syntest {
pub file: Rc<syn::File>,
pub mac: Mac,
pub constant: Const,
pub file: Rc<syn::File>,
}

impl Syntest {
Expand All @@ -18,6 +19,7 @@ impl Syntest {

Ok(Self {
mac: Mac::new(Rc::clone(&file)),
constant: Const::new(Rc::clone(&file)),
file,
})
}
Expand All @@ -27,6 +29,7 @@ impl Syntest {

Ok(Self {
mac: Mac::new(Rc::clone(&file)),
constant: Const::new(Rc::clone(&file)),
file: Rc::new(parse_file(code)?),
})
}
Expand Down

0 comments on commit a17d021

Please sign in to comment.