Clean up; Fix read function
This commit is contained in:
parent
9b53485519
commit
60ba9853ed
@ -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"] }
|
||||
|
@ -31,7 +31,7 @@ pub enum BuiltInFunction {
|
||||
Append(Vec<Expression>),
|
||||
Metadata(Expression),
|
||||
Move(Vec<Expression>),
|
||||
Read(Expression),
|
||||
Read(Option<Expression>),
|
||||
Remove(Expression),
|
||||
Write(Vec<Expression>),
|
||||
|
||||
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -1108,7 +1108,7 @@
|
||||
},
|
||||
"function_call": {
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 0,
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
Loading…
Reference in New Issue
Block a user