lint: clippy fixes
This commit is contained in:
parent
5e072c0773
commit
cbdff2c170
5 changed files with 28 additions and 27 deletions
|
@ -13,7 +13,7 @@ struct Args {
|
|||
#[derive(Debug, Subcommand)]
|
||||
enum Command {
|
||||
#[clap(name = "-c", about = "Run a program passed in as a string")]
|
||||
RunCommand { command: String },
|
||||
RunCmd { command: String },
|
||||
|
||||
#[clap(about = "Run a Mute file")]
|
||||
Run { file: String },
|
||||
|
@ -28,15 +28,15 @@ fn main() {
|
|||
match args.command {
|
||||
Command::Run { file } => {
|
||||
let input = std::fs::read_to_string(file).unwrap();
|
||||
let env = Environment::new();
|
||||
let env = Environment::default();
|
||||
let res = run(&env, &input);
|
||||
match res {
|
||||
Ok(expressions) => expressions.into_iter().for_each(|expr| println!("{expr}")),
|
||||
Err(err) => println!("{}", err),
|
||||
}
|
||||
}
|
||||
Command::RunCommand { command } => {
|
||||
let env = Environment::new();
|
||||
Command::RunCmd { command } => {
|
||||
let env = Environment::default();
|
||||
let res = run(&env, &command);
|
||||
match res {
|
||||
Ok(expressions) => expressions.into_iter().for_each(|expr| println!("{expr}")),
|
||||
|
@ -49,11 +49,11 @@ fn main() {
|
|||
|
||||
fn run(env: &Environment, command: &str) -> Result<Vec<Node>> {
|
||||
let ast = parse(command)?;
|
||||
eval(&env, ast)
|
||||
eval(env, ast)
|
||||
}
|
||||
|
||||
fn repl() {
|
||||
let env = Environment::new();
|
||||
let env = Environment::default();
|
||||
let mut rl = DefaultEditor::new().unwrap();
|
||||
|
||||
println!("Mute -- REPL");
|
||||
|
|
1
src/env/core.rs
vendored
1
src/env/core.rs
vendored
|
@ -68,7 +68,6 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
},
|
||||
_ => Ok(node),
|
||||
})
|
||||
.map(|node| node)
|
||||
.collect::<Result<Vec<Node>, _>>()?;
|
||||
|
||||
Ok(Node::List(inner))
|
||||
|
|
34
src/env/mod.rs
vendored
34
src/env/mod.rs
vendored
|
@ -17,22 +17,6 @@ pub struct RawEnvironment {
|
|||
}
|
||||
|
||||
impl Environment {
|
||||
pub fn new() -> Environment {
|
||||
let mut env = HashMap::new();
|
||||
let core = core::core();
|
||||
let io = io::io();
|
||||
|
||||
env.extend(core);
|
||||
env.extend(io);
|
||||
|
||||
let env = RawEnvironment {
|
||||
current: RefCell::new(env),
|
||||
outer: None,
|
||||
};
|
||||
|
||||
Environment(Rc::new(env))
|
||||
}
|
||||
|
||||
pub fn get(&self, ident: &str) -> Option<Node> {
|
||||
if let Some(val) = self.0.current.borrow().get(ident) {
|
||||
return Some(val.clone());
|
||||
|
@ -54,3 +38,21 @@ impl Environment {
|
|||
self.0.current.borrow_mut().insert(ident, val);
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for Environment {
|
||||
fn default() -> Self {
|
||||
let mut env = HashMap::new();
|
||||
let core = core::core();
|
||||
let io = io::io();
|
||||
|
||||
env.extend(core);
|
||||
env.extend(io);
|
||||
|
||||
let env = RawEnvironment {
|
||||
current: RefCell::new(env),
|
||||
outer: None,
|
||||
};
|
||||
|
||||
Environment(Rc::new(env))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ mod test {
|
|||
#[case("(str (+ 1 2))", "3")]
|
||||
#[case("(str (list 1 2 3))", "(1 2 3)")]
|
||||
fn test_evaluator(#[case] input: &str, #[case] expected: &str) {
|
||||
let env = Environment::new();
|
||||
let env = Environment::default();
|
||||
let ast = parser::parse_str(input).unwrap();
|
||||
let res = eval(&env, ast)
|
||||
.unwrap()
|
||||
|
@ -215,7 +215,7 @@ mod test {
|
|||
#[case("(not-a-func :uwu)")]
|
||||
#[case("{:a}")]
|
||||
fn test_evaluator_fail(#[case] input: &str) {
|
||||
let env = Environment::new();
|
||||
let env = Environment::default();
|
||||
let ast = parser::parse_str(input).unwrap();
|
||||
let res = eval(&env, ast);
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ use crate::{Error, Node};
|
|||
|
||||
pub fn parse_str(input: &str) -> crate::Result<Vec<Node>> {
|
||||
let mut tokens = lexer::read(input)
|
||||
.map_err(|err| Error::ParserError(err))?
|
||||
.map_err(Error::ParserError)?
|
||||
.into_iter()
|
||||
.peekable();
|
||||
let mut ast = Vec::new();
|
||||
|
||||
while let Some(node) = next_statement(&mut tokens).map_err(|err| Error::ParserError(err))? {
|
||||
while let Some(node) = next_statement(&mut tokens).map_err(Error::ParserError)? {
|
||||
ast.push(node)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue