1
0

Improve index parsing

This commit is contained in:
Jeff 2023-12-31 21:46:45 -05:00
parent 5be7b9b73a
commit 346ff1c0da
8 changed files with 14548 additions and 13173 deletions

View File

@ -19,7 +19,12 @@ impl AbstractTree for FunctionExpression {
fn from_syntax_node(source: &str, node: Node, context: &Map) -> Result<Self> {
Error::expect_syntax_node(source, "function_expression", node)?;
let child = node.child(0).unwrap();
let first_child = node.child(0).unwrap();
let child = if first_child.is_named() {
first_child
} else {
node.child(1).unwrap()
};
let function_expression = match child.kind() {
"identifier" => FunctionExpression::Identifier(Identifier::from_syntax_node(

View File

@ -94,7 +94,7 @@ impl AbstractTree for Index {
Type::List(item_type) => Ok(*item_type.clone()),
Type::Map => Ok(Type::Any),
Type::None => Ok(Type::None),
_ => todo!(),
r#type => Ok(r#type),
}
}
}

View File

@ -15,7 +15,7 @@ impl BuiltInFunction for Std {
Error::expect_argument_amount(self, 0, arguments.len())?;
let std_context = STD.get_or_init(|| {
let std_source = "say_hi = () <none> { output(hi) }";
let std_source = "say_hi = () <none> { output('hi') }";
let std_context = Map::new();
interpret_with_context(std_source, std_context.clone()).unwrap();

View File

@ -3,7 +3,6 @@
//!
//! Using this library is simple and straightforward, see the [inferface] module for instructions on
//! interpreting Dust code. Most of the language's features are implemented in the [tools] module.
pub use crate::{
abstract_tree::*,
built_in_functions::{BuiltInFunction, BUILT_IN_FUNCTIONS},

View File

@ -338,17 +338,29 @@ mod index {
}
#[test]
fn complex_index() {
let test = interpret(
fn index_function_calls() {
assert_eq!(
interpret(
"
x = [1 2 3]
y = () <int> { 2 }
x:y()
",
)
.unwrap();
),
Ok(Value::Integer(3))
);
assert_eq!(Value::Integer(3), test);
assert_eq!(
interpret(
"
x = {
y = () <int> { 2 }
}
(x:y)()
",
),
Ok(Value::Integer(2))
);
}
}

View File

@ -200,7 +200,7 @@ module.exports = grammar({
index: $ =>
prec.left(
2,
1,
seq(
$.expression,
':',
@ -377,6 +377,16 @@ module.exports = grammar({
),
function_expression: $ =>
choice(
$._function_expression_kind,
seq(
'(',
$._function_expression_kind,
')',
),
),
_function_expression_kind: $ =>
prec(
1,
choice(
@ -387,7 +397,6 @@ module.exports = grammar({
$.yield,
),
),
function_call: $ =>
prec.right(
seq(

View File

@ -599,7 +599,7 @@
},
"index": {
"type": "PREC_LEFT",
"value": 2,
"value": 1,
"content": {
"type": "SEQ",
"members": [
@ -1231,6 +1231,32 @@
]
},
"function_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_function_expression_kind"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_function_expression_kind"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_function_expression_kind": {
"type": "PREC",
"value": 1,
"content": {

File diff suppressed because it is too large Load Diff