fixed function calls, added array example
This commit is contained in:
parent
fe99fddc29
commit
cefff00db3
5 changed files with 81 additions and 11 deletions
|
@ -187,7 +187,7 @@ impl Parser {
|
|||
parameter_names,
|
||||
} = function_definition;
|
||||
|
||||
let parser_scope = parser_scope.make_child_common();
|
||||
let parser_scope = parser_scope.make_child_function();
|
||||
let parameter_ids = parameter_names
|
||||
.into_iter()
|
||||
.map(|name| parser_scope.add_name(name))
|
||||
|
@ -209,7 +209,7 @@ impl Parser {
|
|||
|
||||
let variable_id = parser_scope
|
||||
.get_variable_id(&name)
|
||||
.expect("call of undeclared function");
|
||||
.expect(&format!("call of undeclared function '{name}'"));
|
||||
let parameters = arguments
|
||||
.into_iter()
|
||||
.map(|argument| self.parse_expression(argument, parser_scope))
|
||||
|
|
|
@ -132,7 +132,11 @@ fn set(args: Vec<Value>) -> Value {
|
|||
let mut object = args.get(0).unwrap().as_object().unwrap().clone();
|
||||
let name = args.get(1).unwrap().as_string().unwrap().to_string();
|
||||
let value = args.get(2).unwrap().clone();
|
||||
object.insert(name, value);
|
||||
if let Value::Bool(false) = value {
|
||||
object.remove(&name);
|
||||
} else {
|
||||
object.insert(name, value);
|
||||
}
|
||||
object.into()
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,12 @@ fn test_function_definition_parser() {
|
|||
pub fn function_call_parser(expression: impl AbstractParser<Expr>) -> impl AbstractParser<FnCall> {
|
||||
let parameters = expression.separated_by(just(',').padded());
|
||||
name()
|
||||
.then(parameters.padded().delimited_by(just('('), just(')')))
|
||||
.then(
|
||||
parameters
|
||||
.padded()
|
||||
.delimited_by(just('('), just(')'))
|
||||
.padded(),
|
||||
)
|
||||
.map(|(name, arguments)| FnCall { arguments, name })
|
||||
}
|
||||
|
||||
|
|
|
@ -100,13 +100,6 @@ impl Value {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_object_mut(&mut self) -> Option<&mut HashMap<String, Value>> {
|
||||
match self {
|
||||
Self::Object(h) => Some(h),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_function(&self) -> Option<&Function> {
|
||||
match self {
|
||||
Self::Function(function) => Some(function),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue