1
0

Continue syntax revision

This commit is contained in:
Jeff 2023-10-31 09:31:10 -04:00
parent 02cded4af4
commit e582f3cad3
43 changed files with 15958 additions and 14195 deletions

View File

@ -10,7 +10,7 @@ take_turn = function <current_room opponent_card> {
remove_card = function <opponent_card> { remove_card = function <opponent_card> {
for card_list in cards { for card_list in cards {
removed = remove card from card_list { # removed = remove card from card_list {
card == opponent_card card == opponent_card
} }
} }

View File

@ -1,6 +1,6 @@
list = [1 2 1 3] list = [1 2 1 3]
removed = remove i in list { removed = remove i from list {
i == 3 i == 3
} }

View File

@ -1,9 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Error, Map, Result, Value}; use crate::{AbstractTree, Error, Identifier, Map, Result, Statement, Value};
use super::{identifier::Identifier, statement::Statement};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Assignment { pub struct Assignment {

View File

@ -2,14 +2,14 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Error, Expression, Identifier, Item, List, Map, Result, Value}; use crate::{AbstractTree, Error, Expression, Identifier, List, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Filter { pub struct Filter {
count: Option<Expression>, count: Option<Expression>,
item_id: Identifier, item_id: Identifier,
collection: Expression, collection: Expression,
predicate: Item, predicate: Statement,
} }
impl AbstractTree for Filter { impl AbstractTree for Filter {
@ -26,7 +26,7 @@ impl AbstractTree for Filter {
let collection = Expression::from_syntax_node(source, collection_node)?; let collection = Expression::from_syntax_node(source, collection_node)?;
let predicate_node = node.child(5).unwrap(); let predicate_node = node.child(5).unwrap();
let predicate = Item::from_syntax_node(source, predicate_node)?; let predicate = Statement::from_syntax_node(source, predicate_node)?;
Ok(Filter { Ok(Filter {
count, count,

View File

@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Expression, Identifier, Item, Map, Result, Value}; use crate::{AbstractTree, Expression, Identifier, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Find { pub struct Find {
identifier: Identifier, identifier: Identifier,
expression: Expression, expression: Expression,
item: Item, item: Statement,
} }
impl AbstractTree for Find { impl AbstractTree for Find {
@ -19,7 +19,7 @@ impl AbstractTree for Find {
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
let item_node = node.child(5).unwrap(); let item_node = node.child(5).unwrap();
let item = Item::from_syntax_node(source, item_node)?; let item = Statement::from_syntax_node(source, item_node)?;
Ok(Find { Ok(Find {
identifier, identifier,

View File

@ -2,14 +2,14 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Error, Expression, Identifier, Item, Map, Result, Value}; use crate::{AbstractTree, Error, Expression, Identifier, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct For { pub struct For {
is_async: bool, is_async: bool,
identifier: Identifier, identifier: Identifier,
expression: Expression, expression: Expression,
item: Item, item: Statement,
} }
impl AbstractTree for For { impl AbstractTree for For {
@ -34,7 +34,7 @@ impl AbstractTree for For {
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
let item_node = node.child(5).unwrap(); let item_node = node.child(5).unwrap();
let item = Item::from_syntax_node(source, item_node)?; let item = Statement::from_syntax_node(source, item_node)?;
Ok(For { Ok(For {
is_async, is_async,

View File

@ -1,76 +0,0 @@
//! Top-level unit of Dust code.
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use tree_sitter::Node;
use crate::{AbstractTree, Error, Map, Result, Statement, Value};
/// An abstractiton of an independent unit of source code, or a comment.
///
/// Items are either comments, which do nothing, or statements, which can be run
/// to produce a single value or interact with a context by creating or
/// referencing variables.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Item {
statements: Vec<Statement>,
}
impl Item {
pub fn new(statements: Vec<Statement>) -> Self {
Self { statements }
}
pub fn run_parallel(&self, source: &str, context: &mut Map) -> Result<Value> {
let statements = &self.statements;
let run_result = statements.into_par_iter().try_for_each(|statement| {
let mut context = context.clone();
statement.run(source, &mut context).map(|_| ())
});
match run_result {
Ok(()) => Ok(Value::Empty),
Err(error) => Err(error),
}
}
}
impl AbstractTree for Item {
fn from_syntax_node(source: &str, node: Node) -> Result<Self> {
debug_assert_eq!("item", node.kind());
let child_count = node.child_count();
let mut statements = Vec::with_capacity(child_count);
for index in 0..child_count {
let child = node.child(index).unwrap();
let statement = match child.kind() {
"statement" => Statement::from_syntax_node(source, child)?,
_ => {
return Err(Error::UnexpectedSyntaxNode {
expected: "comment or statement",
actual: child.kind(),
location: child.start_position(),
relevant_source: source[child.byte_range()].to_string(),
})
}
};
statements.push(statement);
}
Ok(Item { statements })
}
fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
let mut prev_result = Ok(Value::Empty);
for statement in &self.statements {
prev_result?;
prev_result = statement.run(source, context);
}
prev_result
}
}

View File

@ -17,7 +17,6 @@ pub mod identifier;
pub mod if_else; pub mod if_else;
pub mod index; pub mod index;
pub mod insert; pub mod insert;
pub mod item;
pub mod logic; pub mod logic;
pub mod r#match; pub mod r#match;
pub mod math; pub mod math;
@ -32,7 +31,7 @@ pub mod r#while;
pub use { pub use {
assignment::*, expression::*, filter::*, find::*, function_call::*, identifier::*, if_else::*, assignment::*, expression::*, filter::*, find::*, function_call::*, identifier::*, if_else::*,
index::*, insert::*, item::*, logic::*, math::*, r#async::*, r#for::*, r#match::*, r#while::*, index::*, insert::*, logic::*, math::*, r#async::*, r#for::*, r#match::*, r#while::*,
remove::*, select::*, statement::*, sublist::*, tool::*, transform::*, value_node::*, remove::*, select::*, statement::*, sublist::*, tool::*, transform::*, value_node::*,
}; };

View File

@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Expression, Identifier, Item, Map, Result, Value}; use crate::{AbstractTree, Expression, Identifier, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Remove { pub struct Remove {
identifier: Identifier, identifier: Identifier,
expression: Expression, expression: Expression,
item: Item, item: Statement,
} }
impl AbstractTree for Remove { impl AbstractTree for Remove {
@ -19,7 +19,7 @@ impl AbstractTree for Remove {
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
let item_node = node.child(5).unwrap(); let item_node = node.child(5).unwrap();
let item = Item::from_syntax_node(source, item_node)?; let item = Statement::from_syntax_node(source, item_node)?;
Ok(Remove { Ok(Remove {
identifier, identifier,

View File

@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Expression, Identifier, Item, Map, Result, Table, Value}; use crate::{AbstractTree, Expression, Identifier, Map, Result, Statement, Table, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Select { pub struct Select {
identifiers: Vec<Identifier>, identifiers: Vec<Identifier>,
expression: Expression, expression: Expression,
item: Option<Item>, item: Option<Statement>,
} }
impl AbstractTree for Select { impl AbstractTree for Select {
@ -33,7 +33,7 @@ impl AbstractTree for Select {
let item = if final_node.kind() == "}" { let item = if final_node.kind() == "}" {
let item_node = node.child(child_count - 2).unwrap(); let item_node = node.child(child_count - 2).unwrap();
Some(Item::from_syntax_node(source, item_node)?) Some(Statement::from_syntax_node(source, item_node)?)
} else { } else {
None None
}; };

View File

@ -12,7 +12,6 @@ use crate::{
/// Expression, it will always return a non-empty value when run. /// Expression, it will always return a non-empty value when run.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum Statement { pub enum Statement {
Comment(String),
Assignment(Box<Assignment>), Assignment(Box<Assignment>),
Expression(Expression), Expression(Expression),
IfElse(Box<IfElse>), IfElse(Box<IfElse>),
@ -35,12 +34,6 @@ impl AbstractTree for Statement {
let child = node.child(0).unwrap(); let child = node.child(0).unwrap();
match child.kind() { match child.kind() {
"comment" => {
let comment_node = node.child(0).unwrap();
let text = &source[comment_node.byte_range()];
Ok(Statement::Comment(text.to_string()))
}
"assignment" => Ok(Statement::Assignment(Box::new( "assignment" => Ok(Statement::Assignment(Box::new(
Assignment::from_syntax_node(source, child)?, Assignment::from_syntax_node(source, child)?,
))), ))),
@ -81,7 +74,7 @@ impl AbstractTree for Statement {
source, child, source, child,
)?))), )?))),
_ => Err(Error::UnexpectedSyntaxNode { _ => Err(Error::UnexpectedSyntaxNode {
expected: "comment, assignment, expression, if...else, while, for, transform, filter, tool, async, find, remove, select or insert", expected: "assignment, expression, if...else, while, for, transform, filter, tool, async, find, remove, select or insert",
actual: child.kind(), actual: child.kind(),
location: child.start_position(), location: child.start_position(),
relevant_source: source[child.byte_range()].to_string(), relevant_source: source[child.byte_range()].to_string(),
@ -91,7 +84,6 @@ impl AbstractTree for Statement {
fn run(&self, source: &str, context: &mut Map) -> Result<Value> { fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
match self { match self {
Statement::Comment(comment) => Ok(Value::String(comment.clone())),
Statement::Assignment(assignment) => assignment.run(source, context), Statement::Assignment(assignment) => assignment.run(source, context),
Statement::Expression(expression) => expression.run(source, context), Statement::Expression(expression) => expression.run(source, context),
Statement::IfElse(if_else) => if_else.run(source, context), Statement::IfElse(if_else) => if_else.run(source, context),

View File

@ -71,7 +71,7 @@ impl AbstractTree for Tool {
for index in 2..node.child_count() - 1 { for index in 2..node.child_count() - 1 {
let child_node = node.child(index).unwrap(); let child_node = node.child(index).unwrap();
if child_node.is_named() { if child_node.kind() == "expression" {
let expression = Expression::from_syntax_node(source, child_node)?; let expression = Expression::from_syntax_node(source, child_node)?;
expressions.push(expression); expressions.push(expression);

View File

@ -2,13 +2,13 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Expression, Identifier, Item, List, Map, Result, Value}; use crate::{AbstractTree, Expression, Identifier, List, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Transform { pub struct Transform {
identifier: Identifier, identifier: Identifier,
expression: Expression, expression: Expression,
item: Item, item: Statement,
} }
impl AbstractTree for Transform { impl AbstractTree for Transform {
@ -20,7 +20,7 @@ impl AbstractTree for Transform {
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
let item_node = node.child(5).unwrap(); let item_node = node.child(5).unwrap();
let item = Item::from_syntax_node(source, item_node)?; let item = Statement::from_syntax_node(source, item_node)?;
Ok(Transform { Ok(Transform {
identifier, identifier,

View File

@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{ use crate::{
AbstractTree, Error, Expression, Function, Identifier, Item, List, Map, Result, Table, Value, AbstractTree, Error, Expression, Function, Identifier, List, Map, Result, Statement, Table,
ValueType, Value, ValueType,
}; };
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
@ -102,7 +102,7 @@ impl AbstractTree for ValueNode {
let mut identifiers = Vec::new(); let mut identifiers = Vec::new();
let item_node = child.child(child.child_count() - 2).unwrap(); let item_node = child.child(child.child_count() - 2).unwrap();
let item = Item::from_syntax_node(source, item_node)?; let item = Statement::from_syntax_node(source, item_node)?;
for index in 1..child.child_count() - 3 { for index in 1..child.child_count() - 3 {
let child_node = child.child(index).unwrap(); let child_node = child.child(index).unwrap();

View File

@ -1,12 +1,12 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
use crate::{AbstractTree, Expression, Item, Map, Result, Value}; use crate::{AbstractTree, Expression, Map, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct While { pub struct While {
expression: Expression, expression: Expression,
items: Vec<Item>, statement: Statement,
} }
impl AbstractTree for While { impl AbstractTree for While {
@ -16,27 +16,21 @@ impl AbstractTree for While {
let expression_node = node.child(1).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
let child_count = node.child_count(); let statement_node = node.child(3).unwrap();
let mut items = Vec::with_capacity(child_count); let statement = Statement::from_syntax_node(source, statement_node)?;
for index in 3..child_count - 1 { Ok(While {
let item_node = node.child(index).unwrap(); expression,
let item = Item::from_syntax_node(source, item_node)?; statement,
})
items.push(item);
}
Ok(While { expression, items })
} }
fn run(&self, source: &str, context: &mut Map) -> Result<Value> { fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
while self.expression.run(source, context)?.as_boolean()? { while self.expression.run(source, context)?.as_boolean()? {
for item in &self.items { self.statement.run(source, context)?;
item.run(source, context)?;
}
} }
Ok(crate::Value::Empty) Ok(Value::Empty)
} }
} }

View File

@ -6,7 +6,7 @@ use std::fmt::{self, Debug, Formatter};
use tree_sitter::{Parser, Tree as TSTree}; use tree_sitter::{Parser, Tree as TSTree};
use crate::{abstract_tree::item::Item, language, AbstractTree, Map, Result, Value}; use crate::{language, AbstractTree, Map, Result, Statement, Value};
/// Evaluate the given source code. /// Evaluate the given source code.
/// ///
@ -86,7 +86,7 @@ impl<'context, 'code> Evaluator<'context, 'code> {
let mut prev_result = Ok(Value::Empty); let mut prev_result = Ok(Value::Empty);
for item_node in root_node.children(&mut cursor) { for item_node in root_node.children(&mut cursor) {
let item = Item::from_syntax_node(self.source, item_node)?; let item = Statement::from_syntax_node(self.source, item_node)?;
prev_result = item.run(self.source, self.context); prev_result = item.run(self.source, self.context);
} }

View File

@ -1,5 +1,5 @@
//! Command line interface for the dust programming language. //! Command line interface for the dust programming language.
use async_std::{fs::read_to_string, prelude::*}; use async_std::fs::read_to_string;
use clap::Parser; use clap::Parser;
use rustyline::{ use rustyline::{
completion::FilenameCompleter, completion::FilenameCompleter,

View File

@ -2,19 +2,19 @@ use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{Identifier, Item}; use crate::{Identifier, Statement};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Function { pub struct Function {
parameters: Vec<Identifier>, parameters: Vec<Identifier>,
body: Item, body: Box<Statement>,
} }
impl Function { impl Function {
pub fn new(identifiers: Vec<Identifier>, items: Item) -> Self { pub fn new(identifiers: Vec<Identifier>, items: Statement) -> Self {
Function { Function {
parameters: identifiers, parameters: identifiers,
body: items, body: Box::new(items),
} }
} }
@ -22,7 +22,7 @@ impl Function {
&self.parameters &self.parameters
} }
pub fn body(&self) -> &Item { pub fn body(&self) -> &Statement {
&self.body &self.body
} }
} }

View File

@ -7,14 +7,16 @@ async { (output 'Whaddup') }
--- ---
(root (root
(block
(statement (statement
(async (async
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(value (value
(string))))))))) (string)))))))))))
================== ==================
Complex Async Statements Complex Async Statements
@ -33,8 +35,10 @@ async {
--- ---
(root (root
(block
(statement (statement
(async (async
(block
(statement (statement
(if_else (if_else
(if (if
@ -53,15 +57,18 @@ async {
(expression (expression
(value (value
(integer))))) (integer)))))
(statement (block
(expression
(value
(boolean)))))
(else
(statement (statement
(expression (expression
(value (value
(boolean)))))) (boolean))))))
(else
(block
(statement
(expression (expression
(value (value
(string))))))) (boolean))))))))
(statement
(expression
(value
(string)))))))))

View File

@ -8,9 +8,10 @@ not_a_comment
--- ---
(root (root
(block
(statement (statement
(expression (expression
(identifier))) (identifier))))
(comment)) (comment))
================== ==================
@ -22,9 +23,10 @@ not_a_comment # comment
--- ---
(root (root
(block
(statement (statement
(expression (expression
(identifier))) (identifier))))
(comment)) (comment))
================== ==================
@ -39,6 +41,7 @@ not_a_comment #
(root (root
(comment) (comment)
(block
(statement (statement
(expression (expression
(identifier))) (identifier)))
@ -47,4 +50,4 @@ not_a_comment #
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))

View File

@ -9,6 +9,7 @@ filter i in [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(filter (filter
(identifier) (identifier)
@ -24,6 +25,7 @@ filter i in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(expression (expression
(logic (logic
@ -32,7 +34,7 @@ filter i in [1, 2, 3] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))) (integer)))))))))))
================== ==================
Nested Filter Loop Nested Filter Loop
@ -47,16 +49,19 @@ filter i in big_list {
--- ---
(root (root
(block
(statement (statement
(filter (filter
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(filter (filter
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(expression (expression
(logic (logic
@ -65,4 +70,4 @@ filter i in big_list {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))))) (integer))))))))))))))

View File

@ -9,6 +9,7 @@ find i in [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(find (find
(identifier) (identifier)
@ -24,6 +25,7 @@ find i in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(expression (expression
(logic (logic
@ -32,7 +34,7 @@ find i in [1, 2, 3] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))) (integer)))))))))))
================== ==================
Nested Find Loop Nested Find Loop
@ -54,6 +56,7 @@ find i in ["one", "two", "three"] {
--- ---
(root (root
(block
(statement (statement
(find (find
(identifier) (identifier)
@ -69,6 +72,7 @@ find i in ["one", "two", "three"] {
(expression (expression
(value (value
(string)))))) (string))))))
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -78,6 +82,7 @@ find i in ["one", "two", "three"] {
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(expression (expression
(logic (logic
@ -86,7 +91,8 @@ find i in ["one", "two", "three"] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(string))))))))) (string)))))))))))
(statement
(if_else (if_else
(if (if
(expression (expression
@ -99,12 +105,14 @@ find i in ["one", "two", "three"] {
(expression (expression
(value (value
(string))))) (string)))))
(block
(statement (statement
(expression (expression
(value (value
(boolean))))) (boolean))))))
(else (else
(block
(statement (statement
(expression (expression
(value (value
(boolean)))))))))) (boolean)))))))))))))

View File

@ -9,6 +9,7 @@ for i in [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(for (for
(identifier) (identifier)
@ -24,11 +25,12 @@ for i in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(identifier)))))))) (identifier))))))))))
================== ==================
Nested For Loop Nested For Loop
@ -43,18 +45,21 @@ for list in list_of_lists {
--- ---
(root (root
(block
(statement (statement
(for (for
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(for (for
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(identifier)))))))))) (identifier)))))))))))))

View File

@ -7,14 +7,16 @@ function { "Hiya" }
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
(function (function
(block
(statement (statement
(expression (expression
(value (value
(string))))))))) (string)))))))))))
================== ==================
Function Call Function Call
@ -25,13 +27,14 @@ Function Call
--- ---
(root (root
(block
(statement (statement
(expression (expression
(function_call (function_call
(identifier) (identifier)
(expression (expression
(value (value
(string))))))) (string))))))))
================== ==================
Complex Function Complex Function
@ -45,21 +48,24 @@ function <message number> {
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
(function (function
(identifier) (identifier)
(identifier) (identifier)
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(identifier)))) (identifier)))))
(statement
(expression (expression
(tool (tool
(expression (expression
(identifier)))))))))) (identifier))))))))))))
================== ==================
Complex Function Call Complex Function Call
@ -77,6 +83,7 @@ Complex Function Call
--- ---
(root (root
(block
(statement (statement
(expression (expression
(function_call (function_call
@ -97,4 +104,4 @@ Complex Function Call
(identifier) (identifier)
(expression (expression
(value (value
(integer)))))))))) (integer)))))))))))

View File

@ -9,6 +9,7 @@ __xyz__
--- ---
(root (root
(block
(statement (statement
(expression (expression
(identifier))) (identifier)))
@ -17,4 +18,4 @@ __xyz__
(identifier))) (identifier)))
(statement (statement
(expression (expression
(identifier)))) (identifier)))))

View File

@ -7,16 +7,18 @@ if true { "True" }
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(expression (expression
(value (value
(string)))))))) (string))))))))))
================== ==================
Complex If Complex If
@ -27,6 +29,7 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
@ -63,10 +66,11 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
(expression (expression
(value (value
(integer))))))))))))) (integer)))))))))))))
(block
(statement (statement
(expression (expression
(value (value
(string)))))))) (string))))))))))
================== ==================
Nested If Nested If
@ -83,12 +87,14 @@ if true {
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(if_else (if_else
(if (if
@ -101,15 +107,17 @@ if true {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else (else
(block
(statement (statement
(expression (expression
(value (value
(string))))))))))) (string))))))))))))))
================== ==================
If Else If Else
@ -120,21 +128,24 @@ if false { "True" } else { "False" }
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else (else
(block
(statement (statement
(expression (expression
(value (value
(string)))))))) (string))))))))))
================== ==================
If Else If If Else If
@ -149,6 +160,7 @@ if 1 == 1 {
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
@ -161,10 +173,11 @@ if 1 == 1 {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else_if (else_if
(expression (expression
(logic (logic
@ -175,10 +188,11 @@ if 1 == 1 {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(expression (expression
(value (value
(string)))))))) (string))))))))))
================== ==================
If Else Else If Else If Else Else If Else
@ -197,24 +211,27 @@ if false {
--- ---
(root (root
(block
(statement (statement
(if_else (if_else
(if (if
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else_if (else_if
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else_if (else_if
(expression (expression
(logic (logic
@ -231,12 +248,14 @@ if false {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else (else
(block
(statement (statement
(expression (expression
(value (value
(string)))))))) (string))))))))))

View File

@ -11,6 +11,7 @@ foobar:1:42
--- ---
(root (root
(block
(statement (statement
(expression (expression
(index (index
@ -42,7 +43,7 @@ foobar:1:42
(integer))))) (integer)))))
(expression (expression
(value (value
(integer))))))) (integer))))))))
================== ==================
Nested Indexes Nested Indexes
@ -53,6 +54,7 @@ Nested Indexes
--- ---
(root (root
(block
(statement (statement
(expression (expression
(index (index
@ -89,4 +91,4 @@ Nested Indexes
(integer))) (integer)))
(expression (expression
(value (value
(integer))))))) (integer))))))))

View File

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

View File

@ -7,6 +7,7 @@ Simple Map
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -14,7 +15,7 @@ Simple Map
(identifier) (identifier)
(expression (expression
(value (value
(integer)))))))) (integer)))))))))
================== ==================
Nested Maps Nested Maps
@ -33,6 +34,7 @@ x = {
--- ---
(root (root
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -60,4 +62,4 @@ x = {
(identifier) (identifier)
(expression (expression
(value (value
(integer)))))))))) (integer)))))))))))

View File

@ -1,5 +1,5 @@
================== ==================
Equality \==
================== ==================
3 == 1 + 1 + 1 3 == 1 + 1 + 1
@ -7,6 +7,7 @@ Equality
--- ---
(root (root
(block
(statement (statement
(expression (expression
(logic (logic
@ -28,7 +29,7 @@ Equality
(math_operator) (math_operator)
(expression (expression
(value (value
(integer))))))))) (integer))))))))))
================== ==================
&& &&
@ -39,6 +40,7 @@ Equality
--- ---
(root (root
(block
(statement (statement
(expression (expression
(logic (logic
@ -60,7 +62,7 @@ Equality
(logic_operator) (logic_operator)
(expression (expression
(value (value
(boolean))))))))) (boolean))))))))))
================== ==================
\|| \||
@ -71,6 +73,7 @@ Equality
--- ---
(root (root
(block
(statement (statement
(expression (expression
(logic (logic
@ -92,4 +95,4 @@ Equality
(logic_operator) (logic_operator)
(expression (expression
(value (value
(boolean))))))))) (boolean))))))))))

View File

@ -9,6 +9,7 @@ reduce i to acc in [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(reduce (reduce
(identifier) (identifier)
@ -25,13 +26,14 @@ reduce i to acc in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(statement (statement
(expression (expression
(identifier)))))))) (identifier))))))))))
================== ==================
Nested Reduce Loop Nested Reduce Loop
@ -44,6 +46,7 @@ reduce i to acc in ["one", "two", "three"] {
--- ---
(root (root
(block
(statement (statement
(reduce (reduce
(identifier) (identifier)
@ -60,10 +63,11 @@ reduce i to acc in ["one", "two", "three"] {
(expression (expression
(value (value
(string)))))) (string))))))
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(statement (statement
(expression (expression
(identifier)))))))) (identifier))))))))))

View File

@ -9,6 +9,7 @@ remove i from [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(remove (remove
(identifier) (identifier)
@ -24,6 +25,7 @@ remove i from [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(expression (expression
(logic (logic
@ -32,7 +34,7 @@ remove i from [1, 2, 3] {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))) (integer)))))))))))
================== ==================
Nested Remove Nested Remove
@ -47,6 +49,7 @@ removed = remove i from big_list {
--- ---
(root (root
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -56,11 +59,13 @@ removed = remove i from big_list {
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(remove (remove
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(expression (expression
(logic (logic
@ -69,4 +74,4 @@ removed = remove i from big_list {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(integer))))))))))))) (integer))))))))))))))))

View File

@ -9,6 +9,7 @@ x
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -19,7 +20,7 @@ x
(string)))) (string))))
(statement (statement
(expression (expression
(identifier)))) (identifier)))))
================== ==================
Simple Assignment Simple Assignment
@ -31,6 +32,7 @@ y = "one"
--- ---
(root (root
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -46,7 +48,7 @@ y = "one"
(statement (statement
(expression (expression
(value (value
(string))))))) (string))))))))
================== ==================
Complex Assignment Complex Assignment
@ -61,6 +63,7 @@ x = if 1 + 1 == 2 {
--- ---
(root (root
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -83,15 +86,17 @@ x = if 1 + 1 == 2 {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))
(else (else
(block
(statement (statement
(expression (expression
(value (value
(string)))))))))) (string))))))))))))
================== ==================
Expression Precedence Expression Precedence
@ -102,6 +107,7 @@ x = 3 == 1 + 2 + 2
--- ---
(root (root
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -127,4 +133,4 @@ x = 3 == 1 + 2 + 2
(math_operator) (math_operator)
(expression (expression
(value (value
(integer))))))))))) (integer))))))))))))

View File

@ -11,6 +11,7 @@ table <messages, numbers> [
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -46,7 +47,8 @@ table <messages, numbers> [
(string))) (string)))
(expression (expression
(value (value
(float)))))))))))))) (float)))))))))))))))
================== ==================
Table Access Table Access
================== ==================
@ -58,11 +60,13 @@ select <number> from foobar {
--- ---
(root (root
(block
(statement (statement
(select (select
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(expression (expression
(logic (logic
@ -71,7 +75,7 @@ select <number> from foobar {
(logic_operator) (logic_operator)
(expression (expression
(value (value
(string))))))))) (string)))))))))))
================== ==================
Table Insert Table Insert
@ -84,6 +88,7 @@ insert into foobar [
--- ---
(root (root
(block
(statement (statement
(insert (insert
(identifier) (identifier)
@ -98,4 +103,4 @@ insert into foobar [
(string))) (string)))
(expression (expression
(value (value
(integer)))))))))))) (integer)))))))))))))

View File

@ -0,0 +1,35 @@
==================
Simple Tool Call
==================
(output 'hi')
---
(root
(block
(statement
(expression
(tool
(expression
(value
(string))))))))
==================
Nested Tool Call
==================
(assert_equal random_integer, 4)
---
(root
(block
(statement
(expression
(tool
(expression
(identifier))
(expression
(value
(integer))))))))

View File

@ -9,6 +9,7 @@ transform i in [1, 2, 3] {
--- ---
(root (root
(block
(statement (statement
(transform (transform
(identifier) (identifier)
@ -24,11 +25,12 @@ transform i in [1, 2, 3] {
(expression (expression
(value (value
(integer)))))) (integer))))))
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(identifier)))))))) (identifier))))))))))
================== ==================
Nested Transform Loop Nested Transform Loop
@ -43,6 +45,7 @@ transform i in [['one'] ['two'] ['three']] {
--- ---
(root (root
(block
(statement (statement
(transform (transform
(identifier) (identifier)
@ -67,11 +70,13 @@ transform i in [['one'] ['two'] ['three']] {
(expression (expression
(value (value
(string))))))))) (string)))))))))
(block
(statement (statement
(transform (transform
(identifier) (identifier)
(expression (expression
(identifier)) (identifier))
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -79,4 +84,4 @@ transform i in [['one'] ['two'] ['three']] {
(statement (statement
(expression (expression
(value (value
(string))))))))))) (string))))))))))))))

View File

@ -8,6 +8,7 @@ false
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -15,7 +16,7 @@ false
(statement (statement
(expression (expression
(value (value
(boolean))))) (boolean))))))
================== ==================
Integers Integers
@ -27,6 +28,7 @@ Integers
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -46,7 +48,7 @@ Integers
(statement (statement
(expression (expression
(value (value
(integer))))) (integer))))))
================== ==================
Strings Strings
@ -57,6 +59,7 @@ Strings
--- ---
(root (root
(block
(statement (statement
(expression (expression
(value (value
@ -76,4 +79,4 @@ Strings
(statement (statement
(expression (expression
(value (value
(string))))) (string))))))

View File

@ -9,25 +9,26 @@ while true {
--- ---
(root (root
(block
(statement (statement
(while (while
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(expression (expression
(tool (tool
(expression (expression
(value (value
(string))))))))) (string)))))))))))
================== ==================
Nested While Loop Nested While Loop
================== ==================
while true { while (true) {
x = 4 while (x > 0) {
while x > 0 {
x -= 1 x -= 1
} }
} }
@ -35,19 +36,14 @@ while true {
--- ---
(root (root
(block
(statement (statement
(while (while
(expression (expression
(value (value
(boolean))) (boolean)))
(block
(statement (statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(integer)))))
(while (while
(expression (expression
(logic (logic
@ -57,6 +53,7 @@ while true {
(expression (expression
(value (value
(integer))))) (integer)))))
(block
(statement (statement
(assignment (assignment
(identifier) (identifier)
@ -64,4 +61,4 @@ while true {
(statement (statement
(expression (expression
(value (value
(integer))))))))))) (integer))))))))))))))

View File

@ -6,16 +6,16 @@ module.exports = grammar({
extras: $ => [ /\s/, $.comment ], extras: $ => [ /\s/, $.comment ],
rules: { rules: {
root: $ => repeat1($.statement), root: $ => repeat1($.block),
comment: $ => /[#][^#\n]*[#|\n]/, comment: $ => /[#][^#\n]*[#|\n]/,
statement: $ => prec.left(choice( block: $ => prec.right(choice(
repeat1($._statement_kind), repeat1($.statement),
seq('{', repeat1($._statement_kind), '}'), seq('{', repeat1($.statement), '}'),
)), )),
_statement_kind: $ => prec.left(choice( statement: $ => prec.left(choice(
$.assignment, $.assignment,
$.async, $.async,
$.expression, $.expression,
@ -37,7 +37,7 @@ module.exports = grammar({
seq('(', $._expression_kind, ')'), seq('(', $._expression_kind, ')'),
), ),
_expression_kind: $ => prec.right(choice( _expression_kind: $ => prec.left(choice(
$.function_call, $.function_call,
$.identifier, $.identifier,
$.index, $.index,
@ -89,12 +89,12 @@ module.exports = grammar({
map: $ => seq( map: $ => seq(
'{', '{',
repeat(seq( repeat(prec(1, seq(
$.identifier, $.identifier,
'=', '=',
$.expression, $.expression,
optional(',') optional(',')
)), ))),
'}', '}',
), ),
@ -111,9 +111,7 @@ module.exports = grammar({
function: $ => seq( function: $ => seq(
'function', 'function',
optional(seq('<', repeat(seq($.identifier, optional(','))), '>')), optional(seq('<', repeat(seq($.identifier, optional(','))), '>')),
'{', $.block,
$.statement,
'}',
), ),
table: $ => prec.left(seq( table: $ => prec.left(seq(
@ -128,13 +126,13 @@ module.exports = grammar({
$.expression, $.expression,
)), )),
math_operator: $ => token(choice( math_operator: $ => choice(
'+', '+',
'-', '-',
'*', '*',
'/', '/',
'%', '%',
)), ),
logic: $ => prec.right(seq( logic: $ => prec.right(seq(
$.expression, $.expression,
@ -142,7 +140,7 @@ module.exports = grammar({
$.expression, $.expression,
)), )),
logic_operator: $ => token(choice( logic_operator: $ => choice(
'==', '==',
'!=', '!=',
'&&', '&&',
@ -151,19 +149,19 @@ module.exports = grammar({
'<', '<',
">=", ">=",
"<=", "<=",
)), ),
assignment: $ => prec.right(seq( assignment: $ => seq(
$.identifier, $.identifier,
$.assignment_operator, $.assignment_operator,
$.statement, $.statement,
)), ),
assignment_operator: $ => token(choice( assignment_operator: $ => choice(
"=", "=",
"+=", "+=",
"-=", "-=",
)), ),
if_else: $ => prec.left(seq( if_else: $ => prec.left(seq(
$.if, $.if,
@ -175,7 +173,7 @@ module.exports = grammar({
'if', 'if',
$.expression, $.expression,
'{', '{',
$.statement, $.block,
'}', '}',
), ),
@ -183,14 +181,14 @@ module.exports = grammar({
'else if', 'else if',
$.expression, $.expression,
'{', '{',
$.statement, $.block,
'}', '}',
), ),
else: $ => seq( else: $ => seq(
'else', 'else',
'{', '{',
$.statement, $.block,
'}', '}',
), ),
@ -208,7 +206,7 @@ module.exports = grammar({
repeat1(seq( repeat1(seq(
$.expression, $.expression,
'=>', '=>',
$.statement, $.block,
)), )),
'}', '}',
), ),
@ -216,9 +214,7 @@ module.exports = grammar({
while: $ => seq( while: $ => seq(
'while', 'while',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
for: $ => seq( for: $ => seq(
@ -226,9 +222,7 @@ module.exports = grammar({
$.identifier, $.identifier,
'in', 'in',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
transform: $ => seq( transform: $ => seq(
@ -236,9 +230,7 @@ module.exports = grammar({
$.identifier, $.identifier,
'in', 'in',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
filter: $ => seq( filter: $ => seq(
@ -247,9 +239,7 @@ module.exports = grammar({
field('statement_id', $.identifier), field('statement_id', $.identifier),
'in', 'in',
field('collection', $.expression), field('collection', $.expression),
'{', field('predicate', $.block),
field('predicate', $.statement),
'}',
), ),
find: $ => seq( find: $ => seq(
@ -257,9 +247,7 @@ module.exports = grammar({
$.identifier, $.identifier,
'in', 'in',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
remove: $ => seq( remove: $ => seq(
@ -267,9 +255,7 @@ module.exports = grammar({
$.identifier, $.identifier,
'from', 'from',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
reduce: $ => seq( reduce: $ => seq(
@ -279,9 +265,7 @@ module.exports = grammar({
$.identifier, $.identifier,
'in', 'in',
$.expression, $.expression,
'{', $.block,
$.statement,
'}',
), ),
select: $ => prec.right(seq( select: $ => prec.right(seq(
@ -291,7 +275,7 @@ module.exports = grammar({
'>', '>',
'from', 'from',
$.expression, $.expression,
optional(seq('{', $.statement, '}')), optional($.block),
)), )),
insert: $ => prec.right(seq( insert: $ => prec.right(seq(
@ -303,15 +287,15 @@ module.exports = grammar({
async: $ => seq( async: $ => seq(
'async', 'async',
'{', $.block,
$.statement,
'}'
), ),
tool: $ => prec.right(seq( tool: $ => seq(
'(',
$._tool_kind, $._tool_kind,
repeat(prec.left(seq($.expression, optional(',')))), repeat(seq($.expression, optional(','))),
)), ')',
),
_tool_kind: $ => choice( _tool_kind: $ => choice(
// General // General

View File

@ -6,15 +6,15 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
} }
}, },
"comment": { "comment": {
"type": "PATTERN", "type": "PATTERN",
"value": "[#][^#\\n]*[#|\\n]" "value": "[#][^#\\n]*[#|\\n]"
}, },
"statement": { "block": {
"type": "PREC_LEFT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
@ -23,7 +23,7 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement_kind" "name": "statement"
} }
}, },
{ {
@ -37,7 +37,7 @@
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement_kind" "name": "statement"
} }
}, },
{ {
@ -49,7 +49,7 @@
] ]
} }
}, },
"_statement_kind": { "statement": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
"content": { "content": {
@ -141,7 +141,7 @@
] ]
}, },
"_expression_kind": { "_expression_kind": {
"type": "PREC_RIGHT", "type": "PREC_LEFT",
"value": 0, "value": 0,
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
@ -481,6 +481,9 @@
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
"content": {
"type": "PREC",
"value": 1,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -510,6 +513,7 @@
} }
] ]
} }
}
}, },
{ {
"type": "STRING", "type": "STRING",
@ -611,17 +615,9 @@
} }
] ]
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -701,8 +697,6 @@
} }
}, },
"math_operator": { "math_operator": {
"type": "TOKEN",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -726,7 +720,6 @@
"value": "%" "value": "%"
} }
] ]
}
}, },
"logic": { "logic": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
@ -750,8 +743,6 @@
} }
}, },
"logic_operator": { "logic_operator": {
"type": "TOKEN",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -787,12 +778,8 @@
"value": "<=" "value": "<="
} }
] ]
}
}, },
"assignment": { "assignment": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -808,11 +795,8 @@
"name": "statement" "name": "statement"
} }
] ]
}
}, },
"assignment_operator": { "assignment_operator": {
"type": "TOKEN",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -828,7 +812,6 @@
"value": "-=" "value": "-="
} }
] ]
}
}, },
"if_else": { "if_else": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
@ -884,7 +867,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -909,7 +892,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -930,7 +913,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1013,7 +996,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
} }
] ]
} }
@ -1035,17 +1018,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1068,17 +1043,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1101,17 +1068,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1158,21 +1117,13 @@
"name": "expression" "name": "expression"
} }
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "FIELD", "type": "FIELD",
"name": "predicate", "name": "predicate",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
} }
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1195,17 +1146,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1228,17 +1171,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1269,17 +1204,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
@ -1336,22 +1263,9 @@
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -1393,35 +1307,25 @@
"type": "STRING", "type": "STRING",
"value": "async" "value": "async"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "block"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}, },
"tool": { "tool": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "STRING",
"value": "("
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_tool_kind" "name": "_tool_kind"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -1443,10 +1347,12 @@
} }
] ]
} }
} },
{
"type": "STRING",
"value": ")"
} }
] ]
}
}, },
"_tool_kind": { "_tool_kind": {
"type": "CHOICE", "type": "CHOICE",

View File

@ -22,6 +22,11 @@
] ]
} }
}, },
{
"type": "assignment_operator",
"named": true,
"fields": {}
},
{ {
"type": "async", "type": "async",
"named": true, "named": true,
@ -29,6 +34,21 @@
"children": { "children": {
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [
{
"type": "block",
"named": true
}
]
}
},
{
"type": "block",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [ "types": [
{ {
"type": "statement", "type": "statement",
@ -51,7 +71,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "statement", "type": "block",
"named": true "named": true
} }
] ]
@ -66,11 +86,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "block",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "expression",
"named": true "named": true
} }
] ]
@ -144,7 +164,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "statement", "type": "block",
"named": true "named": true
} }
] ]
@ -169,6 +189,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -176,10 +200,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -197,6 +217,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -204,10 +228,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -221,11 +241,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "block",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "identifier",
"named": true "named": true
} }
] ]
@ -259,11 +279,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "block",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "expression",
"named": true "named": true
} }
] ]
@ -365,6 +385,11 @@
] ]
} }
}, },
{
"type": "logic_operator",
"named": true,
"fields": {}
},
{ {
"type": "map", "type": "map",
"named": true, "named": true,
@ -393,11 +418,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "block",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "expression",
"named": true "named": true
} }
] ]
@ -422,6 +447,11 @@
] ]
} }
}, },
{
"type": "math_operator",
"named": true,
"fields": {}
},
{ {
"type": "reduce", "type": "reduce",
"named": true, "named": true,
@ -430,6 +460,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -437,10 +471,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -453,6 +483,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -460,10 +494,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -477,7 +507,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "statement", "type": "block",
"named": true "named": true
} }
] ]
@ -491,6 +521,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -498,10 +532,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -511,7 +541,7 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{ {
@ -615,6 +645,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "block",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -622,10 +656,6 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "statement",
"named": true
} }
] ]
} }
@ -682,16 +712,28 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "block",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "expression",
"named": true "named": true
} }
] ]
} }
}, },
{
"type": "!=",
"named": false
},
{
"type": "%",
"named": false
},
{
"type": "&&",
"named": false
},
{ {
"type": "(", "type": "(",
"named": false "named": false
@ -700,14 +742,38 @@
"type": ")", "type": ")",
"named": false "named": false
}, },
{
"type": "*",
"named": false
},
{
"type": "+",
"named": false
},
{
"type": "+=",
"named": false
},
{ {
"type": ",", "type": ",",
"named": false "named": false
}, },
{
"type": "-",
"named": false
},
{
"type": "-=",
"named": false
},
{ {
"type": "..", "type": "..",
"named": false "named": false
}, },
{
"type": "/",
"named": false
},
{ {
"type": ":", "type": ":",
"named": false "named": false
@ -716,10 +782,18 @@
"type": "<", "type": "<",
"named": false "named": false
}, },
{
"type": "<=",
"named": false
},
{ {
"type": "=", "type": "=",
"named": false "named": false
}, },
{
"type": "==",
"named": false
},
{ {
"type": "=>", "type": "=>",
"named": false "named": false
@ -728,6 +802,10 @@
"type": ">", "type": ">",
"named": false "named": false
}, },
{
"type": ">=",
"named": false
},
{ {
"type": "[", "type": "[",
"named": false "named": false
@ -748,10 +826,6 @@
"type": "assert_equal", "type": "assert_equal",
"named": false "named": false
}, },
{
"type": "assignment_operator",
"named": true
},
{ {
"type": "async", "type": "async",
"named": false "named": false
@ -840,18 +914,10 @@
"type": "length", "type": "length",
"named": false "named": false
}, },
{
"type": "logic_operator",
"named": true
},
{ {
"type": "match", "type": "match",
"named": false "named": false
}, },
{
"type": "math_operator",
"named": true
},
{ {
"type": "metadata", "type": "metadata",
"named": false "named": false
@ -972,6 +1038,10 @@
"type": "{", "type": "{",
"named": false "named": false
}, },
{
"type": "||",
"named": false
},
{ {
"type": "}", "type": "}",
"named": false "named": false

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `dust -c '(length (from_json input))' -p seaCreatures.json` | 2.9 ± 0.4 | 2.5 | 6.7 | 1.00 |
| `jq 'length' seaCreatures.json` | 36.7 ± 4.4 | 34.7 | 65.0 | 12.59 ± 2.14 |
| `node --eval "require('node:fs').readFile('seaCreatures.json', (err, data)=>{console.log(JSON.parse(data).length)})"` | 241.2 ± 13.3 | 227.7 | 273.2 | 82.63 ± 11.00 |
| `nu -c 'open seaCreatures.json \| length'` | 54.0 ± 3.3 | 50.3 | 69.2 | 18.49 ± 2.51 |
| `dust -c '(length (from_json input))' -p jq_data.json` | 7.9 ± 0.8 | 6.6 | 12.5 | 2.70 ± 0.43 |
| `jq 'length' jq_data.json` | 44.8 ± 0.6 | 43.5 | 47.3 | 15.36 ± 1.87 |
| `node --eval "require('node:fs').readFile('jq_data.json', (err, data)=>{console.log(JSON.parse(data).length)})"` | 245.2 ± 7.1 | 235.4 | 259.7 | 84.00 ± 10.46 |
| `nu -c 'open jq_data.json \| length'` | 65.9 ± 5.0 | 62.0 | 90.5 | 22.57 ± 3.22 |
| `dust -c '(length (from_json input))' -p dielectron.json` | 1079.5 ± 22.7 | 1043.8 | 1121.5 | 369.86 ± 45.46 |
| `jq 'length' dielectron.json` | 1365.0 ± 20.3 | 1318.5 | 1400.1 | 467.67 ± 57.07 |
| `node --eval "require('node:fs').readFile('dielectron.json', (err, data)=>{console.log(JSON.parse(data).length)})"` | 1910.8 ± 47.9 | 1855.9 | 1985.7 | 654.66 ± 80.97 |
| `nu -c 'open dielectron.json \| length'` | 2001.2 ± 65.1 | 1923.2 | 2112.7 | 685.65 ± 85.98 |