1
0

Simplify grammar structure

This commit is contained in:
Jeff 2023-11-10 20:44:03 -05:00
parent 71c169a1cf
commit f0fb16607c
31 changed files with 29020 additions and 85617 deletions

View File

@ -1,42 +0,0 @@
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use tree_sitter::Node;
use crate::{AbstractTree, Block, Map, Result, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Async {
block: Block,
}
impl AbstractTree for Async {
fn from_syntax_node(source: &str, node: Node) -> Result<Self> {
debug_assert_eq!("async", node.kind());
let block_node = node.child(1).unwrap();
let block = Block::from_syntax_node(source, block_node)?;
Ok(Async { block })
}
fn run(&self, source: &str, context: &mut Map) -> Result<Value> {
let statements = self.block.statements();
statements
.into_par_iter()
.enumerate()
.find_map_first(|(index, statement)| {
let mut context = context.clone();
let result = statement.run(source, &mut context);
if result.is_err() {
Some(result)
} else if index == statements.len() - 1 {
Some(result)
} else {
None
}
})
.unwrap_or(Ok(Value::Empty))
}
}

View File

@ -1,27 +1,26 @@
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use tree_sitter::Node;
use crate::{AbstractTree, Result, Statement};
use crate::{AbstractTree, Result, Statement, Value};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Block {
pub statements: Vec<Statement>,
}
impl Block {
pub fn statements(&self) -> &Vec<Statement> {
&self.statements
}
is_async: bool,
statements: Vec<Statement>,
}
impl AbstractTree for Block {
fn from_syntax_node(source: &str, node: Node) -> Result<Self> {
debug_assert_eq!("block", node.kind());
let first_child = node.child(0).unwrap();
let is_async = first_child.kind() == "async";
let statement_count = node.child_count();
let mut statements = Vec::with_capacity(statement_count);
for index in 0..statement_count {
for index in 0..statement_count - 1 {
let child_node = node.child(index).unwrap();
if child_node.kind() == "statement" {
@ -30,10 +29,33 @@ impl AbstractTree for Block {
}
}
Ok(Block { statements })
Ok(Block {
is_async,
statements,
})
}
fn run(&self, source: &str, context: &mut crate::Map) -> crate::Result<crate::Value> {
if self.is_async {
let statements = &self.statements;
statements
.into_par_iter()
.enumerate()
.find_map_first(|(index, statement)| {
let mut context = context.clone();
let result = statement.run(source, &mut context);
if result.is_err() {
Some(result)
} else if index == statements.len() - 1 {
Some(result)
} else {
None
}
})
.unwrap_or(Ok(Value::Empty))
} else {
for statement in &self.statements[0..self.statements.len() - 1] {
statement.run(source, context)?;
}
@ -44,3 +66,4 @@ impl AbstractTree for Block {
Ok(final_value)
}
}
}

View File

@ -50,13 +50,13 @@ impl AbstractTree for Index {
Ok(item)
}
Value::Map(map) => {
Value::Map(mut map) => {
let value = if let Expression::Identifier(identifier) = &self.index {
let key = identifier.inner();
map.variables()?.get(key).cloned().unwrap_or(Value::Empty)
} else {
let value = self.index.run(source, context)?;
let value = self.index.run(source, &mut map)?;
let key = value.as_string()?;
map.variables()?.get(key).cloned().unwrap_or(Value::Empty)
@ -96,7 +96,7 @@ mod tests {
#[test]
fn evaluate_complex_index() {
let test = evaluate("{x = [1 2 3]; y = || => {0}; x:((y));}").unwrap();
let test = evaluate("x = [1 2 3]; y = || => {0}; x:((y));").unwrap();
assert_eq!(Value::Integer(1), test);
}

View File

@ -7,7 +7,6 @@
//! examples.
pub mod assignment;
pub mod r#async;
pub mod block;
pub mod built_in_function;
pub mod expression;
@ -31,9 +30,8 @@ pub mod r#while;
pub use {
assignment::*, block::*, built_in_function::*, expression::*, filter::*, find::*,
function_call::*, identifier::*, if_else::*, index::*, insert::*, logic::*, math::*,
r#async::*, r#for::*, r#match::*, r#while::*, remove::*, select::*, statement::*, transform::*,
value_node::*,
function_call::*, identifier::*, if_else::*, index::*, insert::*, logic::*, math::*, r#for::*,
r#match::*, r#while::*, remove::*, select::*, statement::*, transform::*, value_node::*,
};
use tree_sitter::Node;

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use tree_sitter::Node;
use crate::{
AbstractTree, Assignment, Async, Error, Expression, Filter, Find, For, IfElse, Insert, Map,
AbstractTree, Assignment, Block, Error, Expression, Filter, Find, For, IfElse, Insert, Map,
Match, Remove, Result, Select, Transform, Value, While,
};
@ -17,7 +17,7 @@ pub enum Statement {
IfElse(Box<IfElse>),
Match(Match),
While(Box<While>),
Async(Box<Async>),
Block(Box<Block>),
For(Box<For>),
Transform(Box<Transform>),
Filter(Box<Filter>),
@ -49,7 +49,7 @@ impl AbstractTree for Statement {
"while" => Ok(Statement::While(Box::new(While::from_syntax_node(
source, child,
)?))),
"async" => Ok(Statement::Async(Box::new(Async::from_syntax_node(
"block" => Ok(Statement::Block(Box::new(Block::from_syntax_node(
source, child,
)?))),
"for" => Ok(Statement::For(Box::new(For::from_syntax_node(
@ -89,7 +89,7 @@ impl AbstractTree for Statement {
Statement::IfElse(if_else) => if_else.run(source, context),
Statement::Match(r#match) => r#match.run(source, context),
Statement::While(r#while) => r#while.run(source, context),
Statement::Async(run) => run.run(source, context),
Statement::Block(block) => block.run(source, context),
Statement::For(r#for) => r#for.run(source, context),
Statement::Transform(transform) => transform.run(source, context),
Statement::Filter(filter) => filter.run(source, context),

View File

@ -6,7 +6,7 @@ use std::fmt::{self, Debug, Formatter};
use tree_sitter::{Parser, Tree as TSTree};
use crate::{language, AbstractTree, Block, Map, Result, Value};
use crate::{language, AbstractTree, Map, Result, Statement, Value};
/// Evaluate the given source code.
///
@ -89,9 +89,9 @@ impl<'context, 'code> Evaluator<'context, 'code> {
let root_node = cursor.node();
let mut prev_result = Ok(Value::Empty);
for block_node in root_node.children(&mut cursor) {
let block = Block::from_syntax_node(self.source, block_node)?;
prev_result = block.run(self.source, self.context);
for statement_node in root_node.children(&mut cursor) {
let statement = Statement::from_syntax_node(self.source, statement_node)?;
prev_result = statement.run(self.source, self.context);
}
prev_result
@ -227,7 +227,7 @@ mod tests {
}
#[test]
fn evaluate_if_else_else_if_else_if_else_if_else() {
fn evaluate_if_else_if_else_if_else_if_else() {
assert_eq!(
evaluate(
"
@ -253,7 +253,7 @@ mod tests {
assert_eq!(
evaluate(
"
foobar = |message| => message
foobar = |message| => { message }
(foobar 'Hiya')
",
),

View File

@ -1,13 +1,12 @@
==================
================================================================================
Simple Async Statements
==================
================================================================================
async { (output 'Whaddup') }
---
--------------------------------------------------------------------------------
(root
(block
(statement
(async
(block
@ -17,11 +16,11 @@ async { (output 'Whaddup') }
(built_in_function
(expression
(value
(string))))))))))))
(string)))))))))))
==================
================================================================================
Complex Async Statements
==================
================================================================================
async {
if 1 % 2 == 0 {
@ -33,10 +32,9 @@ async {
'foobar'
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(async
(block
@ -72,4 +70,4 @@ async {
(statement
(expression
(value
(string)))))))))
(string))))))))

View File

@ -1,32 +1,30 @@
==================
================================================================================
Simple Function Call
==================
================================================================================
(output 'hi')
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(function_call
(built_in_function
(expression
(value
(string)))))))))
(string))))))))
==================
================================================================================
Nested Function Call
==================
================================================================================
(assert_equal (random_integer) 4)
assert_equal random_integer 4
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(function_call
@ -46,4 +44,4 @@ assert_equal random_integer 4
(built_in_function
(expression
(value
(integer))))))))))))
(integer)))))))))))

View File

@ -8,10 +8,9 @@ not_a_comment
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(identifier)))))
(identifier))))
================================================================================
Partial Line Comments
@ -22,10 +21,9 @@ not_a_comment # comment
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(identifier)))))
(identifier))))
================================================================================
Multiline Comments
@ -38,11 +36,10 @@ not_a_comment #
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(identifier)))
(statement
(expression
(value
(string))))))
(string)))))

View File

@ -1,15 +1,14 @@
==================
================================================================================
Simple Filter Loop
==================
================================================================================
filter i in [1, 2, 3] {
i <= 1
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(filter
(identifier)
@ -34,11 +33,11 @@ filter i in [1, 2, 3] {
(logic_operator)
(expression
(value
(integer)))))))))))
(integer))))))))))
==================
================================================================================
Nested Filter Loop
==================
================================================================================
filter i in big_list {
filter j in i {
@ -46,10 +45,9 @@ filter i in big_list {
}
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(filter
(identifier)
@ -70,4 +68,4 @@ filter i in big_list {
(logic_operator)
(expression
(value
(integer))))))))))))))
(integer)))))))))))))

View File

@ -9,7 +9,6 @@ find i in [1, 2, 3] {
--------------------------------------------------------------------------------
(root
(block
(statement
(find
(identifier)
@ -34,7 +33,7 @@ find i in [1, 2, 3] {
(logic_operator)
(expression
(value
(integer)))))))))))
(integer))))))))))
================================================================================
Nested Find Loop
@ -56,7 +55,6 @@ find i in ["one", "two", "three"] {
--------------------------------------------------------------------------------
(root
(block
(statement
(find
(identifier)
@ -116,4 +114,4 @@ find i in ["one", "two", "three"] {
(statement
(expression
(value
(boolean)))))))))))))
(boolean))))))))))))

View File

@ -2,12 +2,13 @@
Simple For Loop
================================================================================
for i in [1, 2, 3] output i
for i in [1, 2, 3] {
output i
}
--------------------------------------------------------------------------------
(root
(block
(statement
(for
(identifier)
@ -29,18 +30,21 @@ for i in [1, 2, 3] output i
(function_call
(built_in_function
(expression
(identifier)))))))))))
(identifier))))))))))
================================================================================
Nested For Loop
================================================================================
for list in list_of_lists for item in list output item
for list in list_of_lists {
for item in list {
(output item)
}
}
--------------------------------------------------------------------------------
(root
(block
(statement
(for
(identifier)
@ -58,4 +62,4 @@ for list in list_of_lists for item in list output item
(function_call
(built_in_function
(expression
(identifier))))))))))))))
(identifier)))))))))))))

View File

@ -2,12 +2,11 @@
Simple Function
================================================================================
=> "Hiya"
=> { "Hiya" }
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -16,18 +15,17 @@ Simple Function
(statement
(expression
(value
(string)))))))))))
(string))))))))))
================================================================================
Function Assignment
================================================================================
x = => "Hiya"
x = => { "Hiya" }
--------------------------------------------------------------------------------
(root
(block
(statement
(assignment
(identifier)
@ -40,7 +38,7 @@ x = => "Hiya"
(statement
(expression
(value
(string)))))))))))))
(string))))))))))))
================================================================================
Function Call
@ -51,14 +49,13 @@ Function Call
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(function_call
(identifier)
(expression
(value
(string))))))))
(string)))))))
================================================================================
Complex Function
@ -72,7 +69,6 @@ Complex Function
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -92,7 +88,7 @@ Complex Function
(function_call
(built_in_function
(expression
(identifier)))))))))))))
(identifier))))))))))))
================================================================================
Complex Function Call
@ -110,7 +106,6 @@ Complex Function Call
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(function_call
@ -133,4 +128,4 @@ Complex Function Call
(statement
(expression
(value
(integer))))))))))))
(integer)))))))))))

View File

@ -1,15 +1,14 @@
==================
================================================================================
Simple Identifiers
==================
================================================================================
x
_y
__xyz__
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(identifier)))
@ -18,4 +17,4 @@ __xyz__
(identifier)))
(statement
(expression
(identifier)))))
(identifier))))

View File

@ -1,13 +1,12 @@
==================
================================================================================
Simple If
==================
================================================================================
if true { "True" }
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -18,18 +17,17 @@ if true { "True" }
(statement
(expression
(value
(string))))))))))
(string)))))))))
==================
================================================================================
Complex If
==================
================================================================================
if 1 == 1 && 2 == 2 && 3 == 3 "True"
if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -70,22 +68,23 @@ if 1 == 1 && 2 == 2 && 3 == 3 "True"
(statement
(expression
(value
(string))))))))))
(string)))))))))
==================
================================================================================
Nested If
==================
================================================================================
if true
if 42 == 12
if true {
if 42 == 12 {
'hiya'
else
} else {
'bye'
}
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -115,18 +114,17 @@ if true
(statement
(expression
(value
(string))))))))))))))
(string)))))))))))))
==================
================================================================================
If Else
==================
================================================================================
if false "True" else "False"
if false { "True" } else { "False" }
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -143,11 +141,11 @@ if false "True" else "False"
(statement
(expression
(value
(string))))))))))
(string)))))))))
==================
================================================================================
If Else If
==================
================================================================================
if 1 == 1 {
"math is fun"
@ -155,10 +153,9 @@ if 1 == 1 {
"math is broken"
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -190,25 +187,25 @@ if 1 == 1 {
(statement
(expression
(value
(string))))))))))
(string)))))))))
==================
================================================================================
If Else Else If Else
==================
================================================================================
if false
if false {
"no"
else if false
} else if false {
"no"
else if 1 + 1 == 9
} else if 1 + 1 == 9 {
"not the answer"
else
} else {
"42"
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(if_else
(if
@ -255,4 +252,4 @@ else
(statement
(expression
(value
(string))))))))))
(string)))))))))

View File

@ -1,6 +1,6 @@
==================
================================================================================
Simple Indexes
==================
================================================================================
dust_data:1:name
@ -8,10 +8,9 @@ creature:total_clams
foobar:1:42
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(index
@ -43,18 +42,17 @@ foobar:1:42
(integer)))))
(expression
(value
(integer))))))))
(integer)))))))
==================
================================================================================
Nested Indexes
==================
================================================================================
[['answers' 'foobar'], 42, 666]:0:1:0..2
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(index
@ -91,4 +89,4 @@ Nested Indexes
(integer)))
(expression
(value
(integer))))))))
(integer)))))))

View File

@ -1,13 +1,12 @@
==================
================================================================================
List Declaration
==================
================================================================================
['answer', 42]
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -17,18 +16,17 @@ List Declaration
(string)))
(expression
(value
(integer)))))))))
(integer))))))))
==================
================================================================================
List Nesting
==================
================================================================================
['answers', [42, [666]]]
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -47,4 +45,4 @@ List Nesting
(list
(expression
(value
(integer)))))))))))))))
(integer))))))))))))))

View File

@ -1,26 +1,26 @@
==================
================================================================================
Simple Map
==================
================================================================================
{ answer = 42 }
---
--------------------------------------------------------------------------------
(root
(statement
(block
(statement
(expression
(value
(map
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(integer))))))))))
(integer)))))))))
==================
================================================================================
Nested Maps
==================
================================================================================
x = {
y = {
@ -32,19 +32,19 @@ x = {
f = 12
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(map
(block
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
@ -63,9 +63,12 @@ x = {
(statement
(expression
(value
(string))))))))))))
(string))))))))))))))
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(integer))))))))))))
(integer)))))))))))

View File

@ -1,13 +1,12 @@
==================
================================================================================
\==
==================
================================================================================
3 == 1 + 1 + 1
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(logic
@ -29,18 +28,17 @@
(math_operator)
(expression
(value
(integer))))))))))
(integer)))))))))
==================
================================================================================
&&
==================
================================================================================
4 + 2 == 42 && true
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(logic
@ -62,18 +60,17 @@
(logic_operator)
(expression
(value
(boolean))))))))))
(boolean)))))))))
==================
================================================================================
\||
==================
================================================================================
4 + 2 == 42 || true
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(logic
@ -95,4 +92,4 @@
(logic_operator)
(expression
(value
(boolean))))))))))
(boolean)))))))))

View File

@ -1,15 +1,14 @@
==================
================================================================================
Simple Reduce Loop
==================
================================================================================
reduce i to acc in [1, 2, 3] {
acc += i
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(reduce
(identifier)
@ -33,20 +32,19 @@ reduce i to acc in [1, 2, 3] {
(assignment_operator)
(statement
(expression
(identifier))))))))))
(identifier)))))))))
==================
================================================================================
Nested Reduce Loop
==================
================================================================================
reduce i to acc in ["one", "two", "three"] {
acc += i
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(reduce
(identifier)
@ -70,4 +68,4 @@ reduce i to acc in ["one", "two", "three"] {
(assignment_operator)
(statement
(expression
(identifier))))))))))
(identifier)))))))))

View File

@ -1,15 +1,14 @@
==================
================================================================================
Simple Remove
==================
================================================================================
remove i from [1, 2, 3] {
i <= 2
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(remove
(identifier)
@ -34,11 +33,11 @@ remove i from [1, 2, 3] {
(logic_operator)
(expression
(value
(integer)))))))))))
(integer))))))))))
==================
================================================================================
Nested Remove
==================
================================================================================
remove i from big_list {
remove j from i {
@ -46,10 +45,9 @@ remove i from big_list {
}
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(remove
(identifier)
@ -70,4 +68,4 @@ remove i from big_list {
(logic_operator)
(expression
(value
(integer))))))))))))))
(integer)))))))))))))

View File

@ -1,15 +1,14 @@
==================
================================================================================
Simple Statements
==================
================================================================================
1
"one";
x
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -20,19 +19,18 @@ x
(string))))
(statement
(expression
(identifier)))))
(identifier))))
==================
================================================================================
Simple Assignment
==================
================================================================================
x = 1;
y = "one"
---
--------------------------------------------------------------------------------
(root
(block
(statement
(assignment
(identifier)
@ -48,11 +46,11 @@ y = "one"
(statement
(expression
(value
(string))))))))
(string)))))))
==================
================================================================================
Complex Assignment
==================
================================================================================
x = if 1 + 1 == 2 {
'yo'
@ -60,10 +58,9 @@ x = if 1 + 1 == 2 {
'no'
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(assignment
(identifier)
@ -96,18 +93,17 @@ x = if 1 + 1 == 2 {
(statement
(expression
(value
(string))))))))))))
(string)))))))))))
==================
================================================================================
Expression Precedence
==================
================================================================================
x = 3 == 1 + 2 + 2
---
--------------------------------------------------------------------------------
(root
(block
(statement
(assignment
(identifier)
@ -133,4 +129,4 @@ x = 3 == 1 + 2 + 2
(math_operator)
(expression
(value
(integer))))))))))))
(integer)))))))))))

View File

@ -1,6 +1,6 @@
==================
================================================================================
Table Declaration
==================
================================================================================
table |messages numbers| [
['hiya' 42]
@ -8,10 +8,9 @@ table |messages numbers| [
['bar' 99.99]
]
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -48,20 +47,19 @@ table |messages numbers| [
(string)))
(expression
(value
(float)))))))))))))))
(float))))))))))))))
==================
================================================================================
Table Access
==================
================================================================================
select |number| from foobar {
text == 'answer'
}
---
--------------------------------------------------------------------------------
(root
(block
(statement
(select
(identifier_list
@ -77,20 +75,19 @@ select |number| from foobar {
(logic_operator)
(expression
(value
(string)))))))))))
(string))))))))))
==================
================================================================================
Table Insert
==================
================================================================================
insert into foobar [
['bob was here', 0]
]
---
--------------------------------------------------------------------------------
(root
(block
(statement
(insert
(identifier)
@ -105,4 +102,4 @@ insert into foobar [
(string)))
(expression
(value
(integer)))))))))))))
(integer))))))))))))

View File

@ -9,7 +9,6 @@ transform i in [1, 2, 3] {
--------------------------------------------------------------------------------
(root
(block
(statement
(transform
(identifier)
@ -31,7 +30,7 @@ transform i in [1, 2, 3] {
(function_call
(built_in_function
(expression
(identifier)))))))))))
(identifier))))))))))
================================================================================
Nested Transform Loop
@ -46,7 +45,6 @@ transform i in [['one'] ['two'] ['three']] {
--------------------------------------------------------------------------------
(root
(block
(statement
(transform
(identifier)
@ -85,4 +83,4 @@ transform i in [['one'] ['two'] ['three']] {
(statement
(expression
(value
(string))))))))))))))
(string)))))))))))))

View File

@ -1,14 +1,13 @@
==================
================================================================================
Booleans
==================
================================================================================
true
false
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -16,19 +15,18 @@ false
(statement
(expression
(value
(boolean))))))
(boolean)))))
==================
================================================================================
Integers
==================
================================================================================
1 2 3
456 7
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -48,18 +46,17 @@ Integers
(statement
(expression
(value
(integer))))))
(integer)))))
==================
================================================================================
Strings
==================
================================================================================
"one" 'two' "three" `four` 'five'
---
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(value
@ -79,4 +76,4 @@ Strings
(statement
(expression
(value
(string))))))
(string)))))

View File

@ -9,7 +9,6 @@ while true {
--------------------------------------------------------------------------------
(root
(block
(statement
(while
(expression
@ -22,7 +21,7 @@ while true {
(built_in_function
(expression
(value
(string))))))))))))
(string)))))))))))
================================================================================
Nested While Loop
@ -37,7 +36,6 @@ while (true) {
--------------------------------------------------------------------------------
(root
(block
(statement
(while
(expression
@ -62,4 +60,4 @@ while (true) {
(statement
(expression
(value
(integer))))))))))))))
(integer)))))))))))))

View File

@ -7,7 +7,6 @@ Simple Yield
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(yield
@ -15,7 +14,7 @@ Simple Yield
(value
(integer)))
(function_call
(built_in_function)))))))
(built_in_function))))))
================================================================================
Long Yield
@ -30,7 +29,6 @@ Long Yield
--------------------------------------------------------------------------------
(root
(block
(statement
(expression
(yield
@ -59,4 +57,4 @@ Long Yield
(function_call
(identifier))))
(function_call
(built_in_function)))))))
(built_in_function))))))

View File

@ -10,19 +10,21 @@ module.exports = grammar({
],
rules: {
root: $ => repeat1($.block),
root: $ => prec(1, repeat1($.statement)),
_comment: $ => /[#][^#\n]*[#|\n]/,
block: $ => prec.right(choice(
block: $ => seq(
optional('async'),
'{',
repeat1($.statement),
seq('{', repeat1($.statement), '}'),
)),
'}',
),
statement: $ => prec.right(seq(
choice(
$.assignment,
$.async,
$.block,
$.expression,
$.filter,
$.find,
@ -268,11 +270,6 @@ module.exports = grammar({
$.expression,
)),
async: $ => seq(
'async',
$.block,
),
identifier_list: $ => prec.right(choice(
seq(
'|',

View File

@ -3,10 +3,14 @@
"word": "identifier",
"rules": {
"root": {
"type": "PREC",
"value": 1,
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "block"
"name": "statement"
}
}
},
"_comment": {
@ -14,19 +18,6 @@
"value": "[#][^#\\n]*[#|\\n]"
},
"block": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "statement"
}
},
{
"type": "SEQ",
"members": [
{
@ -45,9 +36,6 @@
"value": "}"
}
]
}
]
}
},
"statement": {
"type": "PREC_RIGHT",
@ -66,6 +54,10 @@
"type": "SYMBOL",
"name": "async"
},
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "SYMBOL",
"name": "expression"

View File

@ -538,7 +538,7 @@
"required": true,
"types": [
{
"type": "block",
"type": "statement",
"named": true
}
]
@ -583,6 +583,10 @@
"type": "async",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "expression",
"named": true

File diff suppressed because it is too large Load Diff