Open SimonKagstrom opened 8 years ago
This might be of use to you: https://github.com/mvdan/sh
It's not written in C/C++, but I believe it is possible to build a Go package as a C shared library and call it from most languages. For example: https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf
The binary also has a json output flag, which might help bring the barrier down:
$ cat foo.sh
echo foo bar # comment
$ shfmt -exp.tojson <foo.sh
<AST as a JSON object>
Thanks! Will look into it.
I think the approach go for if using your project is to dlopen
it and use it if it exists, otherwise fall back to the current version. Is it buildable as a shared library?
(I should note that I know nothing about go)
Is it buildable as a shared library?
Yes, that is what you can do with Go. Google "golang shared library" and you'll find plenty of guides and blog posts.
You could either optionally depend on the shared library, or optionally depend on the shfmt
binary for the JSON exporting I showed above. Perhaps the latter would make it easier for both you and the user.
Hi @SimonKagstrom , I really appreciate your work with kcov! I have started using it recently and has proven to be a great tool for Bash testing coverage combined with Shellspec. Would it be possible for you to provide some details about the plans for fixing the parsing issues?
I don't have any concrete plans for fixing this. The library mvdan mentioned above could be a way to do this, but otherwise it would be a major undertaking
What I did was to provide a more basic parsing mode instead, which can be enabled using
kcov --configure=bash-use-basic-parser=1 [...]
which gives more false hits, but is also more resilient against going astray as the standard parser can sometimes do.
The current parser is quite uncapable, so some constructions will lead it astray. A proper shell script parser is needed for this to work better.