bash-parser
bash-parser copied to clipboard
Add full support for comments
Currently comments are removed and do not show up in the AST. For certain use cases (e.g. building a converter from bash to win batch scripts) it'd be useful to have the comments as specific AST elements.
Comments are usually only preserved in the concrete syntax tree, and get stripped before producing an AST. I don't think preserving comments should be a goal of this project; we really only want an AST so we can then execute the command in vorpaljs/cash. Preserving comments and whitespace are huge headaches.
https://github.com/nfischer/shelljs-transpiler is a similar project with basic support for comments, although I know there's good chunks of bash missing from that grammar (mainly because that project has to parse and transpile, which slows down progress a bit).
Comments can be consider like any other token... Main problem with them, they can appear everywhere.
What about shebang? #!/usr/bin/node If comments are stripped this at least should be preserved.