-
-
Notifications
You must be signed in to change notification settings - Fork 5
A syntax analysis problem #3
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
Comments
Hi @lutzmad, thank you for reporting.
Unfortunately ksh cannot support. This is ksh limitation. Parsing shell script code is very difficult. In fact, ShellMetrics does very few code parsing. Supported shells has built in code formatter. I don't think it was made as a code formatter, but when display defined function, it will be formatted. $ bash -c 'foo() { case a in (*) echo ok; esac }; typeset -f foo'
foo ()
{
case a in
*)
echo ok
;;
esac
} Using this technique greatly reduces the code patterns to be analyzed. However, ksh displays defined function as is it. $ ksh -c 'foo() { case a in (*) echo ok; esac }; typeset -f foo'
foo() { case a in (*) echo ok; esac }; To support ksh, we need true shell script parser. There seem to be some parsers, but I haven't tried them. By the way, I think the syntax of ksh is almost the same as bash, so I think you can parse it using bash. Do you know the ksh syntax that bash cannot parse? I would like to know that syntax.
ShellSpec and ShellMetrics is targeted POSIX compliant shells. It cannot be supported because the syntax of csh and tcsh is very different. And I am not familiar with csh and tcsh.
Oh. It is a bashism (kshism) I forgot. There is also
ShellMetrics does not support styles like https://blog.feabhas.com/2018/07/code-quality-cyclomatic-complexity/ lizard has
We need some more research is needed before making any changes. I think first example ( $ bash -c 'foo() { case a in a|b) :; esac; echo "a|b)"; }; typeset -f foo'
foo ()
{
case a in
a | b)
:
;;
esac;
echo "a|b)"
} Second example (
|
Hello Koichi Nakashima,
You are right, I use the bash mode of shellspec and shellmetrics to check my ksh scripts. This works well in general. As long as the bash 4 is available. Thanks for your nice tools, p.s. |
Hello,
nice tool, works well with AIX 7.2.1.4 and bash 4.3.30.
The shellmetrics 0.5.0 tool pass all your tests, after I changed all "run script" statements to "run" (I use shellspec 0.20.2).
Unfortunately my favorit shell, the "ksh", is not supported today. On the other hand shellspec and shellmetrics does not support "csh" or "tcsh" also.
I do some tests based of my scripts, the calculated value seems to be correct. But sometimes your syntax analysis will not fit.
On the other hand, the number of pathes are not counted well for some "if" statements also.
In a short form, nice tool.
The most other tools I know are not able to handle concatenated "if" or "case" terms and the old McCabe samples does not count the number of all pathes also, in these circumstances.
But you should add ";&" to your list of closeing statements, like the ";;", this is available in the bash also (but used only in "ksh" mostly).
A nice tool to give me some useful information to prepare new tests.
With regards,
Lutz
The text was updated successfully, but these errors were encountered: