From def0e87227f8620c84e995d96ee3b65c69e9733e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 25 May 2024 14:24:34 +0100 Subject: [PATCH] syntax: add support for the Bash 5.2 @k expansion operator Updates #921. --- syntax/filetests_test.go | 19 +++++++++++++++++++ syntax/parser.go | 4 ++-- syntax/parser_test.go | 6 +++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/syntax/filetests_test.go b/syntax/filetests_test.go index 2848e77e..b225f799 100644 --- a/syntax/filetests_test.go +++ b/syntax/filetests_test.go @@ -2557,6 +2557,25 @@ var fileTests = []testCase{ }), ), }, + { + Strs: []string{`${a@K} ${b@k}`}, + bash: call( + word(&ParamExp{ + Param: lit("a"), + Exp: &Expansion{ + Op: OtherParamOps, + Word: litWord("K"), + }, + }), + word(&ParamExp{ + Param: lit("b"), + Exp: &Expansion{ + Op: OtherParamOps, + Word: litWord("a"), + }, + }), + ), + }, { Strs: []string{`${a@Q} ${b@#}`}, mksh: call( diff --git a/syntax/parser.go b/syntax/parser.go index d39336bc..59a45b18 100644 --- a/syntax/parser.go +++ b/syntax/parser.go @@ -1375,7 +1375,7 @@ func (p *Parser) paramExpExp() *Expansion { p.curErr("@ expansion operator requires a literal") } switch p.val { - case "a", "u", "A", "E", "K", "L", "P", "U": + case "a", "k", "u", "A", "E", "K", "L", "P", "U": if !p.lang.isBash() { p.langErr(p.pos, "this expansion operator", LangBash) } @@ -1385,7 +1385,7 @@ func (p *Parser) paramExpExp() *Expansion { } case "Q": default: - p.curErr("invalid @ expansion operator") + p.curErr("invalid @ expansion operator %q", p.val) } } return &Expansion{Op: op, Word: p.getWord()} diff --git a/syntax/parser_test.go b/syntax/parser_test.go index 6137680d..ecfe6c97 100644 --- a/syntax/parser_test.go +++ b/syntax/parser_test.go @@ -1798,7 +1798,7 @@ var shellTests = []errorCase{ }, { in: "echo ${foo@bar}", - bash: `1:12: invalid @ expansion operator #NOERR at runtime`, + bash: `1:12: invalid @ expansion operator "bar" #NOERR at runtime`, }, { in: "echo ${foo@'Q'}", @@ -1961,6 +1961,10 @@ var shellTests = []errorCase{ in: "echo ${foo@K}", mksh: `1:12: this expansion operator is a bash feature`, }, + { + in: "echo ${foo@k}", + mksh: `1:12: this expansion operator is a bash feature`, + }, { in: "echo ${foo@L}", mksh: `1:12: this expansion operator is a bash feature`,