From 60ba9853edaaa3cdcacf12358d8c10d3de0c54dc Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 20 Nov 2023 12:49:20 -0500 Subject: [PATCH] Clean up; Fix read function --- Cargo.toml | 7 ++++++- src/abstract_tree/built_in_function.rs | 18 +++++++++++++----- tree-sitter-dust/grammar.js | 2 +- tree-sitter-dust/src/grammar.json | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 033c1ab..312fbc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "dust-lang" description = "Data-Oriented Programming Language" version = "0.3.5" -repository = "https://github.com/tree-sitter/tree-sitter-dust" +repository = "https://git.jeffa.io/jeff/dust.git" edition = "2021" license = "MIT" @@ -10,6 +10,11 @@ license = "MIT" name = "dust" path = "src/main.rs" +[profile.dev] +opt-level = 1 +[profile.dev.package."*"] +opt-level = 3 + [dependencies] ansi_term = "0.12.1" async-std = { version = "1.12.0", features = ["attributes"] } diff --git a/src/abstract_tree/built_in_function.rs b/src/abstract_tree/built_in_function.rs index 43fe7c1..2d8ce99 100644 --- a/src/abstract_tree/built_in_function.rs +++ b/src/abstract_tree/built_in_function.rs @@ -31,7 +31,7 @@ pub enum BuiltInFunction { Append(Vec), Metadata(Expression), Move(Vec), - Read(Expression), + Read(Option), Remove(Expression), Write(Vec), @@ -155,8 +155,11 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::Move(expressions) } "read" => { - let expression_node = node.child(1).unwrap(); - let expression = Expression::from_syntax_node(source, expression_node)?; + let expression = if let Some(node) = node.child(1) { + Some(Expression::from_syntax_node(source, node)?) + } else { + None + }; BuiltInFunction::Read(expression) } @@ -431,8 +434,13 @@ impl AbstractTree for BuiltInFunction { Ok(Value::Empty) } BuiltInFunction::Read(expression) => { - let path_value = expression.run(source, context)?; - let path = PathBuf::from(path_value.as_string()?); + let path = if let Some(expression) = expression { + let path_value = expression.run(source, context)?; + + PathBuf::from(path_value.as_string()?) + } else { + PathBuf::from(".") + }; let content = if path.is_dir() { let dir = read_dir(&path)?; let mut contents = Vec::new(); diff --git a/tree-sitter-dust/grammar.js b/tree-sitter-dust/grammar.js index ff98969..3d03f65 100644 --- a/tree-sitter-dust/grammar.js +++ b/tree-sitter-dust/grammar.js @@ -264,7 +264,7 @@ module.exports = grammar({ field('body', $.block), ), - function_call: $ => prec.right(seq( + function_call: $ => prec.right(1, seq( '(', choice( $.built_in_function, diff --git a/tree-sitter-dust/src/grammar.json b/tree-sitter-dust/src/grammar.json index 142d727..1dacf47 100644 --- a/tree-sitter-dust/src/grammar.json +++ b/tree-sitter-dust/src/grammar.json @@ -1108,7 +1108,7 @@ }, "function_call": { "type": "PREC_RIGHT", - "value": 0, + "value": 1, "content": { "type": "SEQ", "members": [