Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Sep 28, 2023
1 parent 3e228d6 commit b1759f1
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/modules/expression/binop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub mod le;
pub mod eq;
pub mod neq;

pub fn expression_arms_of_type(meta: &mut ParserMetadata, left: &Type, right: &Type, predicate: impl Fn(Type) -> bool, tok_pos: Option<Token>, message: &str) -> Result<Type, Failure> {
pub fn expression_arms_of_type(meta: &ParserMetadata, left: &Type, right: &Type, predicate: impl Fn(Type) -> bool, tok_pos: Option<Token>, message: &str) -> Result<Type, Failure> {
if left == right && [left, right].iter().all(|kind| predicate((*kind).clone())) {
Ok(left.clone())
} else {
error!(meta, tok_pos, message)
}
}

pub fn expression_arms_of_same_type(meta: &mut ParserMetadata, left: &Expr, right: &Expr, tok_pos: Option<Token>, message: &str) -> SyntaxResult {
pub fn expression_arms_of_same_type(meta: &ParserMetadata, left: &Expr, right: &Expr, tok_pos: Option<Token>, message: &str) -> SyntaxResult {
if left.get_type() != right.get_type() {
error!(meta, tok_pos, message)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/function/declaration_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn skip_function_body(meta: &mut ParserMetadata) -> (usize, usize, bool) {
(index_begin, index_end, is_failable)
}

pub fn handle_existing_function(meta: &mut ParserMetadata, tok: Option<Token>) -> Result<(), Failure> {
pub fn handle_existing_function(meta: &ParserMetadata, tok: Option<Token>) -> Result<(), Failure> {
let name = tok.as_ref().unwrap().word.clone();
handle_identifier_name(meta, &name, tok.clone())?;
if meta.get_fun_declaration(&name).is_some() {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/function/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl SyntaxModule<ParserMetadata> for FunctionInvocation {
}

impl FunctionInvocation {
fn get_variable(&self, meta: &mut TranslateMetadata, name: &str, dollar_override: bool) -> String {
fn get_variable(&self, meta: &TranslateMetadata, name: &str, dollar_override: bool) -> String {
let dollar = dollar_override.then(|| "$").unwrap_or_else(|| meta.gen_dollar());
if matches!(self.kind, Type::Array(_)) {
let quote = meta.gen_quote();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/function/invocation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn run_function_with_args(meta: &mut ParserMetadata, mut fun: FunctionDecl, args
Ok((fun.returns.clone(), meta.add_fun_instance(fun.to_interface(), block)))
}

pub fn handle_function_reference(meta: &mut ParserMetadata, tok: Option<Token>, name: &str) -> Result<usize, Failure> {
pub fn handle_function_reference(meta: &ParserMetadata, tok: Option<Token>, name: &str) -> Result<usize, Failure> {
match meta.get_fun_declaration(name) {
Some(fun_decl) => Ok(fun_decl.id),
None => {
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn handle_function_parameters(meta: &mut ParserMetadata, id: usize, fun: Fun
}
}

fn handle_similar_function(meta: &mut ParserMetadata, name: &str) -> Option<String> {
fn handle_similar_function(meta: &ParserMetadata, name: &str) -> Option<String> {
let vars = Vec::from_iter(meta.get_fun_names());
find_best_similarity(name, &vars)
.map(|(match_name, score)| (score >= 0.75).then(|| format!("Did you mean '{match_name}'?")))
Expand Down
2 changes: 1 addition & 1 deletion src/modules/imports/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Import {
Ok(())
}

fn resolve_import(&mut self, meta: &mut ParserMetadata) -> Result<String, Failure> {
fn resolve_import(&mut self, meta: &ParserMetadata) -> Result<String, Failure> {
match fs::read_to_string(self.path.value.clone()) {
Ok(content) => Ok(content),
Err(err) => error!(meta, self.token_path.clone() => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/imports/import_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct ImportString {
}

impl ImportString {
fn resolve_path(&mut self, meta: &mut ParserMetadata, tok: Option<Token>) -> SyntaxResult {
fn resolve_path(&mut self, meta: &ParserMetadata, tok: Option<Token>) -> SyntaxResult {
if self.value == "std" {
self.value = "[standard library]".to_string();
return Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/modules/variable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn variable_name_keywords() -> Vec<&'static str> {
}


pub fn handle_variable_reference(meta: &mut ParserMetadata, tok: Option<Token>, name: &str) -> Result<VariableDecl, Failure> {
pub fn handle_variable_reference(meta: &ParserMetadata, tok: Option<Token>, name: &str) -> Result<VariableDecl, Failure> {
handle_identifier_name(meta, name, tok.clone())?;
match meta.get_var(name) {
Some(variable_unit) => Ok(variable_unit.clone()),
Expand All @@ -53,14 +53,14 @@ pub fn handle_variable_reference(meta: &mut ParserMetadata, tok: Option<Token>,
}
}

fn handle_similar_variable(meta: &mut ParserMetadata, name: &str) -> Option<String> {
fn handle_similar_variable(meta: &ParserMetadata, name: &str) -> Option<String> {
let vars = Vec::from_iter(meta.get_var_names());
find_best_similarity(name, &vars)
.map(|(match_name, score)| (score >= 0.75).then(|| format!("Did you mean '{match_name}'?")))
.flatten()
}

pub fn handle_identifier_name(meta: &mut ParserMetadata, name: &str, tok: Option<Token>) -> Result<(), Failure> {
pub fn handle_identifier_name(meta: &ParserMetadata, name: &str, tok: Option<Token>) -> Result<(), Failure> {
// Validate if the variable name uses the reserved prefix
if name.chars().take(2).all(|chr| chr == '_') && name.len() > 2 {
let new_name = name.get(1..).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/translate/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum ArithOp {
Or
}

pub fn translate_computation(meta: &mut TranslateMetadata, operation: ArithOp, left: Option<String>, right: Option<String>) -> String {
pub fn translate_computation(meta: &TranslateMetadata, operation: ArithOp, left: Option<String>, right: Option<String>) -> String {
match meta.arith_module {
ArithType::BcSed => {
let (left, right) = (left.unwrap_or_default(), right.unwrap_or_default());
Expand Down Expand Up @@ -58,5 +58,5 @@ pub fn translate_computation_eval(meta: &mut TranslateMetadata, operation: Arith
meta.eval_ctx = true;
let result = translate_computation(meta, operation, left, right);
meta.eval_ctx = old_eval;
return result;
result
}
2 changes: 1 addition & 1 deletion src/translate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::ParserMetadata;
pub mod module;
pub mod compute;

pub fn check_all_blocks(meta: &mut ParserMetadata) -> SyntaxResult {
pub fn check_all_blocks(meta: &ParserMetadata) -> SyntaxResult {
let mut stack = 0;
for token in meta.context.expr.iter() {
match token.word.as_str() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/function_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct FunctionInterface {
}

impl FunctionInterface {
pub fn to_fun_declaration(self, id: usize) -> FunctionDecl {
pub fn as_fun_declaration(self, id: usize) -> FunctionDecl {
let is_args_typed = self.arg_types.iter().all(|t| t != &Type::Generic);
FunctionDecl {
name: self.name,
Expand All @@ -31,7 +31,7 @@ impl FunctionInterface {
}
}

pub fn to_fun_instance(self, block: Block) -> FunctionInstance {
pub fn as_fun_instance(self, block: Block) -> FunctionInstance {
FunctionInstance {
variant_id: 0,
args: self.arg_types,
Expand Down
6 changes: 3 additions & 3 deletions src/utils/metadata/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ impl ParserMetadata {
let global_id = self.gen_fun_id();
// Add the function to the public function list
if fun.is_public {
let decl = fun.clone().to_fun_declaration(global_id);
let decl = fun.clone().as_fun_declaration(global_id);
self.context.pub_funs.push(decl);
}
// Add the function to the current scope
let scope = self.context.scopes.last_mut().unwrap();
scope.add_fun(fun.to_fun_declaration(global_id)).then(|| {
scope.add_fun(fun.as_fun_declaration(global_id)).then(|| {
// Add the function to the function cache
self.fun_cache.add_declaration(global_id, ctx);
global_id
Expand All @@ -142,7 +142,7 @@ impl ParserMetadata {
/// This function returns the id of the function instance variant
pub fn add_fun_instance(&mut self, fun: FunctionInterface, block: Block) -> usize {
let id = fun.id.expect("Function id is not set");
self.fun_cache.add_instance(id, fun.to_fun_instance(block))
self.fun_cache.add_instance(id, fun.as_fun_instance(block))
}

/// Gets a function declaration from the current scope or any parent scope
Expand Down

0 comments on commit b1759f1

Please sign in to comment.