From cdf79f87638100c641ff76fdb21294eadf3a32b0 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 29 Sep 2023 00:16:51 -0400 Subject: [PATCH] Implement closed and open statement --- src/interface.rs | 28 +++++++++++++++++----------- src/value/mod.rs | 3 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index 8e48450..2823519 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -109,7 +109,8 @@ impl Item { Ok(Item::Comment(value_string.to_string())) } else if node.kind() == "statement" { - Ok(Item::Statement(Statement::new(node, source)?)) + let child = node.child(0).unwrap(); + Ok(Item::Statement(Statement::new(child, source)?)) } else { Err(Error::UnexpectedSourceNode { expected: "comment or statement", @@ -122,20 +123,20 @@ impl Item { #[derive(Debug)] enum Statement { Closed(Expression), + Open(Expression), } impl Statement { fn new(node: Node, source: &str) -> Result { - if node.kind() == "statement" { - Ok(Statement::Closed(Expression::new( - node.child(0).unwrap(), - source, - )?)) - } else { - Err(Error::UnexpectedSourceNode { - expected: "statement", + let child = node.child(0).unwrap(); + + match node.kind() { + "closed_statement" => Ok(Statement::Closed(Expression::new(child, source)?)), + "open_statement" => Ok(Self::Open(Expression::new(child, source)?)), + _ => Err(Error::UnexpectedSourceNode { + expected: "closed_statement or open_statement", actual: node.kind(), - }) + }), } } @@ -146,7 +147,12 @@ impl Statement { source: &str, ) -> Result { match self { - Statement::Closed(expression) => expression.run(context, &mut cursor, source), + Statement::Closed(expression) => { + expression.run(context, &mut cursor, source)?; + + Ok(Value::Empty) + } + Statement::Open(expression) => expression.run(context, &mut cursor, source), } } } diff --git a/src/value/mod.rs b/src/value/mod.rs index 461eebe..186fc5e 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -66,6 +66,7 @@ impl Value { Ok(Value::Integer(raw)) } + "string" => Ok(Value::String(value_snippet.to_string())), _ => Err(Error::UnexpectedSourceNode { expected: "raw value", actual: child.kind(), @@ -252,7 +253,7 @@ impl Add for Value { Ok(Value::String(concatenated)) } - (Value::String(string), other) | (other, Value::String(string)) => { + (Value::String(_), other) | (other, Value::String(_)) => { Err(Error::ExpectedString { actual: other }) } (Value::Float(left), Value::Float(right)) => {