parsing text..
I''m using fstream to read in text using the getline function.. but how can I parse different strings from that line?
e.g.
if I have a script file something like this
Material "Marble"
{
Effect 3
.color.ambient = 0.3 0.3 0.3
.color.diffuse = 0.5 0.5 0.5
.texture[0].file = "textures\marble.tga"
}
how do I search for the keywords?
why not consider using xml. TinyXML is small and eay to use, and solves the "Just Another Text File Parser"-problem
http://www.grinninglizard.com/tinyxml/
http://www.grinninglizard.com/tinyxml/
I want to do it myself.. for educational purpose..
I want to know how I can make it work this way I can create some kind of script engine later.. but first I want to know a good/easy way to parse text for my material scripts and so, and settings files
I want to know how I can make it work this way I can create some kind of script engine later.. but first I want to know a good/easy way to parse text for my material scripts and so, and settings files
One place to start looking would be stringstream. You can set it equal to a std::string, and then it will act like a std::stream. Thus, you can call things like getline() on it, to read substrings up to characters like ''.'', and read numeric values out of it just like any other stream.
Boost's Spirit library is possibly one of the better ways, but it may be overkill if your parsing is not very complex. Take a compiler design class when you get a chance.
Edit: Did I just recommend boost? Ugh, how gamedev.net of me. Someone kill me if I start using D.
[edited by - bobstevens on April 21, 2004 10:18:30 AM]
Edit: Did I just recommend boost? Ugh, how gamedev.net of me. Someone kill me if I start using D.
[edited by - bobstevens on April 21, 2004 10:18:30 AM]
quote:Original post by bobstevens
Boost''s Spirit library is possibly one of the better ways, but it may be overkill if your parsing is not very complex. Take a compiler design class when you get a chance.
Edit: Did I just recommend boost? Ugh, how gamedev.net of me. Someone kill me if I start using D.
[edited by - bobstevens on April 21, 2004 10:18:30 AM]
Bison isn''t too bad if you can bear using the trainwreck known as C.
Boost Rawks
So does spirit.
So does D.
How very GD.net of me, too, I guess :-\
daerid | Legends | Garage Games | Spirit | Hapy | Boost | Python | Google
"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool
So does spirit.
So does D.
How very GD.net of me, too, I guess :-\
daerid | Legends | Garage Games | Spirit | Hapy | Boost | Python | Google
"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool
I was reminded of my love for boost::spirit today. So I''ll second or third that. It has a decent learning curve, but it is fun, just tinker with the examples for awhile.
boost::spirit is quite powerful and fun to play with, but I''d say the learning curve can grow appreciably depending on the complexity of the script/setting files you''re parsing.
I''m personally a fan of XML files, even more so since I started getting into C#/.NET development. And I just think they''re very, very cool.
I''m personally a fan of XML files, even more so since I started getting into C#/.NET development. And I just think they''re very, very cool.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement