Skip to content

Commit

Permalink
move fn define
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Sep 21, 2024
1 parent 67fe7c2 commit 91117d6
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,6 @@ pub(crate) struct Analyzer<'run, 'src> {
}

impl<'run, 'src> Analyzer<'run, 'src> {
fn define(
&mut self,
name: Name<'src>,
second_type: &'static str,
duplicates_allowed: bool,
) -> CompileResult<'src> {
if let Some((first_type, original)) = self.definitions.get(name.lexeme()) {
if !(*first_type == second_type && duplicates_allowed) {
let ((first_type, second_type), (original, redefinition)) = if name.line < original.line {
((second_type, *first_type), (name, *original))
} else {
((*first_type, second_type), (*original, name))
};

return Err(redefinition.token.error(Redefinition {
first_type,
second_type,
name: name.lexeme(),
first: original.line,
}));
}
}

self.definitions.insert(name.lexeme(), (second_type, name));

Ok(())
}

pub(crate) fn analyze(
asts: &HashMap<PathBuf, Ast<'src>>,
doc: Option<String>,
Expand Down Expand Up @@ -227,6 +199,34 @@ impl<'run, 'src> Analyzer<'run, 'src> {
})
}

fn define(
&mut self,
name: Name<'src>,
second_type: &'static str,
duplicates_allowed: bool,
) -> CompileResult<'src> {
if let Some((first_type, original)) = self.definitions.get(name.lexeme()) {
if !(*first_type == second_type && duplicates_allowed) {
let ((first_type, second_type), (original, redefinition)) = if name.line < original.line {
((second_type, *first_type), (name, *original))
} else {
((*first_type, second_type), (*original, name))
};

return Err(redefinition.token.error(Redefinition {
first_type,
second_type,
name: name.lexeme(),
first: original.line,
}));
}
}

self.definitions.insert(name.lexeme(), (second_type, name));

Ok(())
}

fn analyze_recipe(recipe: &UnresolvedRecipe<'src>) -> CompileResult<'src> {
let mut parameters = BTreeSet::new();
let mut passed_default = false;
Expand Down

0 comments on commit 91117d6

Please sign in to comment.