1
0

Fix find loops and index syntax

This commit is contained in:
Jeff 2023-11-15 21:35:40 -05:00
parent 2876f50822
commit a21aa5e37b
6 changed files with 10125 additions and 10115 deletions

View File

@ -52,11 +52,10 @@ impl AbstractTree for Assignment {
fn run(&self, source: &str, context: &mut Map) -> Result<Value> { fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
let key = self.identifier.inner().clone(); let key = self.identifier.inner().clone();
let value = self.statement.run(source, context)?; let value = self.statement.run(source, context)?;
let mut variables = context.variables_mut()?;
let new_value = match self.operator { let new_value = match self.operator {
AssignmentOperator::PlusEqual => { AssignmentOperator::PlusEqual => {
if let Some(mut previous_value) = variables.get(&key).cloned() { if let Some(mut previous_value) = context.variables()?.get(&key).cloned() {
previous_value += value; previous_value += value;
previous_value previous_value
} else { } else {
@ -64,7 +63,7 @@ impl AbstractTree for Assignment {
} }
} }
AssignmentOperator::MinusEqual => { AssignmentOperator::MinusEqual => {
if let Some(mut previous_value) = variables.get(&key).cloned() { if let Some(mut previous_value) = context.variables()?.get(&key).cloned() {
previous_value -= value; previous_value -= value;
previous_value previous_value
} else { } else {
@ -74,7 +73,7 @@ impl AbstractTree for Assignment {
AssignmentOperator::Equal => value, AssignmentOperator::Equal => value,
}; };
variables.insert(key, new_value); context.variables_mut()?.insert(key, new_value);
Ok(Value::Empty) Ok(Value::Empty)
} }

View File

@ -30,12 +30,13 @@ impl AbstractTree for Find {
} }
fn run(&self, source: &str, context: &mut Map) -> Result<Value> { fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
let value = self.expression.run(source, context)?; let expression_run = self.expression.run(source, context)?;
let values = value.as_list()?.items(); let list = expression_run.as_list()?.items();
let key = self.identifier.inner(); let key = self.identifier.inner();
let loop_context = Map::clone_from(context)?;
let find_result = values.par_iter().find_map_first(|value| { let find_result = list.par_iter().find_map_first(|value| {
let loop_context = Map::clone_from(context).unwrap();
loop_context loop_context
.variables_mut() .variables_mut()
.unwrap() .unwrap()

View File

@ -34,7 +34,7 @@ pub fn evaluate(source: &str) -> Result<Value> {
/// let mut context = Map::new(); /// let mut context = Map::new();
/// ///
/// { /// {
/// let mut variables = context.variables_mut(); /// let mut variables = context.variables_mut().unwrap();
/// ///
/// variables.insert("one".into(), 1.into()); /// variables.insert("one".into(), 1.into());
/// variables.insert("two".into(), 2.into()); /// variables.insert("two".into(), 2.into());

View File

@ -124,7 +124,7 @@ module.exports = grammar({
'}', '}',
), ),
index: $ => prec.left(seq( index: $ => prec.left(1, seq(
$.expression, $.expression,
':', ':',
$.expression, $.expression,

View File

@ -606,7 +606,7 @@
}, },
"index": { "index": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 1,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

File diff suppressed because it is too large Load Diff