Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A83 Add chain modifiers for function invocations #55

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}