Refactor evaluators and resolvers into common form (#258)
This commit is contained in:
parent
bc79d16eac
commit
28a57d9828
@ -2,7 +2,19 @@ use common::*;
|
||||
|
||||
use brev;
|
||||
|
||||
pub fn evaluate_assignments<'a>(
|
||||
pub struct AssignmentEvaluator<'a: 'b, 'b> {
|
||||
pub assignments: &'b Map<&'a str, Expression<'a>>,
|
||||
pub evaluated: Map<&'a str, String>,
|
||||
pub exports: &'b Set<&'a str>,
|
||||
pub overrides: &'b Map<&'b str, &'b str>,
|
||||
pub quiet: bool,
|
||||
pub scope: &'b Map<&'a str, String>,
|
||||
pub shell: &'b str,
|
||||
pub dry_run: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||
pub fn evaluate_assignments(
|
||||
assignments: &Map<&'a str, Expression<'a>>,
|
||||
overrides: &Map<&str, &str>,
|
||||
quiet: bool,
|
||||
@ -27,18 +39,6 @@ pub fn evaluate_assignments<'a>(
|
||||
Ok(evaluator.evaluated)
|
||||
}
|
||||
|
||||
pub struct AssignmentEvaluator<'a: 'b, 'b> {
|
||||
pub assignments: &'b Map<&'a str, Expression<'a>>,
|
||||
pub evaluated: Map<&'a str, String>,
|
||||
pub exports: &'b Set<&'a str>,
|
||||
pub overrides: &'b Map<&'b str, &'b str>,
|
||||
pub quiet: bool,
|
||||
pub scope: &'b Map<&'a str, String>,
|
||||
pub shell: &'b str,
|
||||
pub dry_run: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||
pub fn evaluate_line(
|
||||
&mut self,
|
||||
line: &[Fragment<'a>],
|
||||
|
@ -2,7 +2,16 @@ use common::*;
|
||||
|
||||
use CompilationErrorKind::*;
|
||||
|
||||
pub fn resolve_assignments<'a>(
|
||||
pub struct AssignmentResolver<'a: 'b, 'b> {
|
||||
assignments: &'b Map<&'a str, Expression<'a>>,
|
||||
assignment_tokens: &'b Map<&'a str, Token<'a>>,
|
||||
stack: Vec<&'a str>,
|
||||
seen: Set<&'a str>,
|
||||
evaluated: Set<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
|
||||
pub fn resolve_assignments(
|
||||
assignments: &Map<&'a str, Expression<'a>>,
|
||||
assignment_tokens: &Map<&'a str, Token<'a>>,
|
||||
) -> CompilationResult<'a, ()> {
|
||||
@ -22,15 +31,6 @@ pub fn resolve_assignments<'a>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct AssignmentResolver<'a: 'b, 'b> {
|
||||
assignments: &'b Map<&'a str, Expression<'a>>,
|
||||
assignment_tokens: &'b Map<&'a str, Token<'a>>,
|
||||
stack: Vec<&'a str>,
|
||||
seen: Set<&'a str>,
|
||||
evaluated: Set<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
|
||||
fn resolve_assignment(&mut self, name: &'a str) -> CompilationResult<'a, ()> {
|
||||
if self.evaluated.contains(name) {
|
||||
return Ok(());
|
||||
|
@ -1,8 +1,6 @@
|
||||
use common::*;
|
||||
|
||||
use edit_distance::edit_distance;
|
||||
use assignment_evaluator::evaluate_assignments;
|
||||
use range_ext::RangeExt;
|
||||
|
||||
pub struct Justfile<'a> {
|
||||
pub recipes: Map<&'a str, Recipe<'a>>,
|
||||
@ -55,7 +53,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
||||
return Err(RuntimeError::UnknownOverrides{overrides: unknown_overrides});
|
||||
}
|
||||
|
||||
let scope = evaluate_assignments(
|
||||
let scope = AssignmentEvaluator::evaluate_assignments(
|
||||
&self.assignments,
|
||||
&configuration.overrides,
|
||||
configuration.quiet,
|
||||
|
@ -53,6 +53,7 @@ mod common {
|
||||
pub use tempdir::TempDir;
|
||||
|
||||
pub use assignment_evaluator::AssignmentEvaluator;
|
||||
pub use assignment_resolver::AssignmentResolver;
|
||||
pub use command_ext::CommandExt;
|
||||
pub use compilation_error::{CompilationError, CompilationErrorKind, CompilationResult};
|
||||
pub use configuration::Configuration;
|
||||
@ -63,7 +64,9 @@ mod common {
|
||||
pub use misc::{default, empty};
|
||||
pub use parameter::Parameter;
|
||||
pub use parser::Parser;
|
||||
pub use range_ext::RangeExt;
|
||||
pub use recipe::Recipe;
|
||||
pub use recipe_resolver::RecipeResolver;
|
||||
pub use runtime_error::{RuntimeError, RunResult};
|
||||
pub use shebang::Shebang;
|
||||
pub use token::{Token, TokenKind};
|
||||
|
@ -3,8 +3,6 @@ use common::*;
|
||||
use itertools;
|
||||
use TokenKind::*;
|
||||
use CompilationErrorKind::*;
|
||||
use recipe_resolver::resolve_recipes;
|
||||
use assignment_resolver::resolve_assignments;
|
||||
|
||||
pub struct Parser<'a> {
|
||||
text: &'a str,
|
||||
@ -350,7 +348,7 @@ impl<'a> Parser<'a> {
|
||||
}))
|
||||
}
|
||||
|
||||
resolve_recipes(&self.recipes, &self.assignments, self.text)?;
|
||||
RecipeResolver::resolve_recipes(&self.recipes, &self.assignments, self.text)?;
|
||||
|
||||
for recipe in self.recipes.values() {
|
||||
for parameter in &recipe.parameters {
|
||||
@ -371,7 +369,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
resolve_assignments(&self.assignments, &self.assignment_tokens)?;
|
||||
AssignmentResolver::resolve_assignments(&self.assignments, &self.assignment_tokens)?;
|
||||
|
||||
Ok(Justfile {
|
||||
recipes: self.recipes,
|
||||
|
@ -2,7 +2,15 @@ use common::*;
|
||||
|
||||
use CompilationErrorKind::*;
|
||||
|
||||
pub fn resolve_recipes<'a>(
|
||||
pub struct RecipeResolver<'a: 'b, 'b> {
|
||||
stack: Vec<&'a str>,
|
||||
seen: Set<&'a str>,
|
||||
resolved: Set<&'a str>,
|
||||
recipes: &'b Map<&'a str, Recipe<'a>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> RecipeResolver<'a, 'b> {
|
||||
pub fn resolve_recipes(
|
||||
recipes: &Map<&'a str, Recipe<'a>>,
|
||||
assignments: &Map<&'a str, Expression<'a>>,
|
||||
text: &'a str,
|
||||
@ -15,7 +23,7 @@ pub fn resolve_recipes<'a>(
|
||||
};
|
||||
|
||||
for recipe in recipes.values() {
|
||||
resolver.resolve(recipe)?;
|
||||
resolver.resolve_recipe(recipe)?;
|
||||
resolver.seen = empty();
|
||||
}
|
||||
|
||||
@ -58,15 +66,7 @@ pub fn resolve_recipes<'a>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct RecipeResolver<'a: 'b, 'b> {
|
||||
stack: Vec<&'a str>,
|
||||
seen: Set<&'a str>,
|
||||
resolved: Set<&'a str>,
|
||||
recipes: &'b Map<&'a str, Recipe<'a>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> RecipeResolver<'a, 'b> {
|
||||
fn resolve(&mut self, recipe: &Recipe<'a>) -> CompilationResult<'a, ()> {
|
||||
fn resolve_recipe(&mut self, recipe: &Recipe<'a>) -> CompilationResult<'a, ()> {
|
||||
if self.resolved.contains(recipe.name) {
|
||||
return Ok(())
|
||||
}
|
||||
@ -85,7 +85,7 @@ impl<'a, 'b> RecipeResolver<'a, 'b> {
|
||||
.cloned().collect()
|
||||
}));
|
||||
}
|
||||
self.resolve(dependency)?;
|
||||
self.resolve_recipe(dependency)?;
|
||||
},
|
||||
None => return Err(dependency_token.error(UnknownDependency {
|
||||
recipe: recipe.name,
|
||||
|
Loading…
Reference in New Issue
Block a user