-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
syntax: got "}" can only be used to close a block
on a seemingly normal block
#739
Comments
Apparently, the "bug(?)" has to do with the "at" sign ( $ shfmt
=() {
echo "$@"
}
= Hello world\!
=() {
echo "$@"
}
= Hello world\!
$ |
Found a workaround (I just love the internet...): $ shfmt
@()
{
echo "$@"
}
@ Hello world\!
@()
{
echo "$@"
}
@ Hello world\! I'm still not sure why |
Interestingly, it's not only the "at" sign ( $ for i in @ + - = , ^; do echo; echo __ $i __; echo "$i() { echo yay; }" | shfmt; echo; done
__ @ __
<standard input>:1:17: "}" can only be used to close a block
__ + __
<standard input>:1:17: "}" can only be used to close a block
__ - __
-() { echo yay; }
__ = __
=() { echo yay; }
__ , __
,() { echo yay; }
__ ^ __
^() { echo yay; }
|
Thanks for the report! This might be a bug in the parser. I'd be happy to review a patch if you're up for looking into it :) |
"}" can only be used to close a block
on a seemingly normal block"}" can only be used to close a block
on a seemingly normal block
Actually, I'm not. The only reason I use this tool is because I'm forced to. One clear and present danger with tools like this is that they are often misused |
I'm not sure how to answer to that, so I won't :) |
I'll take a look at this @mvdan :) |
Sounds good! |
the lexer assumes an extglob token if any of the wildcards expressions (such as `@`, and `+`) are succeeded by a left parenthesis but that proves to be an issue if the wildcard is used as a function name. example input: ``` $ cat in.sh @() { echo "$@"; } ``` `bash` and `gosh` comparison: ``` $ bash ./in.sh hello $ ./gosh in.sh in.sh:5:1: "}" can only be used to close a block ``` given `in.sh`, gosh reports about a syntax error - this is because a closing bracket is found while the lexer doesn't assume a function block fix the issue by assuming a function if: * if the expression is found at the beginning of the statement or if its preceded by a "function" * if `(` is immediately succeeded by a `)` - although this is a valid bash syntax, we'll operate on the likelihood that it is a function fixes mvdan#739
the lexer assumes an extglob token if any of the wildcards expressions (such as `@`, and `+`) are succeeded by a left parenthesis but that proves to be an issue if the wildcard is used as a function name. example input: ``` $ cat in.sh @() { echo "$@"; } ``` `bash` and `gosh` comparison: ``` $ bash ./in.sh hello $ ./gosh in.sh in.sh:5:1: "}" can only be used to close a block ``` given `in.sh`, gosh reports about a syntax error - this is because a closing bracket is found while the lexer isn't assuming a function block fix the issue by assuming a function if one of the conditions below is true: * if the expression is found at the beginning of the statement or if its preceded by a "function" * if `(` is immediately succeeded by a `)` - although this is a valid bash syntax, we'll operate on the likelihood that it is a function fixes mvdan#739
the lexer assumes an extglob token if any of the wildcards expressions (such as `@`, and `+`) are succeeded by a left parenthesis but that proves to be an issue if the wildcard is used as a function name. example input: ``` $ cat in.sh @() { echo "$@"; } ``` `bash` and `gosh` comparison: ``` $ bash ./in.sh hello $ ./gosh in.sh in.sh:5:1: "}" can only be used to close a block ``` given `in.sh`, gosh reports about a syntax error - this is because a closing bracket is found while the lexer isn't assuming a function block fix the issue by assuming a function if one of the conditions below is true: * if the expression is found at the beginning of the statement or if its preceded by a "function" * if `(` is immediately succeeded by a `)` - although this is a valid bash syntax, we'll operate on the likelihood that it is a function fixes mvdan#739
the lexer assumes an extglob token if any of the wildcards expressions (such as `@`, and `+`) are succeeded by a left parenthesis but that proves to be an issue if the wildcard is used as a function name. example input: ``` $ cat in.sh @() { echo "$@"; } ``` `bash` and `gosh` comparison: ``` $ bash ./in.sh hello $ ./gosh in.sh in.sh:5:1: "}" can only be used to close a block ``` given `in.sh`, gosh reports about a syntax error - this is because a closing bracket is found while the lexer isn't assuming a function block fix the issue by assuming a function if one of the conditions below is true: * if the expression is found at the beginning of the statement or if its preceded by a "function" * if `(` is immediately succeeded by a `)` - although this is a valid bash syntax, we'll operate on the likelihood that it is a function fixes mvdan#739
the lexer assumes an extglob token if any of the wildcards expressions (such as `@`, and `+`) are succeeded by a left parenthesis but that proves to be an issue if the wildcard is used as a function name. example input: ``` $ cat in.sh @() { echo "$@"; } ``` `bash` and `gosh` comparison: ``` $ bash ./in.sh hello $ ./gosh in.sh in.sh:5:1: "}" can only be used to close a block ``` given `in.sh`, gosh reports about a syntax error - this is because a closing bracket is found while the lexer isn't assuming a function block fix the issue by assuming a function if one of the conditions below is true: * if the expression is found at the beginning of the statement or if its preceded by a "function" * if `(` is immediately succeeded by a `)` - although this is a valid bash syntax, we'll operate on the likelihood that it is a function fixes #739
I'm struggling to understand what's wrong with this sample:
The text was updated successfully, but these errors were encountered: