digitalmars.D - Has anyone written an INI parser in tango?
- Rayne (1/1) Sep 11 2008 Just wondering if anyone had because it doesnt seen that the creators of...
- Anyone (4/5) Sep 11 2008 Check out this:
- Jarrett Billingsley (2/7) Sep 11 2008 Clever reply!
- Manfred_Nowak (15/16) Sep 11 2008 To the contrary:
- Chris R. Miller (10/11) Sep 11 2008 I wrote sort of a half-ini parser a while back. It doesn't support ini
- Rayne (2/18) Sep 11 2008 Awesome Yes it does help, thank's
- Bill Baxter (5/6) Sep 11 2008 Is there some reason you are really set on using a crappy format like in...
- Rayne (2/11) Sep 11 2008 Yep, I do actually. But it looks like I don't have a choice.
- Chris R. Miller (9/13) Sep 11 2008 What's so bad about ini?
- Bill Baxter (14/27) Sep 12 2008 It's not hierarchical.
- Chris R. Miller (16/46) Sep 12 2008 You could emulate that with headers like:
- Jesse Phillips (3/9) Sep 12 2008 Ummm, isn't that what an ini file is? I assume it is not a .d file, as
- Bill Baxter (13/22) Sep 12 2008 There are also the [section] thingys in an ini file.
- David Wilson (7/21) Sep 12 2008 I've always thought that was a benefit rather than a hinderence. It's
- Walter Bright (56/59) Sep 12 2008 Here's a simple one I wrote a while back. A description of the file
- Rayne (2/76) Sep 12 2008 Thanks for the effort, however as it turns out I was being an idiot, I f...
- Janderson (6/83) Sep 13 2008 I know this has been solved but I'd like to point out that windows
- Stewart Gordon (17/20) Oct 17 2008 Are you looking for an INI parser in the first place, or are you seeing
Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.
Sep 11 2008
Rayne Wrote:Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Check out this:
Sep 11 2008
On Fri, Sep 12, 2008 at 12:11 AM, Anyone <anyone mail.com> wrote:Rayne Wrote:Clever reply!Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Check out this:
Sep 11 2008
Jarrett Billingsley wrote:Clever reply!To the contrary: | Even good conversationalists sometimes find themselves in | situations where the conversation is just not going the way they | want it to. This book provides techniques to help you better | direct and control the conversation at such times. (ISBN-13: | 978-0684868011, page 14f) Hints to ISBN-13: 978-0684868011 are not among those techniques. Ummm---a hint, that some technique is not described in ISBN-13: 978- 0684868011 is in it neither---we successfully opened ISBN-10: 0470065532 ISBN-13: 978-0470065532 :-) -manfred -- If life is going to exist in this Universe, then the one thing it cannot afford to have is a sense of proportion. (Douglas Adams)
Sep 11 2008
Rayne wrote:Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.I wrote sort of a half-ini parser a while back. It doesn't support ini headers, but you could probably write that in relatively easily. Pretty web version: http://www.fsdev.net/repositories/entry/tick/trunk/tick/server/Conf.d Direct source download: http://svn.fsdev.net/tick/trunk/server/Conf.d It's GPLv3, but if you need a more flexible license consider this my dual-licensing for that one file under whatever license you want (IOTW BSD). Hope that helps you some.
Sep 11 2008
Chris R. Miller Wrote:Rayne wrote:Awesome Yes it does help, thank'sJust wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.I wrote sort of a half-ini parser a while back. It doesn't support ini headers, but you could probably write that in relatively easily. Pretty web version: http://www.fsdev.net/repositories/entry/tick/trunk/tick/server/Conf.d Direct source download: http://svn.fsdev.net/tick/trunk/server/Conf.d It's GPLv3, but if you need a more flexible license consider this my dual-licensing for that one file under whatever license you want (IOTW BSD). Hope that helps you some.
Sep 11 2008
On Fri, Sep 12, 2008 at 9:38 AM, Rayne <DiscipleRayne gmail.com> wrote:Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Is there some reason you are really set on using a crappy format like ini? There are several decent JSON parsers. I've been using the one from Cashew. Tango has one now too I think. --bb
Sep 11 2008
Bill Baxter Wrote:On Fri, Sep 12, 2008 at 9:38 AM, Rayne <DiscipleRayne gmail.com> wrote:Yep, I do actually. But it looks like I don't have a choice.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Is there some reason you are really set on using a crappy format like ini? There are several decent JSON parsers. I've been using the one from Cashew. Tango has one now too I think. --bb
Sep 11 2008
Bill Baxter wrote:On Fri, Sep 12, 2008 at 9:38 AM, Rayne <DiscipleRayne gmail.com> wrote:What's so bad about ini? 1) It's simple. Even people with little to no computer savvy can look at an ini file and deduce how to make things work. 2) It's easy to parse. 3) It's not platform-dependent. Using the line iterator in Tango you don't even have to be cognizant of the differences between /r/n and /n. Just go! 4) It's simple enough to be edited from a command-line editor.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Is there some reason you are really set on using a crappy format like ini?
Sep 11 2008
On Fri, Sep 12, 2008 at 3:43 PM, Chris R. Miller <lordsauronthegreat gmail.com> wrote:Bill Baxter wrote:It's not hierarchical. But you're right, if you never have any plans to go beyond very simple key=value uses, then it's fine. But if that's all you need then maybe you don't even need ini. Just a file with plain old ---- foo = bar x = y ---- will do and you can just read the lines with a simple regex. That said I don't know the full spec of the ini format. So maybe it has some tricks I'm not aware of. --bbOn Fri, Sep 12, 2008 at 9:38 AM, Rayne <DiscipleRayne gmail.com> wrote:What's so bad about ini? 1) It's simple. Even people with little to no computer savvy can look at an ini file and deduce how to make things work. 2) It's easy to parse. 3) It's not platform-dependent. Using the line iterator in Tango you don't even have to be cognizant of the differences between /r/n and /n. Just go! 4) It's simple enough to be edited from a command-line editor.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Is there some reason you are really set on using a crappy format like ini?
Sep 12 2008
Bill Baxter wrote:On Fri, Sep 12, 2008 at 3:43 PM, Chris R. Miller <lordsauronthegreat gmail.com> wrote:You could emulate that with headers like: [hier1.hier11] foo = bar [hier1.hier12] bar = foo I think I did that with a Java project a (long) while back. That was using Java's java.util.Properties though... I forget if that was even partly ini-compliant.Bill Baxter wrote:It's not hierarchical.On Fri, Sep 12, 2008 at 9:38 AM, Rayne <DiscipleRayne gmail.com> wrote:What's so bad about ini? 1) It's simple. Even people with little to no computer savvy can look at an ini file and deduce how to make things work. 2) It's easy to parse. 3) It's not platform-dependent. Using the line iterator in Tango you don't even have to be cognizant of the differences between /r/n and /n. Just go! 4) It's simple enough to be edited from a command-line editor.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Is there some reason you are really set on using a crappy format like ini?But you're right, if you never have any plans to go beyond very simple key=value uses, then it's fine. But if that's all you need then maybe you don't even need ini. Just a file with plain old ---- foo = bar x = y ---- will do and you can just read the lines with a simple regex.Heh, I never got as far as a regex. My code does exactly what you comments). I only thought it would be useful as a starting point to add the ability to parse ini headers into.That said I don't know the full spec of the ini format. So maybe it has some tricks I'm not aware of.I think the attractiveness of ini is that there aren't any special tricks to have to be aware of. It's the ultimate WYSIWYG in configuration storage.
Sep 12 2008
On Fri, 12 Sep 2008 17:17:55 +0900, Bill Baxter wrote:But you're right, if you never have any plans to go beyond very simple key=value uses, then it's fine. But if that's all you need then maybe you don't even need ini. Just a file with plain old ---- foo = bar x = y ----Ummm, isn't that what an ini file is? I assume it is not a .d file, as that would need compiled and thus defeat the purpose of using ini.
Sep 12 2008
On Sat, Sep 13, 2008 at 11:46 AM, Jesse Phillips <jessekphillips gmail.com> wrote:On Fri, 12 Sep 2008 17:17:55 +0900, Bill Baxter wrote:There are also the [section] thingys in an ini file. But anyway, I've always associated ini files with Windows-specific cruftery. I guess from Windows' win.ini, system.ini etc. Registry .reg files and ".inf" files are also just ini files, basically. But you've convinced me. I was wrong. INI is a super format with lightweight syntax that fits the bill perfectly if all you need is to save and load a few variables. Especially if having a human-editable format is important. I've gained new respect for the humble INI. Thanks, --bbBut you're right, if you never have any plans to go beyond very simple key=value uses, then it's fine. But if that's all you need then maybe you don't even need ini. Just a file with plain old ---- foo = bar x = y ----Ummm, isn't that what an ini file is? I assume it is not a .d file, as that would need compiled and thus defeat the purpose of using ini.
Sep 12 2008
2008/9/12 Bill Baxter <wbaxter gmail.com>:I've always thought that was a benefit rather than a hinderence. It's also untyped and supports comments. JSON certainly isn't a good format to expose end users to. INIs are also very amenable to having other software tweak settings, whereas more complex formats can't always claim that (you ever tried to write code that updates a bind configuration file?).4) It's simple enough to be edited from a command-line editor.It's not hierarchical.But you're right, if you never have any plans to go beyond very simple key=value uses, then it's fine. But if that's all you need then maybe you don't even need ini. Just a file with plain old ---- foo = bar x = y ---- will do and you can just read the lines with a simple regex. That said I don't know the full spec of the ini format. So maybe it has some tricks I'm not aware of. --bb
Sep 12 2008
Rayne wrote:Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Here's a simple one I wrote a while back. A description of the file format is here: http://openrj.sourceforge.net/ // Written in the D programming language // placed into Public Domain // Written by Walter Bright module std.openrj; import std.string; alias char[][] [char[]] [] openrj_t; class OpenrjException : Exception { uint linnum; this(uint linnum, char[] msg) { this.linnum = linnum; super(std.string.format("OpenrjException line %s: %s", linnum, msg)); } } openrj_t parse(char[] db) { openrj_t rj; char[][] lines; char[][] [char[]] record; lines = std.string.splitlines(db); for (uint linnum = 0; linnum < lines.length; linnum++) { char[] line = lines[linnum]; // Splice lines ending with backslash while (line.length && line[length - 1] == '\\') { if (++linnum == lines.length) throw new OpenrjException(linnum, "no line after \\ line"); line = line[0 .. length - 1] ~ lines[linnum]; } if (line[0 .. 2] == "%%") { // Comment lines separate records if (record) rj ~= record; record = null; line = null; continue; } int colon = std.string.find(line, ':'); if (colon == -1) throw new OpenrjException(linnum, "'key : value' expected"); char[] key = std.string.strip(line[0 .. colon]); char[] value = std.string.strip(line[colon + 1 .. length]); char[][] fields = record[key]; fields ~= value; record[key] = fields; } if (record) rj ~= record; return rj; }
Sep 12 2008
Walter Bright Wrote:Rayne wrote:Thanks for the effort, however as it turns out I was being an idiot, I figured out how the properties work in Tango, its basicly an INI file. At least it works almost the same.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Here's a simple one I wrote a while back. A description of the file format is here: http://openrj.sourceforge.net/ // Written in the D programming language // placed into Public Domain // Written by Walter Bright module std.openrj; import std.string; alias char[][] [char[]] [] openrj_t; class OpenrjException : Exception { uint linnum; this(uint linnum, char[] msg) { this.linnum = linnum; super(std.string.format("OpenrjException line %s: %s", linnum, msg)); } } openrj_t parse(char[] db) { openrj_t rj; char[][] lines; char[][] [char[]] record; lines = std.string.splitlines(db); for (uint linnum = 0; linnum < lines.length; linnum++) { char[] line = lines[linnum]; // Splice lines ending with backslash while (line.length && line[length - 1] == '\\') { if (++linnum == lines.length) throw new OpenrjException(linnum, "no line after \\ line"); line = line[0 .. length - 1] ~ lines[linnum]; } if (line[0 .. 2] == "%%") { // Comment lines separate records if (record) rj ~= record; record = null; line = null; continue; } int colon = std.string.find(line, ':'); if (colon == -1) throw new OpenrjException(linnum, "'key : value' expected"); char[] key = std.string.strip(line[0 .. colon]); char[] value = std.string.strip(line[colon + 1 .. length]); char[][] fields = record[key]; fields ~= value; record[key] = fields; } if (record) rj ~= record; return rj; }
Sep 12 2008
Rayne wrote:Walter Bright Wrote:I know this has been solved but I'd like to point out that windows offers GetPrivateProfileString. Its not portable and not that efficient (although that would only be a concern if your reading 10000's of entries). http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx -KoelRayne wrote:Thanks for the effort, however as it turns out I was being an idiot, I figured out how the properties work in Tango, its basicly an INI file. At least it works almost the same.Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Here's a simple one I wrote a while back. A description of the file format is here: http://openrj.sourceforge.net/ // Written in the D programming language // placed into Public Domain // Written by Walter Bright module std.openrj; import std.string; alias char[][] [char[]] [] openrj_t; class OpenrjException : Exception { uint linnum; this(uint linnum, char[] msg) { this.linnum = linnum; super(std.string.format("OpenrjException line %s: %s", linnum, msg)); } } openrj_t parse(char[] db) { openrj_t rj; char[][] lines; char[][] [char[]] record; lines = std.string.splitlines(db); for (uint linnum = 0; linnum < lines.length; linnum++) { char[] line = lines[linnum]; // Splice lines ending with backslash while (line.length && line[length - 1] == '\\') { if (++linnum == lines.length) throw new OpenrjException(linnum, "no line after \\ line"); line = line[0 .. length - 1] ~ lines[linnum]; } if (line[0 .. 2] == "%%") { // Comment lines separate records if (record) rj ~= record; record = null; line = null; continue; } int colon = std.string.find(line, ':'); if (colon == -1) throw new OpenrjException(linnum, "'key : value' expected"); char[] key = std.string.strip(line[0 .. colon]); char[] value = std.string.strip(line[colon + 1 .. length]); char[][] fields = record[key]; fields ~= value; record[key] = fields; } if (record) rj ~= record; return rj; }
Sep 13 2008
"Rayne" <DiscipleRayne gmail.com> wrote in message news:gacdld$19l0$1 digitalmars.com...Just wondering if anyone had because it doesnt seen that the creators of Tango have, and their crappy properties stuff doesnt appeal to me in the least bit.Are you looking for an INI parser in the first place, or are you seeing whether anybody's written a Tango one before you convert an existing Phobos one to use Tango? Since a few alternatives to INI have been mentioned.... While I was a PhD student, I created Configur8, which is a configuration file format inspired by INI, but with a slightly different syntax and the ability to import and override stuff from another Configur8 file. The only problem is that I never got round to writing a D implementation, but I should be able to dig it up and convert my C++ implementation to D without too much work. Since I don't use Tango, somebody else would have to do the final step of the conversion process. Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Oct 17 2008