1
0

Add statment_kind syntax node

This commit is contained in:
Jeff 2024-02-16 10:55:15 -05:00
parent 1ce2178af5
commit 9f2b0461df
29 changed files with 23196 additions and 23572 deletions

View File

@ -6,39 +6,56 @@ use crate::{
Match, SyntaxNode, Type, TypeDefinition, Value, While,
};
/// Abstract representation of a statement.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Statement {
is_return: bool,
statement_inner: StatementInner,
statement_inner: StatementKind,
}
impl AbstractTree for Statement {
fn from_syntax(node: SyntaxNode, source: &str, context: &Context) -> Result<Self, SyntaxError> {
todo!()
fn from_syntax(
node: SyntaxNode,
source: &str,
_context: &Context,
) -> Result<Self, SyntaxError> {
SyntaxError::expect_syntax_node(source, "statement", node)?;
let first_child = node.child(0).unwrap();
let is_return = first_child.kind() == "return";
let child = if is_return {
node.child(1).unwrap()
} else {
first_child
};
Ok(Statement {
is_return,
statement_inner: StatementKind::from_syntax(child, source, _context)?,
})
}
fn expected_type(&self, context: &Context) -> Result<Type, ValidationError> {
todo!()
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
self.statement_inner.expected_type(_context)
}
fn validate(&self, source: &str, context: &Context) -> Result<(), ValidationError> {
todo!()
fn validate(&self, _source: &str, _context: &Context) -> Result<(), ValidationError> {
self.statement_inner.validate(_source, _context)
}
fn run(&self, source: &str, context: &Context) -> Result<Value, RuntimeError> {
todo!()
fn run(&self, _source: &str, _context: &Context) -> Result<Value, RuntimeError> {
self.statement_inner.run(_source, _context)
}
}
impl Format for Statement {
fn format(&self, output: &mut String, indent_level: u8) {
todo!()
fn format(&self, _output: &mut String, _indent_level: u8) {
self.statement_inner.format(_output, _indent_level)
}
}
/// Abstract representation of a statement.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum StatementInner {
enum StatementKind {
Assignment(Box<Assignment>),
Expression(Expression),
IfElse(Box<IfElse>),
@ -50,38 +67,38 @@ pub enum StatementInner {
TypeDefinition(TypeDefinition),
}
impl AbstractTree for StatementInner {
impl AbstractTree for StatementKind {
fn from_syntax(node: SyntaxNode, source: &str, context: &Context) -> Result<Self, SyntaxError> {
SyntaxError::expect_syntax_node(source, "statement", node)?;
SyntaxError::expect_syntax_node(source, "statement_kind", node)?;
let child = node.child(0).unwrap();
match child.kind() {
"assignment" => Ok(StatementInner::Assignment(Box::new(
"assignment" => Ok(StatementKind::Assignment(Box::new(
Assignment::from_syntax(child, source, context)?,
))),
"expression" => Ok(StatementInner::Expression(Expression::from_syntax(
"expression" => Ok(StatementKind::Expression(Expression::from_syntax(
child, source, context,
)?)),
"if_else" => Ok(StatementInner::IfElse(Box::new(IfElse::from_syntax(
"if_else" => Ok(StatementKind::IfElse(Box::new(IfElse::from_syntax(
child, source, context,
)?))),
"while" => Ok(StatementInner::While(Box::new(While::from_syntax(
"while" => Ok(StatementKind::While(Box::new(While::from_syntax(
child, source, context,
)?))),
"block" => Ok(StatementInner::Block(Box::new(Block::from_syntax(
"block" => Ok(StatementKind::Block(Box::new(Block::from_syntax(
child, source, context,
)?))),
"for" => Ok(StatementInner::For(Box::new(For::from_syntax(
"for" => Ok(StatementKind::For(Box::new(For::from_syntax(
child, source, context,
)?))),
"index_assignment" => Ok(StatementInner::IndexAssignment(Box::new(
"index_assignment" => Ok(StatementKind::IndexAssignment(Box::new(
IndexAssignment::from_syntax(child, source, context)?,
))),
"match" => Ok(StatementInner::Match(Match::from_syntax(
"match" => Ok(StatementKind::Match(Match::from_syntax(
child, source, context,
)?)),
"type_definition" => Ok(StatementInner::TypeDefinition(TypeDefinition::from_syntax(
"type_definition" => Ok(StatementKind::TypeDefinition(TypeDefinition::from_syntax(
child, source, context
)?)),
_ => Err(SyntaxError::UnexpectedSyntaxNode {
@ -96,17 +113,17 @@ impl AbstractTree for StatementInner {
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
match self {
StatementInner::Assignment(assignment) => assignment.expected_type(_context),
StatementInner::Expression(expression) => expression.expected_type(_context),
StatementInner::IfElse(if_else) => if_else.expected_type(_context),
StatementInner::Match(r#match) => r#match.expected_type(_context),
StatementInner::While(r#while) => r#while.expected_type(_context),
StatementInner::Block(block) => block.expected_type(_context),
StatementInner::For(r#for) => r#for.expected_type(_context),
StatementInner::IndexAssignment(index_assignment) => {
StatementKind::Assignment(assignment) => assignment.expected_type(_context),
StatementKind::Expression(expression) => expression.expected_type(_context),
StatementKind::IfElse(if_else) => if_else.expected_type(_context),
StatementKind::Match(r#match) => r#match.expected_type(_context),
StatementKind::While(r#while) => r#while.expected_type(_context),
StatementKind::Block(block) => block.expected_type(_context),
StatementKind::For(r#for) => r#for.expected_type(_context),
StatementKind::IndexAssignment(index_assignment) => {
index_assignment.expected_type(_context)
}
StatementInner::TypeDefinition(type_definition) => {
StatementKind::TypeDefinition(type_definition) => {
type_definition.expected_type(_context)
}
}
@ -114,17 +131,17 @@ impl AbstractTree for StatementInner {
fn validate(&self, _source: &str, _context: &Context) -> Result<(), ValidationError> {
match self {
StatementInner::Assignment(assignment) => assignment.validate(_source, _context),
StatementInner::Expression(expression) => expression.validate(_source, _context),
StatementInner::IfElse(if_else) => if_else.validate(_source, _context),
StatementInner::Match(r#match) => r#match.validate(_source, _context),
StatementInner::While(r#while) => r#while.validate(_source, _context),
StatementInner::Block(block) => block.validate(_source, _context),
StatementInner::For(r#for) => r#for.validate(_source, _context),
StatementInner::IndexAssignment(index_assignment) => {
StatementKind::Assignment(assignment) => assignment.validate(_source, _context),
StatementKind::Expression(expression) => expression.validate(_source, _context),
StatementKind::IfElse(if_else) => if_else.validate(_source, _context),
StatementKind::Match(r#match) => r#match.validate(_source, _context),
StatementKind::While(r#while) => r#while.validate(_source, _context),
StatementKind::Block(block) => block.validate(_source, _context),
StatementKind::For(r#for) => r#for.validate(_source, _context),
StatementKind::IndexAssignment(index_assignment) => {
index_assignment.validate(_source, _context)
}
StatementInner::TypeDefinition(type_definition) => {
StatementKind::TypeDefinition(type_definition) => {
type_definition.validate(_source, _context)
}
}
@ -132,39 +149,39 @@ impl AbstractTree for StatementInner {
fn run(&self, _source: &str, _context: &Context) -> Result<Value, RuntimeError> {
match self {
StatementInner::Assignment(assignment) => assignment.run(_source, _context),
StatementInner::Expression(expression) => expression.run(_source, _context),
StatementInner::IfElse(if_else) => if_else.run(_source, _context),
StatementInner::Match(r#match) => r#match.run(_source, _context),
StatementInner::While(r#while) => r#while.run(_source, _context),
StatementInner::Block(block) => block.run(_source, _context),
StatementInner::For(r#for) => r#for.run(_source, _context),
StatementInner::IndexAssignment(index_assignment) => {
StatementKind::Assignment(assignment) => assignment.run(_source, _context),
StatementKind::Expression(expression) => expression.run(_source, _context),
StatementKind::IfElse(if_else) => if_else.run(_source, _context),
StatementKind::Match(r#match) => r#match.run(_source, _context),
StatementKind::While(r#while) => r#while.run(_source, _context),
StatementKind::Block(block) => block.run(_source, _context),
StatementKind::For(r#for) => r#for.run(_source, _context),
StatementKind::IndexAssignment(index_assignment) => {
index_assignment.run(_source, _context)
}
StatementInner::TypeDefinition(type_definition) => {
StatementKind::TypeDefinition(type_definition) => {
type_definition.run(_source, _context)
}
}
}
}
impl Format for StatementInner {
impl Format for StatementKind {
fn format(&self, output: &mut String, indent_level: u8) {
StatementInner::indent(output, indent_level);
StatementKind::indent(output, indent_level);
match self {
StatementInner::Assignment(assignment) => assignment.format(output, indent_level),
StatementInner::Expression(expression) => expression.format(output, indent_level),
StatementInner::IfElse(if_else) => if_else.format(output, indent_level),
StatementInner::Match(r#match) => r#match.format(output, indent_level),
StatementInner::While(r#while) => r#while.format(output, indent_level),
StatementInner::Block(block) => block.format(output, indent_level),
StatementInner::For(r#for) => r#for.format(output, indent_level),
StatementInner::IndexAssignment(index_assignment) => {
StatementKind::Assignment(assignment) => assignment.format(output, indent_level),
StatementKind::Expression(expression) => expression.format(output, indent_level),
StatementKind::IfElse(if_else) => if_else.format(output, indent_level),
StatementKind::Match(r#match) => r#match.format(output, indent_level),
StatementKind::While(r#while) => r#while.format(output, indent_level),
StatementKind::Block(block) => block.format(output, indent_level),
StatementKind::For(r#for) => r#for.format(output, indent_level),
StatementKind::IndexAssignment(index_assignment) => {
index_assignment.format(output, indent_level)
}
StatementInner::TypeDefinition(type_definition) => {
StatementKind::TypeDefinition(type_definition) => {
type_definition.format(output, indent_level)
}
}

View File

@ -149,14 +149,10 @@ impl Interpreter {
check_for_error(root, source, &mut cursor)?;
println!("abstracting...");
let abstract_tree = Root::from_syntax(syntax_tree.root_node(), source, &self.context)?;
abstract_tree.validate(source, &self.context)?;
println!("{abstract_tree:?}");
Ok(abstract_tree)
}

View File

@ -8,12 +8,13 @@ Simple As
(root
(statement
(statement_kind
(expression
(as
(expression
(value
(integer)))
(type)))))
(type))))))
================================================================================
As Function
@ -25,13 +26,14 @@ foo as (int) -> int
(root
(statement
(statement_kind
(expression
(as
(expression
(identifier))
(type
(type)
(type))))))
(type)))))))
================================================================================
As List in For Loop
@ -43,6 +45,7 @@ for i in foobar as [string] {}
(root
(statement
(statement_kind
(for
(identifier)
(expression
@ -52,4 +55,4 @@ for i in foobar as [string] {}
(type
(type
(identifier)))))
(block))))
(block)))))

View File

@ -8,12 +8,14 @@ x = y
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(identifier))))))
(identifier))))))))
================================================================================
Simple Assignment with Type
@ -25,14 +27,16 @@ x <int> = y
(root
(statement
(statement_kind
(assignment
(identifier)
(type_specification
(type))
(assignment_operator)
(statement
(statement_kind
(expression
(identifier))))))
(identifier))))))))
================================================================================
Map Item Assignment
@ -44,6 +48,7 @@ x:y = 1
(root
(statement
(statement_kind
(index_assignment
(index
(index_expression
@ -52,9 +57,10 @@ x:y = 1
(identifier)))
(assignment_operator)
(statement
(statement_kind
(expression
(value
(integer)))))))
(integer)))))))))
================================================================================
List Item Assignment
@ -66,6 +72,7 @@ x:9 = 'foobar'
(root
(statement
(statement_kind
(index_assignment
(index
(index_expression
@ -75,6 +82,7 @@ x:9 = 'foobar'
(integer))))
(assignment_operator)
(statement
(statement_kind
(expression
(value
(string)))))))
(string)))))))))

View File

@ -8,15 +8,17 @@ async { output ('Whaddup') }
(root
(statement
(statement_kind
(block
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string)))))))))
(string)))))))))))
================================================================================
Complex Async Statements
@ -36,8 +38,10 @@ async {
(root
(statement
(statement_kind
(block
(statement
(statement_kind
(if_else
(if
(expression
@ -57,16 +61,19 @@ async {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(boolean))))))
(boolean)))))))
(else
(block
(statement
(statement_kind
(expression
(value
(boolean))))))))
(boolean))))))))))
(statement
(statement_kind
(expression
(value
(string)))))))
(string)))))))))

View File

@ -10,15 +10,17 @@ Simple Block
(root
(statement
(statement_kind
(block
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(integer)))))))))
(integer)))))))))))
================================================================================
Block with Return
@ -34,16 +36,20 @@ Block with Return
(root
(statement
(statement_kind
(block
(statement
(statement_kind
(expression
(value
(integer))))
(integer)))))
(statement
(statement_kind
(expression
(value
(integer))))
(integer)))))
(statement
(statement_kind
(expression
(value
(integer)))))))
(integer)))))))))

View File

@ -8,9 +8,10 @@ Simple Command
(root
(statement
(statement_kind
(expression
(command
(command_text)))))
(command_text))))))
================================================================================
Command Sequence
@ -22,13 +23,15 @@ Command Sequence
(root
(statement
(expression
(command
(command_text))))
(statement
(statement_kind
(expression
(command
(command_text)))))
(statement
(statement_kind
(expression
(command
(command_text))))))
================================================================================
Command with Arguments
@ -40,11 +43,12 @@ Command with Arguments
(root
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument)))))
(command_argument))))))
================================================================================
Command Sequence with Arguments
@ -57,19 +61,21 @@ Command Sequence with Arguments
(root
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument)
(command_argument)
(command_argument))))
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)))))
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
================================================================================
Command Sequence with Arguments
@ -82,19 +88,21 @@ Command Sequence with Arguments
(root
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument)
(command_argument)
(command_argument))))
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)))))
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
================================================================================
Command Assignment
@ -107,24 +115,28 @@ cat_output = ^cat Cargo.toml;
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(command_argument))))))))
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)))))))
(command_argument)))))))))
================================================================================
Command with Semicolon
@ -136,18 +148,21 @@ ls_output = ^ls --long -a; ls_output
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(command_argument))))))))
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))
================================================================================
Command with Semicolon
@ -159,18 +174,21 @@ ls_output = ^ls --long -a; ls_output
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(command_argument))))))))
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))
================================================================================
Command with Quoted Semicolon
@ -182,14 +200,17 @@ ls_output = ^echo ';'; ls_output
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(command
(command_text)
(command_argument))))))
(command_argument))))))))
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))

View File

@ -9,8 +9,9 @@ not_a_comment
(root
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))
================================================================================
Partial Line Comments
@ -22,8 +23,9 @@ not_a_comment # comment
(root
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))
================================================================================
Multiline Comments
@ -37,9 +39,11 @@ not_a_comment #
(root
(statement
(statement_kind
(expression
(identifier)))
(identifier))))
(statement
(statement_kind
(expression
(value
(string)))))
(string))))))

View File

@ -11,11 +11,12 @@ enum Foobar {
(root
(statement
(statement_kind
(type_definition
(enum_definition
(identifier)
(identifier)
(identifier)))))
(identifier))))))
================================================================================
Nested Enum
@ -33,6 +34,7 @@ enum Foobar {
(root
(statement
(statement_kind
(type_definition
(enum_definition
(identifier)
@ -43,7 +45,7 @@ enum Foobar {
(enum_definition
(identifier)
(identifier)
(identifier)))))))
(identifier))))))))
================================================================================
Simple Enum Instance
@ -55,11 +57,12 @@ Foobar::Foo
(root
(statement
(statement_kind
(expression
(value
(enum_instance
(identifier)
(identifier))))))
(identifier)))))))
================================================================================
Nested Enum Instance
@ -71,6 +74,7 @@ FooBar::Bar(BazBuf::Baz(123))
(root
(statement
(statement_kind
(expression
(value
(enum_instance
@ -83,4 +87,4 @@ FooBar::Bar(BazBuf::Baz(123))
(identifier)
(expression
(value
(integer)))))))))))
(integer))))))))))))

View File

@ -14,10 +14,12 @@ fib = (i <int>) <int> {
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(function
@ -28,6 +30,7 @@ fib = (i <int>) <int> {
(type))
(block
(statement
(statement_kind
(if_else
(if
(expression
@ -40,12 +43,14 @@ fib = (i <int>) <int> {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(integer))))))
(integer)))))))
(else
(block
(statement
(statement_kind
(expression
(math
(expression
@ -72,4 +77,4 @@ fib = (i <int>) <int> {
(math_operator)
(expression
(value
(integer))))))))))))))))))))))
(integer))))))))))))))))))))))))))

View File

@ -10,6 +10,7 @@ for i in [1, 2, 3] {
(root
(statement
(statement_kind
(for
(identifier)
(expression
@ -26,12 +27,13 @@ for i in [1, 2, 3] {
(integer))))))
(block
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(identifier)))))))))
(identifier)))))))))))
================================================================================
Nested For Loop
@ -47,21 +49,24 @@ for list in list_of_lists {
(root
(statement
(statement_kind
(for
(identifier)
(expression
(identifier))
(block
(statement
(statement_kind
(for
(identifier)
(expression
(identifier))
(block
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(identifier))))))))))))
(identifier)))))))))))))))

View File

@ -8,6 +8,7 @@ Anonymous Function
(root
(statement
(statement_kind
(expression
(value
(function
@ -15,9 +16,10 @@ Anonymous Function
(type))
(block
(statement
(statement_kind
(expression
(value
(string))))))))))
(string))))))))))))
================================================================================
Function Assignment
@ -31,10 +33,12 @@ foobar = (x <int>, y <int>) <int> {
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(function
@ -48,13 +52,14 @@ foobar = (x <int>, y <int>) <int> {
(type))
(block
(statement
(statement_kind
(expression
(math
(expression
(identifier))
(math_operator)
(expression
(identifier)))))))))))))
(identifier))))))))))))))))
================================================================================
Identifier Function Call
@ -66,13 +71,14 @@ foobar("Hiya")
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string)))))))
(string))))))))
================================================================================
Index Function Call
@ -84,6 +90,7 @@ foo:bar("Hiya")
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -94,7 +101,7 @@ foo:bar("Hiya")
(identifier))))
(expression
(value
(string)))))))
(string))))))))
================================================================================
Double Function Call
@ -106,6 +113,7 @@ foobar()("Hiya")
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -114,7 +122,7 @@ foobar()("Hiya")
(identifier))))
(expression
(value
(string)))))))
(string))))))))
================================================================================
Anonymous Function Call
@ -126,6 +134,7 @@ Anonymous Function Call
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -138,11 +147,12 @@ Anonymous Function Call
(type))
(block
(statement
(statement_kind
(expression
(identifier)))))))
(identifier))))))))
(expression
(value
(string)))))))
(string))))))))
================================================================================
Complex Function Call
@ -161,6 +171,7 @@ foobar(
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -176,14 +187,16 @@ foobar(
(map
(identifier)
(statement
(statement_kind
(expression
(value
(integer))))
(integer)))))
(identifier)
(statement
(statement_kind
(expression
(value
(integer)))))))))))
(integer)))))))))))))
================================================================================
Callback Function Call
@ -195,6 +208,7 @@ x(() <bool> { true })
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -206,9 +220,10 @@ x(() <bool> { true })
(type))
(block
(statement
(statement_kind
(expression
(value
(boolean))))))))))))
(boolean))))))))))))))
================================================================================
Nested Function Call
@ -220,6 +235,7 @@ from_json(read('file.json'))
(root
(statement
(statement_kind
(expression
(function_call
(function_expression
@ -230,4 +246,4 @@ from_json(read('file.json'))
(identifier))
(expression
(value
(string)))))))))
(string))))))))))

View File

@ -11,14 +11,18 @@ x123x
(root
(statement
(expression
(identifier)))
(statement
(expression
(identifier)))
(statement
(expression
(identifier)))
(statement
(statement_kind
(expression
(identifier))))
(statement
(statement_kind
(expression
(identifier))))
(statement
(statement_kind
(expression
(identifier))))
(statement
(statement_kind
(expression
(identifier)))))

View File

@ -8,6 +8,7 @@ if true { "True" }
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -15,9 +16,10 @@ if true { "True" }
(boolean)))
(block
(statement
(statement_kind
(expression
(value
(string)))))))))
(string)))))))))))
================================================================================
Complex If
@ -29,6 +31,7 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -66,9 +69,10 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string)))))))))
(string)))))))))))
================================================================================
Nested If
@ -86,6 +90,7 @@ if true {
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -93,6 +98,7 @@ if true {
(boolean)))
(block
(statement
(statement_kind
(if_else
(if
(expression
@ -106,15 +112,17 @@ if true {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else
(block
(statement
(statement_kind
(expression
(value
(string)))))))))))))
(string))))))))))))))))
================================================================================
If Else
@ -126,6 +134,7 @@ if false { "True" } else { "False" }
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -133,15 +142,17 @@ if false { "True" } else { "False" }
(boolean)))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else
(block
(statement
(statement_kind
(expression
(value
(string)))))))))
(string)))))))))))
================================================================================
If Else If
@ -157,6 +168,7 @@ if 1 == 1 {
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -170,9 +182,10 @@ if 1 == 1 {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else_if
(expression
(logic
@ -185,9 +198,10 @@ if 1 == 1 {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string)))))))))
(string)))))))))))
================================================================================
If Else Else If Else
@ -207,6 +221,7 @@ if false {
(root
(statement
(statement_kind
(if_else
(if
(expression
@ -214,18 +229,20 @@ if false {
(boolean)))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else_if
(expression
(value
(boolean)))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else_if
(expression
(logic
@ -244,12 +261,14 @@ if false {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else
(block
(statement
(statement_kind
(expression
(value
(string)))))))))
(string)))))))))))

View File

@ -12,6 +12,7 @@ foobar:1:42
(root
(statement
(statement_kind
(expression
(index
(index_expression
@ -22,15 +23,17 @@ foobar:1:42
(value
(integer)))))
(index_expression
(identifier)))))
(identifier))))))
(statement
(statement_kind
(expression
(index
(index_expression
(identifier))
(index_expression
(identifier)))))
(identifier))))))
(statement
(statement_kind
(expression
(index
(index_expression
@ -42,7 +45,7 @@ foobar:1:42
(integer)))))
(index_expression
(value
(integer)))))))
(integer))))))))
================================================================================
Nested Indexes
@ -54,6 +57,7 @@ Nested Indexes
(root
(statement
(statement_kind
(expression
(index
(index_expression
@ -85,7 +89,7 @@ Nested Indexes
(value
(integer)))))
(index_expression
(range))))))
(range)))))))
================================================================================
Function Call Index
@ -97,6 +101,7 @@ x:(y()):0
(root
(statement
(statement_kind
(expression
(index
(index_expression
@ -109,4 +114,4 @@ x:(y()):0
(identifier))))))
(index_expression
(value
(integer)))))))
(integer))))))))

View File

@ -8,6 +8,7 @@ List Declaration
(root
(statement
(statement_kind
(expression
(value
(list
@ -16,7 +17,7 @@ List Declaration
(string)))
(expression
(value
(integer))))))))
(integer)))))))))
================================================================================
List Nesting
@ -28,6 +29,7 @@ List Nesting
(root
(statement
(statement_kind
(expression
(value
(list
@ -45,4 +47,4 @@ List Nesting
(list
(expression
(value
(integer))))))))))))))
(integer)))))))))))))))

View File

@ -8,6 +8,7 @@ true && false
(root
(statement
(statement_kind
(expression
(logic
(expression
@ -16,7 +17,7 @@ true && false
(logic_operator)
(expression
(value
(boolean)))))))
(boolean))))))))
================================================================================
Logic Sequence
@ -28,6 +29,7 @@ Logic Sequence
(root
(statement
(statement_kind
(expression
(logic
(expression
@ -42,7 +44,7 @@ Logic Sequence
(logic_operator)
(expression
(value
(boolean)))))))
(boolean))))))))
================================================================================
Complex Logic Sequence
@ -56,6 +58,7 @@ Complex Logic Sequence
(root
(statement
(statement_kind
(expression
(logic
(expression
@ -97,4 +100,4 @@ Complex Logic Sequence
(logic_operator)
(expression
(value
(integer)))))))))
(integer))))))))))

View File

@ -8,14 +8,16 @@ Simple Map
(root
(statement
(statement_kind
(expression
(value
(map
(identifier)
(statement
(statement_kind
(expression
(value
(integer)))))))))
(integer)))))))))))
================================================================================
Map with Types
@ -30,6 +32,7 @@ Map with Types
(root
(statement
(statement_kind
(expression
(value
(map
@ -37,14 +40,16 @@ Map with Types
(type_specification
(type))
(statement
(statement_kind
(expression
(value
(integer))))
(integer)))))
(identifier)
(type_specification
(type
(type)))
(statement
(statement_kind
(expression
(value
(list
@ -53,7 +58,7 @@ Map with Types
(string)))
(expression
(value
(string))))))))))))
(string))))))))))))))
================================================================================
Nested Maps
@ -73,35 +78,42 @@ x = {
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(map
(identifier)
(statement
(statement_kind
(expression
(value
(map
(identifier)
(statement
(statement_kind
(expression
(value
(string))))
(string)))))
(identifier)
(statement
(statement_kind
(expression
(value
(map
(identifier)
(statement
(statement_kind
(expression
(value
(string))))))))))))
(string)))))))))))))))
(identifier)
(statement
(statement_kind
(expression
(value
(integer)))))))))))
(integer))))))))))))))

View File

@ -13,6 +13,7 @@ match x {
(root
(statement
(statement_kind
(match
(expression
(identifier))
@ -20,18 +21,21 @@ match x {
(value
(integer)))
(statement
(statement_kind
(block
(statement
(statement_kind
(expression
(value
(boolean))))))
(boolean))))))))
(match_pattern
(value
(integer)))
(statement
(statement_kind
(expression
(value
(boolean)))))))
(boolean)))))))))
================================================================================
Match Enum
@ -46,6 +50,7 @@ match foobar {
(root
(statement
(statement_kind
(match
(expression
(identifier))
@ -54,14 +59,16 @@ match foobar {
(identifier)
(identifier)))
(statement
(statement_kind
(expression
(value
(boolean))))
(boolean)))))
(match_pattern
(enum_pattern
(identifier)
(identifier)))
(statement
(statement_kind
(expression
(value
(boolean)))))))
(boolean)))))))))

View File

@ -8,11 +8,12 @@ Simple Command Pipe
(root
(statement
(statement_kind
(pipe
(command
(command_text))
(command
(command_text)))))
(command_text))))))
================================================================================
Simple Function Pipe
@ -24,6 +25,7 @@ fs:read('file.txt') | output()
(root
(statement
(statement_kind
(pipe
(function_call
(function_expression
@ -37,4 +39,4 @@ fs:read('file.txt') | output()
(string))))
(function_call
(function_expression
(identifier))))))
(identifier)))))))

View File

@ -8,6 +8,7 @@ Simple Range
(root
(statement
(statement_kind
(expression
(value
(range)))))
(range))))))

View File

@ -10,16 +10,19 @@ x
(root
(statement
(statement_kind
(expression
(value
(integer))))
(integer)))))
(statement
(statement_kind
(expression
(value
(string))))
(string)))))
(statement
(statement_kind
(expression
(identifier))))
(identifier)))))
================================================================================
Simple Assignment
@ -32,21 +35,25 @@ y = "one"
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(integer))))))
(integer))))))))
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(string)))))))
(string)))))))))
================================================================================
Complex Assignment
@ -62,10 +69,12 @@ x = if 1 + 1 == 2 {
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(if_else
(if
(expression
@ -85,15 +94,17 @@ x = if 1 + 1 == 2 {
(integer)))))
(block
(statement
(statement_kind
(expression
(value
(string))))))
(string)))))))
(else
(block
(statement
(statement_kind
(expression
(value
(string)))))))))))
(string))))))))))))))
================================================================================
Expression Precedence
@ -105,10 +116,12 @@ x = 3 == 1 + 2 + 2
(root
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(math
(expression
@ -129,4 +142,4 @@ x = 3 == 1 + 2 + 2
(math_operator)
(expression
(value
(integer)))))))))
(integer)))))))))))

View File

@ -11,6 +11,7 @@ struct Foo {
(root
(statement
(statement_kind
(type_definition
(struct_definition
(identifier)
@ -19,7 +20,7 @@ struct Foo {
(type))
(identifier)
(type_specification
(type))))))
(type)))))))
================================================================================
Nested Structure
@ -38,6 +39,7 @@ struct Foo {
(root
(statement
(statement_kind
(type_definition
(struct_definition
(identifier)
@ -48,14 +50,16 @@ struct Foo {
(type_specification
(type))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(identifier)
(type_specification
(type
(identifier)))
(statement
(statement_kind
(expression
(value
(struct_instance
@ -63,6 +67,7 @@ struct Foo {
(map
(identifier)
(statement
(statement_kind
(expression
(value
(integer)))))))))))))
(integer))))))))))))))))

View File

@ -9,13 +9,15 @@ false
(root
(statement
(expression
(value
(boolean))))
(statement
(statement_kind
(expression
(value
(boolean)))))
(statement
(statement_kind
(expression
(value
(boolean))))))
================================================================================
Integers
@ -28,25 +30,30 @@ Integers
(root
(statement
(expression
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(statement_kind
(expression
(value
(integer)))))
(statement
(statement_kind
(expression
(value
(integer)))))
(statement
(statement_kind
(expression
(value
(integer)))))
(statement
(statement_kind
(expression
(value
(integer)))))
(statement
(statement_kind
(expression
(value
(integer))))))
================================================================================
Floats
@ -68,43 +75,53 @@ infinity_gauntlet
(root
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(float)))))
(statement
(statement_kind
(expression
(value
(float))))
(statement
(expression
(identifier)))
(float)))))
(statement
(statement_kind
(expression
(identifier))))
(statement
(statement_kind
(expression
(identifier)))))
================================================================================
Strings
@ -116,22 +133,27 @@ Strings
(root
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(statement_kind
(expression
(value
(string)))))
(statement
(statement_kind
(expression
(value
(string)))))
(statement
(statement_kind
(expression
(value
(string)))))
(statement
(statement_kind
(expression
(value
(string)))))
(statement
(statement_kind
(expression
(value
(string))))))

View File

@ -10,19 +10,21 @@ while true {
(root
(statement
(statement_kind
(while
(expression
(value
(boolean)))
(block
(statement
(statement_kind
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string))))))))))
(string))))))))))))
================================================================================
Nested While Loop
@ -38,12 +40,14 @@ while true {
(root
(statement
(statement_kind
(while
(expression
(value
(boolean)))
(block
(statement
(statement_kind
(while
(expression
(logic
@ -55,10 +59,12 @@ while true {
(integer)))))
(block
(statement
(statement_kind
(assignment
(identifier)
(assignment_operator)
(statement
(statement_kind
(expression
(value
(integer)))))))))))))
(integer)))))))))))))))))

View File

@ -15,6 +15,13 @@ module.exports = grammar({
prec.left(
seq(
optional('return'),
$.statement_kind,
optional(';'),
),
),
statement_kind: $ =>
prec.left(
choice(
$.assignment,
$.block,
@ -27,8 +34,6 @@ module.exports = grammar({
$.while,
$.type_definition,
),
optional(';'),
),
),
expression: $ =>

View File

@ -36,6 +36,28 @@
]
},
{
"type": "SYMBOL",
"name": "statement_kind"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
}
]
}
},
"statement_kind": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
@ -79,20 +101,6 @@
"name": "type_definition"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
}
]
}
},
"expression": {

View File

@ -606,6 +606,21 @@
"type": "statement",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "statement_kind",
"named": true
}
]
}
},
{
"type": "statement_kind",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,

File diff suppressed because it is too large Load Diff