Why don’t you use an existing file format instead of rolling your own? TOML is built into Julia, but there are also other (JSON, YAML, etc). Otherwise those packages could be inspirations for you.
I want to use an external program which takes this kind of format as an input. The parser would help with reusing/modifying the already existing files, which are quite long.
I’ll take a look at the mentioned projects. Let’s see if I can find some common strategy, which I can reuse.
You may find Lerche useful. It reads an EBNF for your grammar to create a parser. Rules provided by you for traversing and transforming the resultant parse tree are then applied. Lerche is only version 0.1 but the API is designed to match the Lark API so it shouldn’t change.
There are certainly opportunities for speed improvement in Lerche. As a workaround, you can see from the linked project that it is possible to simply serialise the generated parser.