Re: Add ".git/config" file parser
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Oct 10, 2005, 22:12 UTC
- Message-ID
- <Pine.LNX.4.64.0510101456570.14597@g5.osdl.org>
- In-Reply-To
- <434AE209.60605@zytor.com>
On Mon, 10 Oct 2005, H. Peter Anvin wrote:
Show 5 quoted lines
> > A suggestion: if you make your basic types (integer, string, boolean) > recognizable by the parser, you can present them in that way. This pretty > much means strings will have to always be double-quoted, but that avoids a > bunch of ambiguities.
Well, the parser is already pretty unambiguous, purely by virtue of being stupid as hell.
In particular, the only thing quoting does is to actually make whitespace meaningful, and as a way to allow comments inside strings (otherwise a "#" or ";" is always a "comment starts here" marker).
Outside of quotes, any whitespace will just collapse to a single space (and be removed from beginning and end).
And quite frankly, always keeping the things as strings just makes things so much easier and the interfaces very simple. And if/when you want to turn the string into a boolean or a regular integer, there are two helper functions that do exactly that, so it's not very hard.
I considered using some "smart" parser (ie using something like flex/bison), but the thing is, I didn't want smart. I personally think it's a lot more important for the file format to be _nice_, and there I think it's fine if
[diff] external=/usr/local/bin/gnu-diff
doesn't need quotes, even if it's obviously a string. Simplicity is a virtue (both in parsing and in the "language" parsed).
In fact, even the example I had - with a space and an argument - doesn't need quotes (since the single space will be collapsed to a single space), I just put that as an example.
Side note: the design is meant to allow different programs to share the same config file without having to know about each others config variables. Anything they don't recognize is just ignored. The downside is that if you mistype an option name, nobody will recognize it, and nobody will complain either.
That was one of the reasons for the "scoping". It not only allows grouping of variables, but it means that the "git-diff-xyz" family of programs might decide that they'll report anything that starts with "diff." but that they don't understand as a warning (but preferably not error, since it might be a newer option that an older version of git just doesn't understand).
Linus