1
0

Refine command implementation; Add tests

This commit is contained in:
Jeff 2024-01-29 18:17:50 -05:00
parent df5cf93e58
commit 0752ebedf2
9 changed files with 23918 additions and 24635 deletions

View File

@ -0,0 +1,17 @@
async {
{
*echo 'Starting 1...'
*sleep 1
*echo 'Finished 1.'
}
{
*echo 'Starting 2...'
*sleep 2
*echo 'Finished 2.'
}
{
*echo 'Starting 3...'
*sleep 3
*echo 'Finished 3.'
}
}

View File

@ -206,7 +206,7 @@ impl StarshipPrompt {
let right_prompt = if let Ok(output) = &run_starship_right { let right_prompt = if let Ok(output) = &run_starship_right {
String::from_utf8_lossy(&output.stdout).trim().to_string() String::from_utf8_lossy(&output.stdout).trim().to_string()
} else { } else {
">".to_string() "".to_string()
}; };
self.left = left_prompt; self.left = left_prompt;

20
tests/commands.rs Normal file
View File

@ -0,0 +1,20 @@
use dust_lang::{interpret, Value};
use std::fs::{remove_file, write};
#[test]
fn simple_command() {
assert_eq!(interpret("^echo hi"), Ok(Value::String("".to_string())))
}
#[test]
fn assign_command_output() {
write("target/test.txt", "123").unwrap();
assert_eq!(
interpret("x = ^cat target/test.txt; x"),
Ok(Value::String("123".to_string()))
);
remove_file("target/test.txt").unwrap();
}

View File

@ -2,7 +2,7 @@
Simple Command Simple Command
================================================================================ ================================================================================
*ls ^ls
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -16,7 +16,7 @@ Simple Command
Command Sequence Command Sequence
================================================================================ ================================================================================
*less *ls ^less ^ls
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -34,7 +34,7 @@ Command Sequence
Command with Arguments Command with Arguments
================================================================================ ================================================================================
*ls --long -a ^ls --long -a
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -50,8 +50,8 @@ Command with Arguments
Command Sequence with Arguments Command Sequence with Arguments
================================================================================ ================================================================================
*cargo run -- -c "output('hi there')" ^cargo run -- -c "output('hi there')"
*ls --long -a ^ls --long -a
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -70,3 +70,126 @@ Command Sequence with Arguments
(command_text) (command_text)
(command_argument) (command_argument)
(command_argument))))) (command_argument)))))
================================================================================
Command Sequence with Arguments
================================================================================
^cargo run -- -c "output('hi there')"
^ls --long -a
--------------------------------------------------------------------------------
(root
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)
(command_argument)
(command_argument))))
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)))))
================================================================================
Command Assignment
================================================================================
ls_output = ^ls --long -a;
cat_output = ^cat Cargo.toml;
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)))))))
================================================================================
Command with Semicolon
================================================================================
ls_output = ^ls --long -a; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(expression
(identifier))))
================================================================================
Command with Semicolon
================================================================================
ls_output = ^ls --long -a; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(expression
(identifier))))
================================================================================
Command with Quoted Semicolon
================================================================================
ls_output = ^echo ';'; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument))))))
(statement
(expression
(identifier))))

View File

@ -2,7 +2,7 @@
Simple Command Pipe Simple Command Pipe
================================================================================ ================================================================================
*ls | *less ^ls | ^less
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -85,7 +85,7 @@ module.exports = grammar({
command: $ => command: $ =>
prec.right( prec.right(
seq( seq(
'*', '^',
$.command_text, $.command_text,
repeat($.command_argument), repeat($.command_argument),
), ),
@ -95,7 +95,7 @@ module.exports = grammar({
command_argument: $ => command_argument: $ =>
choice( choice(
/[^*\s]+/, /[^^|;\s]+/,
/("[^"]*?")|('[^']*?')|(`[^`]*?`)/, /("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
), ),

View File

@ -233,7 +233,7 @@
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "*" "value": "^"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -258,7 +258,7 @@
"members": [ "members": [
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "[^*\\s]+" "value": "[^^|;\\s]+"
}, },
{ {
"type": "PATTERN", "type": "PATTERN",

View File

@ -885,6 +885,10 @@
"type": "]", "type": "]",
"named": false "named": false
}, },
{
"type": "^",
"named": false
},
{ {
"type": "any", "type": "any",
"named": false "named": false
@ -935,11 +939,11 @@
}, },
{ {
"type": "float", "type": "float",
"named": false "named": true
}, },
{ {
"type": "float", "type": "float",
"named": true "named": false
}, },
{ {
"type": "for", "type": "for",

File diff suppressed because it is too large Load Diff