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

View File

@ -149,14 +149,10 @@ 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)
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,13 +9,15 @@ false
(root (root
(statement (statement
(expression (statement_kind
(value
(boolean))))
(statement
(expression (expression
(value (value
(boolean))))) (boolean)))))
(statement
(statement_kind
(expression
(value
(boolean))))))
================================================================================ ================================================================================
Integers Integers
@ -28,25 +30,30 @@ Integers
(root (root
(statement (statement
(expression (statement_kind
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(expression
(value
(integer))))
(statement
(expression (expression
(value (value
(integer))))) (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 Floats
@ -68,43 +75,53 @@ infinity_gauntlet
(root (root
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement (statement
(statement_kind
(expression (expression
(value (value
(float)))) (float)))))
(statement
(expression
(identifier)))
(statement (statement
(statement_kind
(expression (expression
(identifier)))) (identifier))))
(statement
(statement_kind
(expression
(identifier)))))
================================================================================ ================================================================================
Strings Strings
@ -116,22 +133,27 @@ Strings
(root (root
(statement (statement
(expression (statement_kind
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))
(statement
(expression (expression
(value (value
(string))))) (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 (root
(statement (statement
(statement_kind
(while (while
(expression (expression
(value (value
(boolean))) (boolean)))
(block (block
(statement (statement
(statement_kind
(expression (expression
(function_call (function_call
(function_expression (function_expression
(identifier)) (identifier))
(expression (expression
(value (value
(string)))))))))) (string))))))))))))
================================================================================ ================================================================================
Nested While Loop Nested While Loop
@ -38,12 +40,14 @@ while true {
(root (root
(statement (statement
(statement_kind
(while (while
(expression (expression
(value (value
(boolean))) (boolean)))
(block (block
(statement (statement
(statement_kind
(while (while
(expression (expression
(logic (logic
@ -55,10 +59,12 @@ while true {
(integer))))) (integer)))))
(block (block
(statement (statement
(statement_kind
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(statement (statement
(statement_kind
(expression (expression
(value (value
(integer))))))))))))) (integer)))))))))))))))))

View File

@ -15,6 +15,13 @@ module.exports = grammar({
prec.left( prec.left(
seq( seq(
optional('return'), optional('return'),
$.statement_kind,
optional(';'),
),
),
statement_kind: $ =>
prec.left(
choice( choice(
$.assignment, $.assignment,
$.block, $.block,
@ -27,8 +34,6 @@ module.exports = grammar({
$.while, $.while,
$.type_definition, $.type_definition,
), ),
optional(';'),
),
), ),
expression: $ => 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", "type": "CHOICE",
"members": [ "members": [
{ {
@ -79,20 +101,6 @@
"name": "type_definition" "name": "type_definition"
} }
] ]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
}
]
} }
}, },
"expression": { "expression": {

View File

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

File diff suppressed because it is too large Load Diff