Skip to content

Commit

Permalink
Merge pull request #55 from Ph0enixKM/A83
Browse files Browse the repository at this point in the history
A83 Add chain modifiers for function invocations
  • Loading branch information
Ph0enixKM committed Mar 31, 2023
2 parents b709a88 + e46c8b7 commit e159da2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ jobs:
run: cargo build --verbose
- name: Run validity tests
run: cargo test validity --verbose
- name: Run performance tests
run: cargo test performance --verbose
6 changes: 3 additions & 3 deletions src/modules/command/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl SyntaxModule<ParserMetadata> for CommandModifier {
swap(&mut self.is_unsafe, &mut meta.context.is_unsafe_ctx);
if self.is_expr {
syntax(meta, &mut *self.expr)?;
if !matches!(self.expr.value, Some(ExprType::CommandExpr(_))) {
return error!(meta, tok, format!("Expected command expression, after '{sequence}' command modifiers."));
if !matches!(self.expr.value, Some(ExprType::CommandExpr(_) | ExprType::FunctionInvocation(_))) {
return error!(meta, tok, format!("Expected command or function call, after '{sequence}' command modifiers."));
}
} else {
match token(meta, "{") {
Expand All @@ -104,7 +104,7 @@ impl SyntaxModule<ParserMetadata> for CommandModifier {

impl TranslateModule for CommandModifier {
fn translate(&self, meta: &mut TranslateMetadata) -> String {
meta.silenced = true;
meta.silenced = self.is_silent;
let result = if self.is_expr {
return self.expr.translate(meta)
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/condition/failed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils::metadata::{ParserMetadata, TranslateMetadata};

#[derive(Debug, Clone)]
pub struct Failed {
is_parsed: bool,
pub is_parsed: bool,
is_question_mark: bool,
is_main: bool,
block: Box<Block>
Expand All @@ -27,6 +27,8 @@ impl SyntaxModule<ParserMetadata> for Failed {
fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult {
let tok = meta.get_current_token();
if meta.context.is_unsafe_ctx {
self.is_main = meta.context.is_main_ctx;
self.is_parsed = true;
return Ok(());
}
if let Ok(_) = token(meta, "?") {
Expand Down
37 changes: 37 additions & 0 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,4 +779,41 @@ fn chained_modifiers() {
silent unsafe $non-existant command$
";
test_amber!(code, "Hello World");
}

#[test]
fn chained_modifiers_commands() {
let code = "
unsafe silent {
echo 'Hello World'
$non-existant command$
}
// Test for expression
let _ = silent unsafe $non-existant command$
// Test for single statement
silent unsafe $non-existant command$
";
test_amber!(code, "Hello World");
}

#[test]
fn chained_modifiers_functions() {
let code = "
fun foo(a) {
echo a
fail 1
}
fun bar() {
echo 'this should not appear'
}
unsafe foo('one')
unsafe {
foo('two')
}
unsafe silent foo('this should not appear')
silent bar()
";
test_amber!(code, "one\ntwo");
}

0 comments on commit e159da2

Please sign in to comment.