Fix infintite loop
This commit is contained in:
parent
5e105177cf
commit
edded5043d
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::{RuntimeError, SyntaxError, ValidationError},
|
error::{RuntimeError, SyntaxError, ValidationError},
|
||||||
value_node::ValueNode,
|
value_node::ValueNode,
|
||||||
AbstractTree, As, Command, Context, Format, FunctionCall, Identifier, Index, Logic, Math, New,
|
AbstractTree, As, Command, Context, Format, FunctionCall, Identifier, Index, Logic, Math,
|
||||||
SyntaxNode, Type, Value,
|
SyntaxNode, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,7 +20,6 @@ pub enum Expression {
|
|||||||
Math(Box<Math>),
|
Math(Box<Math>),
|
||||||
Logic(Box<Logic>),
|
Logic(Box<Logic>),
|
||||||
FunctionCall(Box<FunctionCall>),
|
FunctionCall(Box<FunctionCall>),
|
||||||
New(New),
|
|
||||||
Command(Command),
|
Command(Command),
|
||||||
As(Box<As>),
|
As(Box<As>),
|
||||||
}
|
}
|
||||||
@ -51,13 +50,11 @@ impl AbstractTree for Expression {
|
|||||||
"function_call" => Expression::FunctionCall(Box::new(FunctionCall::from_syntax(
|
"function_call" => Expression::FunctionCall(Box::new(FunctionCall::from_syntax(
|
||||||
child, source, _context,
|
child, source, _context,
|
||||||
)?)),
|
)?)),
|
||||||
"new" => Expression::New(New::from_syntax(child, source, _context)?),
|
|
||||||
"command" => Expression::Command(Command::from_syntax(child, source, _context)?),
|
"command" => Expression::Command(Command::from_syntax(child, source, _context)?),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(SyntaxError::UnexpectedSyntaxNode {
|
return Err(SyntaxError::UnexpectedSyntaxNode {
|
||||||
expected:
|
expected: "value, identifier, index, math, logic, function call, as or command"
|
||||||
"value, identifier, index, math, logic, function call, new, as or command"
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
actual: child.kind().to_string(),
|
actual: child.kind().to_string(),
|
||||||
location: child.start_position(),
|
location: child.start_position(),
|
||||||
relevant_source: source[child.byte_range()].to_string(),
|
relevant_source: source[child.byte_range()].to_string(),
|
||||||
@ -76,7 +73,6 @@ impl AbstractTree for Expression {
|
|||||||
Expression::Logic(logic) => logic.expected_type(_context),
|
Expression::Logic(logic) => logic.expected_type(_context),
|
||||||
Expression::FunctionCall(function_call) => function_call.expected_type(_context),
|
Expression::FunctionCall(function_call) => function_call.expected_type(_context),
|
||||||
Expression::Index(index) => index.expected_type(_context),
|
Expression::Index(index) => index.expected_type(_context),
|
||||||
Expression::New(new) => new.expected_type(_context),
|
|
||||||
Expression::Command(command) => command.expected_type(_context),
|
Expression::Command(command) => command.expected_type(_context),
|
||||||
Expression::As(r#as) => r#as.expected_type(_context),
|
Expression::As(r#as) => r#as.expected_type(_context),
|
||||||
}
|
}
|
||||||
@ -90,7 +86,6 @@ impl AbstractTree for Expression {
|
|||||||
Expression::Logic(logic) => logic.validate(_source, _context),
|
Expression::Logic(logic) => logic.validate(_source, _context),
|
||||||
Expression::FunctionCall(function_call) => function_call.validate(_source, _context),
|
Expression::FunctionCall(function_call) => function_call.validate(_source, _context),
|
||||||
Expression::Index(index) => index.validate(_source, _context),
|
Expression::Index(index) => index.validate(_source, _context),
|
||||||
Expression::New(new) => new.validate(_source, _context),
|
|
||||||
Expression::Command(command) => command.validate(_source, _context),
|
Expression::Command(command) => command.validate(_source, _context),
|
||||||
Expression::As(r#as) => r#as.validate(_source, _context),
|
Expression::As(r#as) => r#as.validate(_source, _context),
|
||||||
}
|
}
|
||||||
@ -104,7 +99,6 @@ impl AbstractTree for Expression {
|
|||||||
Expression::Logic(logic) => logic.run(_source, _context),
|
Expression::Logic(logic) => logic.run(_source, _context),
|
||||||
Expression::FunctionCall(function_call) => function_call.run(_source, _context),
|
Expression::FunctionCall(function_call) => function_call.run(_source, _context),
|
||||||
Expression::Index(index) => index.run(_source, _context),
|
Expression::Index(index) => index.run(_source, _context),
|
||||||
Expression::New(new) => new.run(_source, _context),
|
|
||||||
Expression::Command(command) => command.run(_source, _context),
|
Expression::Command(command) => command.run(_source, _context),
|
||||||
Expression::As(r#as) => r#as.run(_source, _context),
|
Expression::As(r#as) => r#as.run(_source, _context),
|
||||||
}
|
}
|
||||||
@ -120,7 +114,6 @@ impl Format for Expression {
|
|||||||
Expression::Logic(logic) => logic.format(_output, _indent_level),
|
Expression::Logic(logic) => logic.format(_output, _indent_level),
|
||||||
Expression::FunctionCall(function_call) => function_call.format(_output, _indent_level),
|
Expression::FunctionCall(function_call) => function_call.format(_output, _indent_level),
|
||||||
Expression::Index(index) => index.format(_output, _indent_level),
|
Expression::Index(index) => index.format(_output, _indent_level),
|
||||||
Expression::New(new) => new.format(_output, _indent_level),
|
|
||||||
Expression::Command(command) => command.format(_output, _indent_level),
|
Expression::Command(command) => command.format(_output, _indent_level),
|
||||||
Expression::As(r#as) => r#as.format(_output, _indent_level),
|
Expression::As(r#as) => r#as.format(_output, _indent_level),
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ impl Identifier {
|
|||||||
Identifier(Arc::new(key.to_string()))
|
Identifier(Arc::new(key.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_raw_parts(arc: Arc<String>) -> Self {
|
||||||
|
Identifier(arc)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn inner(&self) -> &Arc<String> {
|
pub fn inner(&self) -> &Arc<String> {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ pub mod r#match;
|
|||||||
pub mod match_pattern;
|
pub mod match_pattern;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod math_operator;
|
pub mod math_operator;
|
||||||
pub mod new;
|
|
||||||
pub mod statement;
|
pub mod statement;
|
||||||
pub mod struct_definition;
|
pub mod struct_definition;
|
||||||
pub mod r#type;
|
pub mod r#type;
|
||||||
@ -43,8 +42,8 @@ pub use {
|
|||||||
assignment::*, assignment_operator::*, block::*, command::*, enum_defintion::*,
|
assignment::*, assignment_operator::*, block::*, command::*, enum_defintion::*,
|
||||||
enum_pattern::*, expression::*, function_call::*, function_expression::*, function_node::*,
|
enum_pattern::*, expression::*, function_call::*, function_expression::*, function_node::*,
|
||||||
identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*,
|
identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*,
|
||||||
logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, new::*,
|
logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, r#as::*,
|
||||||
r#as::*, r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*,
|
r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*,
|
||||||
type_definition::*, type_specification::*, value_node::*,
|
type_definition::*, type_specification::*, value_node::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,11 +119,7 @@ impl AbstractTree for Root {
|
|||||||
let mut value = Value::none();
|
let mut value = Value::none();
|
||||||
|
|
||||||
for statement in &self.statements {
|
for statement in &self.statements {
|
||||||
if let Statement::Return(inner_statement) = statement {
|
value = statement.run(source, context)?;
|
||||||
return inner_statement.run(source, context);
|
|
||||||
} else {
|
|
||||||
value = statement.run(source, context)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(value)
|
Ok(value)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::sync::OnceLock;
|
use std::sync::{Arc, OnceLock};
|
||||||
|
|
||||||
use enum_iterator::{all, Sequence};
|
use enum_iterator::{all, Sequence};
|
||||||
|
|
||||||
@ -8,10 +8,10 @@ pub fn all_built_in_identifiers() -> impl Iterator<Item = BuiltInIdentifier> {
|
|||||||
all()
|
all()
|
||||||
}
|
}
|
||||||
|
|
||||||
const OPTION: OnceLock<Identifier> = OnceLock::new();
|
static OPTION: OnceLock<Identifier> = OnceLock::new();
|
||||||
const NONE: OnceLock<Identifier> = OnceLock::new();
|
static NONE: OnceLock<Identifier> = OnceLock::new();
|
||||||
|
|
||||||
#[derive(Sequence)]
|
#[derive(Sequence, Debug)]
|
||||||
pub enum BuiltInIdentifier {
|
pub enum BuiltInIdentifier {
|
||||||
Option,
|
Option,
|
||||||
None,
|
None,
|
||||||
@ -20,8 +20,12 @@ pub enum BuiltInIdentifier {
|
|||||||
impl BuiltInIdentifier {
|
impl BuiltInIdentifier {
|
||||||
pub fn get(&self) -> Identifier {
|
pub fn get(&self) -> Identifier {
|
||||||
match self {
|
match self {
|
||||||
BuiltInIdentifier::Option => OPTION.get_or_init(|| Identifier::new("Option")).clone(),
|
BuiltInIdentifier::Option => OPTION
|
||||||
BuiltInIdentifier::None => NONE.get_or_init(|| Identifier::new("None")).clone(),
|
.get_or_init(|| Identifier::from_raw_parts(Arc::new("Option".to_string())))
|
||||||
|
.clone(),
|
||||||
|
BuiltInIdentifier::None => NONE
|
||||||
|
.get_or_init(|| Identifier::from_raw_parts(Arc::new("None".to_string())))
|
||||||
|
.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,10 +149,14 @@ impl Interpreter {
|
|||||||
|
|
||||||
check_for_error(root, source, &mut cursor)?;
|
check_for_error(root, source, &mut cursor)?;
|
||||||
|
|
||||||
|
println!("abstracting...");
|
||||||
|
|
||||||
let abstract_tree = Root::from_syntax(syntax_tree.root_node(), source, &self.context)?;
|
let abstract_tree = Root::from_syntax(syntax_tree.root_node(), source, &self.context)?;
|
||||||
|
|
||||||
abstract_tree.validate(source, &self.context)?;
|
abstract_tree.validate(source, &self.context)?;
|
||||||
|
|
||||||
|
println!("{abstract_tree:?}");
|
||||||
|
|
||||||
Ok(abstract_tree)
|
Ok(abstract_tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user