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

parser: figure out what to do about bash's extended globbing #37

Closed
mvdan opened this issue Oct 19, 2016 · 1 comment
Closed

parser: figure out what to do about bash's extended globbing #37

mvdan opened this issue Oct 19, 2016 · 1 comment
Labels

Comments

@mvdan
Copy link
Owner

mvdan commented Oct 19, 2016

If bash's extended globbing is on, some programs are suddenly valid:

shopt -s extglob

echo foo@(bar)

Normally, this fails as ( is a token:

 $ echo 'echo @(foo)' | bash
bash: line 1: syntax error near unexpected token `('
bash: line 1: `echo @(foo)'
 $ echo 'echo @(foo)' | shfmt
1:7: a command can only contain words and redirects

I see two possible options:

  • Change the behaviour of the parser whenever a shopt statement is parsed (ugh)
  • Always parse extended globbing stuff in the bash mode

The first option would make the parser even more complex, as it would change behaviour not only depending on the context, but also depending on what statements it has parsed.

The second option is somewhat cleaner, but I see some minor disadvantages:

  • Some invalid bash programs will be accepted (which is okay for shfmt)
  • If this parser is ever used for anything serious, another package (like an interpreter/executor) would have to take care of erroring if it finds an extended globbing node when not in extglob mode
@mvdan mvdan added the bash label Oct 19, 2016
@mvdan
Copy link
Owner Author

mvdan commented Oct 24, 2016

I went for the latter, which is the only option that doesn't make us understand shopt and otherwise evaluate the program.

See 3917ecf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant