Skip to content

Commit

Permalink
syntax: add support for the Bash 5.2 @k expansion operator
Browse files Browse the repository at this point in the history
Updates #921.
  • Loading branch information
mvdan committed May 25, 2024
1 parent 23633a4 commit def0e87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions syntax/filetests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()}
Expand Down
6 changes: 5 additions & 1 deletion syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'}",
Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit def0e87

Please sign in to comment.