YEs, another configuration language
A whitespace-sensitive configuration language and data format.
Seriously, how many configuration languages do we have? From the top of my head, I can only name:
Hmmm... that's it I think. wE NeEd MOrE cOnfIGURaTion LanGuaGEs!!1!1!!
I originally based this off of the Ruby/DSL for homebrew formulas.
Here are my complaints for the alternatives:
- JSON, while simple, isn't too readable and only has the bear minimum of datatypes. That may be a feature for some people, though.
- YAML is dangerous. And unpredictable.
- INI and TOML are quite similar and they both are quite nice with a lot of datatypes but, in my opinion, the format isn't as natural to read as YAML. TOML supports dates and datetime, though.
- Finally, XML is garbage. It's barely human-readable and can decode into a super wonky format. So no.
Finally, I just wanted an excuse to play with Lark.
- Enums with a built-in resolver
- Date time and Date support
- YAML-like syntax
- Support for comments, unicode escape sequences, string modifications, and cleanly managed indented strings
Given this modcfg document:
module hello_world:
hello => world
this: "also works"
'single quotes' = "equals double quotes"
how -> {
about: {
some:
- very
- crazy
- data:
structures = o_0
}
}
and this python script:
import modcfg
modcfg.loads(DOC) # `DOC` is the document above
The output is
[
Module(
name="hello_world",
contents=[
{
"hello": "world",
"this": "also works",
"single quotes": "equals double quotes",
"how": {
"about": {
"some": ["very", "crazy", {"data": {"structures": "o_0"}}]
}
},
}
],
)
]
Crazy, right? It gets better with enums and date(time)s... You might as well read the whole documentation.
$ pip install modcfg
The classic method:
$ git clone https://github.com/ThatXliner/modcfg.git
$ cd modcfg
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -e .
The best method (requires Poetry):
$ git clone https://github.com/ThatXliner/modcfg.git
$ cd modcfg
$ poetry install
Lark is epic.
Modular Configuration language.