mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-12 09:30:40 +01:00
Allow equation variables in function calls, closes #144
This commit is contained in:
parent
ea2d28956d
commit
7a444022a2
@ -293,11 +293,7 @@ fn analyse_binary(
|
|||||||
|
|
||||||
context.in_equation = false;
|
context.in_equation = false;
|
||||||
|
|
||||||
let var_name = if let Some(var_name) = &context.equation_variable {
|
let var_name = context.equation_variable.as_ref().unwrap();
|
||||||
var_name
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
let identifier = Identifier::from_full_name(var_name);
|
let identifier = Identifier::from_full_name(var_name);
|
||||||
context.equation_variable = None;
|
context.equation_variable = None;
|
||||||
|
|
||||||
@ -474,6 +470,18 @@ fn analyse_var(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if context.symbol_table.contains_fn(&identifier.full_name) {
|
||||||
|
if let Some(Expr::Group(arg)) = adjacent_factor {
|
||||||
|
return Ok(Expr::FnCall(identifier, vec![*arg]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(Expr::Vector(args)) = adjacent_factor {
|
||||||
|
return Ok(Expr::FnCall(identifier, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(Expr::FnCall(identifier, vec![adjacent_factor.unwrap()]));
|
||||||
|
}
|
||||||
|
|
||||||
let is_comprehension_var = if let Some(vars) = &context.comprehension_vars {
|
let is_comprehension_var = if let Some(vars) = &context.comprehension_vars {
|
||||||
vars.iter().any(|x| x.name == identifier.pure_name)
|
vars.iter().any(|x| x.name == identifier.pure_name)
|
||||||
} else {
|
} else {
|
||||||
@ -538,6 +546,7 @@ fn analyse_var(
|
|||||||
|
|
||||||
if !is_parameter {
|
if !is_parameter {
|
||||||
context.equation_variable = Some(identifier.full_name.clone());
|
context.equation_variable = Some(identifier.full_name.clone());
|
||||||
|
|
||||||
return with_adjacent(
|
return with_adjacent(
|
||||||
build_var(context, &identifier.full_name),
|
build_var(context, &identifier.full_name),
|
||||||
adjacent_factor,
|
adjacent_factor,
|
||||||
@ -711,7 +720,8 @@ fn build_var(context: &mut Context, name: &str) -> Expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let var_exists = context.symbol_table.contains_var(name);
|
let var_exists = context.symbol_table.contains_var(name);
|
||||||
if context.in_equation && !var_exists {
|
let fn_exists = context.symbol_table.contains_fn(name);
|
||||||
|
if context.in_equation && !var_exists && !fn_exists {
|
||||||
context.equation_variable = Some(name.to_string());
|
context.equation_variable = Some(name.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ pub struct BinaryFuncInfo(
|
|||||||
FuncType,
|
FuncType,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct VectorFuncInfo(fn(KalkValue) -> Result<KalkValue, KalkError>, FuncType);
|
pub struct VectorFuncInfo(fn(KalkValue) -> Result<KalkValue, KalkError>, FuncType);
|
||||||
|
|
||||||
impl UnaryFuncInfo {
|
impl UnaryFuncInfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user