Maybe it could be done with an island grammar, sort of similar to the way RATFOR (PDF, 80.8 KB) preprocessor worked:
The Ratfor grammar is simple and straightforward, being essentially
prog : stat | prog stat stat : if (...) stat | if (...) stat else stat | while (...) stat | for (...; ...; ...) stat | do ... stat | repeat stat | repeat stat until (...) | switch (...) | { case ...: prog ... default: prog } | return | break | next | digits stat | { prog } | anything unrecognizableThe observation that Ratfor knows no Fortran follows directly from the rule that says a statement is
‘‘anything unrecognizable’’. In fact most of Fortran falls into this category, since any statement that does not begin with one of the keywords is by definition ‘‘unrecognizable.’’
There are several more features which are needed:
- automating help message generation with flag descriptions
- customizing the usage message
- implementing sub-commands (like
githas) (somehow similar to entry statements) - short flags / flag aliases
There are also Python packages like click, which accomplish the same thing using Python’s function decorator mechanism. I bet we could find more examples.