4 ms·
> Anyone have a suggestion for an alternative to YAML that's easier to write by hand than JSON and also supports nested declarations? ("XML with a fancy text ed
by lelanthran 3y ago
> Anyone have a suggestion for an alternative to YAML that's easier to write by hand than JSON and also supports nested declarations? ("XML with a fancy text editor" doesn't count)
S-expressions. A parser for s-expressions (with no evaluation) can be as small as 300 lines of C code.
It'd take a day to write, and can express everything in a way that:
1. Current IDEs and code-editors can semantic-highlight
2. Current IDEs and code-editors can auto-format
Add in builtins for setting/getting symbols, and you can also DRY your config with variables and functions.
[EDIT: The DRY is optional - if you don't want someone messing up configs down the line, then don't implement any builtins that modify the symbol table, just examine the tree in your program after you have read in the s-expressions.]
- xigoi 3y agoS-expressions don't have associative arrays (maps/dicts/objects), which are very important for config.
- lelanthran 3y agoS-expressions don't have anything. They can represent almost everything, though. Composite data types, nested objects, alists, lists, trees, tables... With only a few primitive additions, you should be able to represent everything, except for bidirectional cyclic graphs.
- mbakke 3y agoBut then you have to evaluate things, which brings all kinds of problems. Your parser is no longer 300 lines, and eventually you might snap and throw it all away for a full-blown interpreter which makes dealing with user provided input difficult. I'm actually investigating using S-expressions for describing jobs and systems, but haven't figured out how to safely evaluate them short of running in isolated VMs. Edit: thinking more about this, it is possible to represent all those things without evaluation. It's just awkward to create them... but that can be solved on a different level.
- waffletower 3y agoThere is a discussion above regarding EDN, which supports S-expressions, has maps, sets, and vectors (JSON style collection syntax []). I think it could be an excellent replacement for YAML in some important use cases, but it is lacking for representing inline, non-Lisp code and heredocs.