Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze and Compiler tweaks #1534

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Settings::from_setting_iter
Makes the Settings type responsible for constructing itself from an
iterator of Setting values, which allows the analyzer code to be more
concise.
  • Loading branch information
neunenak committed Jan 25, 2023
commit 0ee5ccec80c667a80376105e26e6daf9933d8eb7
45 changes: 4 additions & 41 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,11 @@ impl<'src> Analyzer<'src> {
}
}

let mut settings = Settings::default();

for (_, set) in self.sets {
match set.value {
Setting::AllowDuplicateRecipes(allow_duplicate_recipes) => {
settings.allow_duplicate_recipes = allow_duplicate_recipes;
}
Setting::DotenvLoad(dotenv_load) => {
settings.dotenv_load = Some(dotenv_load);
}
Setting::Export(export) => {
settings.export = export;
}
Setting::Fallback(fallback) => {
settings.fallback = fallback;
}
Setting::IgnoreComments(ignore_comments) => {
settings.ignore_comments = ignore_comments;
}
Setting::PositionalArguments(positional_arguments) => {
settings.positional_arguments = positional_arguments;
}
Setting::Shell(shell) => {
settings.shell = Some(shell);
}
Setting::WindowsPowerShell(windows_powershell) => {
settings.windows_powershell = windows_powershell;
}
Setting::WindowsShell(windows_shell) => {
settings.windows_shell = Some(windows_shell);
}
Setting::Tempdir(tempdir) => {
settings.tempdir = Some(tempdir);
}
}
}

let assignments = self.assignments;
let settings = Settings::from_setting_iter(self.sets.into_iter().map(|(_, set)| set.value));

let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Default::default();

AssignmentResolver::resolve_assignments(&assignments)?;
AssignmentResolver::resolve_assignments(&self.assignments)?;

for recipe in recipes {
if let Some(original) = recipe_table.get(recipe.name.lexeme()) {
Expand All @@ -96,7 +59,7 @@ impl<'src> Analyzer<'src> {
recipe_table.insert(recipe.clone());
}

let recipes = RecipeResolver::resolve_recipes(recipe_table, &assignments)?;
let recipes = RecipeResolver::resolve_recipes(recipe_table, &self.assignments)?;

let mut aliases = Table::new();
while let Some(alias) = self.aliases.pop() {
Expand All @@ -116,7 +79,7 @@ impl<'src> Analyzer<'src> {
}),
}),
aliases,
assignments,
assignments: self.assignments,
recipes,
settings,
})
Expand Down
41 changes: 41 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@ pub(crate) struct Settings<'src> {
}

impl<'src> Settings<'src> {
pub(crate) fn from_setting_iter(iter: impl Iterator<Item = Setting<'src>>) -> Self {
let mut settings = Self::default();

for set in iter {
match set {
Setting::AllowDuplicateRecipes(allow_duplicate_recipes) => {
settings.allow_duplicate_recipes = allow_duplicate_recipes;
}
Setting::DotenvLoad(dotenv_load) => {
settings.dotenv_load = Some(dotenv_load);
}
Setting::Export(export) => {
settings.export = export;
}
Setting::Fallback(fallback) => {
settings.fallback = fallback;
}
Setting::IgnoreComments(ignore_comments) => {
settings.ignore_comments = ignore_comments;
}
Setting::PositionalArguments(positional_arguments) => {
settings.positional_arguments = positional_arguments;
}
Setting::Shell(shell) => {
settings.shell = Some(shell);
}
Setting::WindowsPowerShell(windows_powershell) => {
settings.windows_powershell = windows_powershell;
}
Setting::WindowsShell(windows_shell) => {
settings.windows_shell = Some(windows_shell);
}
Setting::Tempdir(tempdir) => {
settings.tempdir = Some(tempdir);
}
}
}

settings
}

pub(crate) fn shell_command(&self, config: &Config) -> Command {
let (command, args) = self.shell(config);

Expand Down