www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Has anyone written an INI parser in tango?

reply Rayne <DiscipleRayne gmail.com> writes:
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
next sibling parent reply Anyone <anyone mail.com> writes:
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
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Fri, Sep 12, 2008 at 12:11 AM, Anyone <anyone mail.com> wrote:
 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:
Clever reply!
Sep 11 2008
parent "Manfred_Nowak" <svv1999 hotmail.com> writes:
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
prev sibling next sibling parent reply "Chris R. Miller" <lordsauronthegreat gmail.com> writes:
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
parent Rayne <DiscipleRayne gmail.com> writes:
Chris R. Miller Wrote:

 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.
Awesome Yes it does help, thank's
Sep 11 2008
prev sibling next sibling parent reply "Bill Baxter" <wbaxter gmail.com> writes:
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
next sibling parent Rayne <DiscipleRayne gmail.com> writes:
Bill Baxter Wrote:

 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
Yep, I do actually. But it looks like I don't have a choice.
Sep 11 2008
prev sibling parent reply "Chris R. Miller" <lordsauronthegreat gmail.com> writes:
Bill Baxter wrote:
 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?
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.
Sep 11 2008
next sibling parent reply "Bill Baxter" <wbaxter gmail.com> writes:
On Fri, Sep 12, 2008 at 3:43 PM, Chris R. Miller
<lordsauronthegreat gmail.com> wrote:
 Bill Baxter wrote:
 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?
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.
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
next sibling parent "Chris R. Miller" <lordsauronthegreat gmail.com> writes:
Bill Baxter wrote:
 On Fri, Sep 12, 2008 at 3:43 PM, Chris R. Miller
 <lordsauronthegreat gmail.com> wrote:
 Bill Baxter wrote:
 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?
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.
It's not hierarchical.
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.
 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
prev sibling parent reply Jesse Phillips <jessekphillips gmail.com> writes:
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
parent "Bill Baxter" <wbaxter gmail.com> writes:
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:

 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.
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, --bb
Sep 12 2008
prev sibling parent "David Wilson" <dw botanicus.net> writes:
2008/9/12 Bill Baxter <wbaxter gmail.com>:
 4) It's simple enough to be edited from a command-line editor.
It's not hierarchical.
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?).
 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
prev sibling next sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
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
parent reply Rayne <DiscipleRayne gmail.com> writes:
Walter Bright Wrote:

 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; }
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.
Sep 12 2008
parent Janderson <ask me.com> writes:
Rayne wrote:
 Walter Bright Wrote:
 
 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; }
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.
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 -Koel
Sep 13 2008
prev sibling parent "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"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