Thanks again Daniel. Not sure I want to go this path, but as we talking
about it....
I never did any tokenizer stuff, but am curious, in general logic, how you
would go about the passes?
1) First pass - get rid of ctrl linefeeds to get one long string.
2) Start marching down the string looking for tokens? This part not sure
about. Using regex could be a nightmare I would think. Maybe when you see
"options {", you replace it with "<options>" and when you find the last "}",
replace it with "</options>". Do that for everything, then you have xml
that can deserialize with the std .net stuff. Not sure.
Guess for now, will just leave as XML to get things working, then think
about it more after am closer to done. Cheers!
--
William Stacey, MVP
message
Probably 50 or so key words with values like bool, string[], int,
string.
Hrmm, it wouldn't be terribly hard to write. It'd take acouple days, for
sure, but if you aren't trying to compile to MSIL or anything, it'd be
doable without much of a headache(its codegen that makes you wanna tear
your
hair out).
The simplist way would be a very simple parser that just returns a
dictionary with name,value pairs. If one was really nuts you could go the
xsd.exe way and generate a config class that loads and writes out the
config
file,

.
Actually, that would be an interesting project, a library of config
parsers
and config object generators, or more interestingly a parser generator
based
on some kind of grammer...something to think about at the least, something
like this must exist for .NET somewhere....but I'm going off tangent here.
Anyway, it'd be easier than adapting libConfuse, I think, but probably
still
more work than you are looking for.
What is "jay"?
Its the parser generator that mono uses. I've been using it to write the
parser of a compiler these last couple of days. There are a few other
generators out there, jay is just the one I happen to have used. I'm
pretty
sure it would apply to this circumstance, but it requires learning a bit
of
new syntax and writing your own tokenizer. To avoid that a direct C#
parser
could probably be written, just not as efficent, I would think.
--
William Stacey, MVP
message
Thanks Erik. After looking at the lib, looks like more work then
what
I
want to get into. Maybe I will just use xml serializer instead. I
guess
most folks may like xml config files these days. Cheers!
Personally, I'm tryign to find a way to get away from them,

. After a
year
or so of too much xml, I'm starting to see why people fuss when someone
uses
xml as a human readable\writeable language.
While I don't know a library that will parse it, writing a parser
shouldn't
be terribly difficult, maybe a days work using jay, depending on the
flexibility.
Are you interested in a limited set of keywords or an open ended
parser?
--
William Stacey, MVP
Anyone know of some library that will parse files like following:
options {
directory "/etc";
allow-query { any; }; // This is the default
recursion no;
listen-on { 192.168.0.225; };
forwarders { 4.2.2.2; };
};
--
William Stacey, MVP
libConfuse pretty much does what you want:
http://www.nongnu.org/confuse/
It's pure C, but it comes prebaked with a VS.NET project so it
wouldn't
be
too hard to convert/wrap.
It might take you less time to write something yourself with Regex.
Erik