vorpaljs / bash-parser

Parses bash into an AST
https://vorpaljs.github.io/bash-parser-playground/
MIT License
200 stars 34 forks source link

Add full support for comments #62

Open daniel-sc opened 5 years ago

daniel-sc commented 5 years ago

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.

nfischer commented 5 years ago

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).

piranna commented 5 years ago

Comments can be consider like any other token... Main problem with them, they can appear everywhere.

jcubic commented 3 years ago

What about shebang? #!/usr/bin/node If comments are stripped this at least should be preserved.