Fix tests
This commit is contained in:
parent
a4660cbafb
commit
a42b43ed78
@ -5,7 +5,7 @@
|
|||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tree_sitter::{Node, Parser, Tree as TSTree, TreeCursor};
|
use tree_sitter::{Parser, Tree as TSTree, TreeCursor};
|
||||||
|
|
||||||
use crate::{language, Error, Primitive, Result, Value, VariableMap};
|
use crate::{language, Error, Primitive, Result, Value, VariableMap};
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ impl<'context, 'code> Evaluator<'context, 'code> {
|
|||||||
|
|
||||||
cursor_1.goto_first_child();
|
cursor_1.goto_first_child();
|
||||||
|
|
||||||
for item_node in node.named_children(&mut cursor_0) {
|
for _ in node.children(&mut cursor_0) {
|
||||||
let item_result = Item::new(self.source, &mut cursor_1);
|
let item_result = Item::new(self.source, &mut cursor_1);
|
||||||
|
|
||||||
match item_result {
|
match item_result {
|
||||||
@ -183,12 +183,9 @@ pub enum Statement {
|
|||||||
|
|
||||||
impl EvaluatorTree for Statement {
|
impl EvaluatorTree for Statement {
|
||||||
fn new(source: &str, cursor: &mut TreeCursor) -> Result<Self> {
|
fn new(source: &str, cursor: &mut TreeCursor) -> Result<Self> {
|
||||||
let node = cursor.node();
|
|
||||||
cursor.goto_first_child();
|
cursor.goto_first_child();
|
||||||
let child = cursor.node();
|
let child = cursor.node();
|
||||||
|
|
||||||
assert_eq!(node.kind(), "statement");
|
|
||||||
|
|
||||||
match child.kind() {
|
match child.kind() {
|
||||||
"expression" => Ok(Self::Expression(Expression::new(source, cursor)?)),
|
"expression" => Ok(Self::Expression(Expression::new(source, cursor)?)),
|
||||||
_ => Err(Error::UnexpectedSyntax {
|
_ => Err(Error::UnexpectedSyntax {
|
||||||
@ -295,30 +292,33 @@ pub struct ControlFlow {
|
|||||||
impl EvaluatorTree for ControlFlow {
|
impl EvaluatorTree for ControlFlow {
|
||||||
fn new(source: &str, cursor: &mut TreeCursor) -> Result<Self> {
|
fn new(source: &str, cursor: &mut TreeCursor) -> Result<Self> {
|
||||||
let node = cursor.node();
|
let node = cursor.node();
|
||||||
cursor.goto_first_child();
|
|
||||||
let child = cursor.node();
|
|
||||||
|
|
||||||
assert_eq!(node.kind(), "control_flow");
|
assert_eq!(node.kind(), "control_flow");
|
||||||
|
|
||||||
|
println!("{node:?}");
|
||||||
|
|
||||||
// Skip the child nodes for the keywords "if", "then" and "else".
|
// Skip the child nodes for the keywords "if", "then" and "else".
|
||||||
let if_expression_node = child.next_named_sibling().unwrap();
|
|
||||||
|
let if_node = node.child_by_field_name("if_expression").unwrap();
|
||||||
|
|
||||||
|
cursor.reset(if_node);
|
||||||
|
|
||||||
let if_expression = Expression::new(source, cursor)?;
|
let if_expression = Expression::new(source, cursor)?;
|
||||||
|
|
||||||
let then_statement_node = node.next_named_sibling().unwrap();
|
println!("{:?}", cursor.node());
|
||||||
|
|
||||||
|
let then_node = node.child_by_field_name("then_statement").unwrap();
|
||||||
|
|
||||||
|
cursor.reset(then_node);
|
||||||
|
|
||||||
|
let position = cursor.node();
|
||||||
let then_statement = Statement::new(source, cursor)?;
|
let then_statement = Statement::new(source, cursor)?;
|
||||||
|
|
||||||
let else_statement_node = node.next_named_sibling();
|
cursor.reset(position);
|
||||||
|
|
||||||
let else_statement = if let Some(child) = else_statement_node {
|
|
||||||
Some(Statement::new(source, cursor)?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(ControlFlow {
|
Ok(ControlFlow {
|
||||||
if_expression,
|
if_expression,
|
||||||
then_statement,
|
then_statement,
|
||||||
else_statement,
|
else_statement: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user