I wrote a script the other day for a nontechnical team and I thought I'd replace the cryptic command-line flags with a command that reads more like a sentence.
I came up with a command line along the lines of:
<script.sh> run tests for <module> ... in <language> ...
The keyword "for" introduces a list of modules, whereas "in" introduces a list of languages. ("in" may itself become a language code in the future, as an aside.)
The way I parse this is by defining its high-level structure as a . If + = "run tests", I kick in specific parsing looking for the "for" and "in" keywords.
Next, I wanted to change the syntax to:
<script.sh> run <module> ... tests in <language> ...
In my opinion, this reads better.
I have the skill to make this work with handcrafted Bash argument parsing, but the complexity of that would be overkill IMO. An alternative could be Lex/Yacc: the script could write temporary Lex+Yacc scripts and use them to parse its command line. That also seems overkill.
Is there a good, straightforward way to define a simple context-free grammar that can be used to parse command lines like the above into variables? I'm happy to hear starting points rather than full-fledged solutions.