Skip to content

Commit e159da2

Browse files
authored
Merge pull request #55 from Ph0enixKM/A83
A83 Add chain modifiers for function invocations
2 parents b709a88 + e46c8b7 commit e159da2

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

.github/workflows/rust.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ jobs:
1818
run: cargo build --verbose
1919
- name: Run validity tests
2020
run: cargo test validity --verbose
21-
- name: Run performance tests
22-
run: cargo test performance --verbose

src/modules/command/modifier.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl SyntaxModule<ParserMetadata> for CommandModifier {
8181
swap(&mut self.is_unsafe, &mut meta.context.is_unsafe_ctx);
8282
if self.is_expr {
8383
syntax(meta, &mut *self.expr)?;
84-
if !matches!(self.expr.value, Some(ExprType::CommandExpr(_))) {
85-
return error!(meta, tok, format!("Expected command expression, after '{sequence}' command modifiers."));
84+
if !matches!(self.expr.value, Some(ExprType::CommandExpr(_) | ExprType::FunctionInvocation(_))) {
85+
return error!(meta, tok, format!("Expected command or function call, after '{sequence}' command modifiers."));
8686
}
8787
} else {
8888
match token(meta, "{") {
@@ -104,7 +104,7 @@ impl SyntaxModule<ParserMetadata> for CommandModifier {
104104

105105
impl TranslateModule for CommandModifier {
106106
fn translate(&self, meta: &mut TranslateMetadata) -> String {
107-
meta.silenced = true;
107+
meta.silenced = self.is_silent;
108108
let result = if self.is_expr {
109109
return self.expr.translate(meta)
110110
} else {

src/modules/condition/failed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::utils::metadata::{ParserMetadata, TranslateMetadata};
66

77
#[derive(Debug, Clone)]
88
pub struct Failed {
9-
is_parsed: bool,
9+
pub is_parsed: bool,
1010
is_question_mark: bool,
1111
is_main: bool,
1212
block: Box<Block>
@@ -27,6 +27,8 @@ impl SyntaxModule<ParserMetadata> for Failed {
2727
fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult {
2828
let tok = meta.get_current_token();
2929
if meta.context.is_unsafe_ctx {
30+
self.is_main = meta.context.is_main_ctx;
31+
self.is_parsed = true;
3032
return Ok(());
3133
}
3234
if let Ok(_) = token(meta, "?") {

src/tests/validity.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,41 @@ fn chained_modifiers() {
779779
silent unsafe $non-existant command$
780780
";
781781
test_amber!(code, "Hello World");
782+
}
783+
784+
#[test]
785+
fn chained_modifiers_commands() {
786+
let code = "
787+
unsafe silent {
788+
echo 'Hello World'
789+
$non-existant command$
790+
}
791+
// Test for expression
792+
let _ = silent unsafe $non-existant command$
793+
// Test for single statement
794+
silent unsafe $non-existant command$
795+
";
796+
test_amber!(code, "Hello World");
797+
}
798+
799+
#[test]
800+
fn chained_modifiers_functions() {
801+
let code = "
802+
fun foo(a) {
803+
echo a
804+
fail 1
805+
}
806+
807+
fun bar() {
808+
echo 'this should not appear'
809+
}
810+
811+
unsafe foo('one')
812+
unsafe {
813+
foo('two')
814+
}
815+
unsafe silent foo('this should not appear')
816+
silent bar()
817+
";
818+
test_amber!(code, "one\ntwo");
782819
}

0 commit comments

Comments
 (0)