Clean up; Fix read function
This commit is contained in:
parent
9b53485519
commit
60ba9853ed
@ -2,7 +2,7 @@
|
|||||||
name = "dust-lang"
|
name = "dust-lang"
|
||||||
description = "Data-Oriented Programming Language"
|
description = "Data-Oriented Programming Language"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
repository = "https://github.com/tree-sitter/tree-sitter-dust"
|
repository = "https://git.jeffa.io/jeff/dust.git"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
@ -10,6 +10,11 @@ license = "MIT"
|
|||||||
name = "dust"
|
name = "dust"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
async-std = { version = "1.12.0", features = ["attributes"] }
|
async-std = { version = "1.12.0", features = ["attributes"] }
|
||||||
|
@ -31,7 +31,7 @@ pub enum BuiltInFunction {
|
|||||||
Append(Vec<Expression>),
|
Append(Vec<Expression>),
|
||||||
Metadata(Expression),
|
Metadata(Expression),
|
||||||
Move(Vec<Expression>),
|
Move(Vec<Expression>),
|
||||||
Read(Expression),
|
Read(Option<Expression>),
|
||||||
Remove(Expression),
|
Remove(Expression),
|
||||||
Write(Vec<Expression>),
|
Write(Vec<Expression>),
|
||||||
|
|
||||||
@ -155,8 +155,11 @@ impl AbstractTree for BuiltInFunction {
|
|||||||
BuiltInFunction::Move(expressions)
|
BuiltInFunction::Move(expressions)
|
||||||
}
|
}
|
||||||
"read" => {
|
"read" => {
|
||||||
let expression_node = node.child(1).unwrap();
|
let expression = if let Some(node) = node.child(1) {
|
||||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
Some(Expression::from_syntax_node(source, node)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
BuiltInFunction::Read(expression)
|
BuiltInFunction::Read(expression)
|
||||||
}
|
}
|
||||||
@ -431,8 +434,13 @@ impl AbstractTree for BuiltInFunction {
|
|||||||
Ok(Value::Empty)
|
Ok(Value::Empty)
|
||||||
}
|
}
|
||||||
BuiltInFunction::Read(expression) => {
|
BuiltInFunction::Read(expression) => {
|
||||||
|
let path = if let Some(expression) = expression {
|
||||||
let path_value = expression.run(source, context)?;
|
let path_value = expression.run(source, context)?;
|
||||||
let path = PathBuf::from(path_value.as_string()?);
|
|
||||||
|
PathBuf::from(path_value.as_string()?)
|
||||||
|
} else {
|
||||||
|
PathBuf::from(".")
|
||||||
|
};
|
||||||
let content = if path.is_dir() {
|
let content = if path.is_dir() {
|
||||||
let dir = read_dir(&path)?;
|
let dir = read_dir(&path)?;
|
||||||
let mut contents = Vec::new();
|
let mut contents = Vec::new();
|
||||||
|
@ -264,7 +264,7 @@ module.exports = grammar({
|
|||||||
field('body', $.block),
|
field('body', $.block),
|
||||||
),
|
),
|
||||||
|
|
||||||
function_call: $ => prec.right(seq(
|
function_call: $ => prec.right(1, seq(
|
||||||
'(',
|
'(',
|
||||||
choice(
|
choice(
|
||||||
$.built_in_function,
|
$.built_in_function,
|
||||||
|
@ -1108,7 +1108,7 @@
|
|||||||
},
|
},
|
||||||
"function_call": {
|
"function_call": {
|
||||||
"type": "PREC_RIGHT",
|
"type": "PREC_RIGHT",
|
||||||
"value": 0,
|
"value": 1,
|
||||||
"content": {
|
"content": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
Loading…
Reference in New Issue
Block a user