Boost::Spirit

Started by
2 comments, last by Madster 17 years, 4 months ago
I have to write a parser for a simple text format. It's not recursive and it's fully defined. I could have gone the hackish way with if's and std::cin but I decided to make it robust and go with Boost::Spirit. Then I started reading the docs. Then I finished reading the docs and while the concepts are clearer, I still have no idea what to do. I'm familiar with STL and have used Bison and Flex in the past. Has anyone here worked with Spirit before? Could you give me some pointers? Thanks :)
Working on a fully self-funded project
Advertisement
Look at the calculator example they give, and if need be, strip it down and copy and paste. It's pretty complex to do a full blown grammar but if your thing is simple, you can do it the simple way (with the parse function IIRC). If you need specific help on something, I can probably help.
How simple is the text format?

If it's really simple it might be best to quickly write a simple parser than try to learn a whole new library - and save that for when you want to parse something more complicated.
I tried the calculator example, but I needed to read the input from a file, so I instead started with the example file parser that just echoes. Then I didn't know what to add.

I need to pick up values and store them, and maybe (I could do it in the parser or afterwards) do some consistency checks.
The reason I picked Spirit is because this is the first of three different script types the project will use... so supposedly once I get this one right, the others will be a breeze to code. The other reason is that users will be writing their own scripts, so I don't want them tripping on hackish parser glitches.

Here's an example script:
(whitespace can be anywhere)

aniscript top=-0.5 bottom=0.5 left=0.5 right=0.5object Image id="mifoto" src="mifoto.jpg" loop=1keyframe time=0,hold zoomx=0.5,hold zoomy=0.5,hold top 0.5,linear left 0.5,hold zorder=-1,holdobject Text id="exito1" src="groovy" style="bold" family="times new roman" loop=foreverkeyframe time=0,hold zoomy=0.35,hold zoomx=0.7,hold top=0.1,linear left=0.2,hold rotz=-5,linear zorder=1,holdkeyframe time=0.5,hold top=0.2,linear rotz=5,linearobject Tiles id="runningman" src="megamad.tlm" loop=10keyframe time=0,hold zoomx=0.15,hold zoomy=0.2,hold tile=0,hold zorder=2,holdkeyframe time=0.1,hold tile=1,holdkeyframe time=0.2,hold tile=2,holdkeyframe time=0.3,hold tile=1,holdgroup id="textman"element id="runningman" attx=0 atty=0element id="exito1" attx=0 atty=-0.1object Group id="runacross" src="textman" loop=1keyframe time=0 top=0.7,hold left=-0.6,linear zorder=2,holdkeyframe time=0.40 top=0.7,hold left=0.6,lineargroup id="screen"element id="mifoto" attx=0 atty=0element id="runacross" attx=0 atty=0


I'll check the calculator example again and compare with the file echo example. The thing is that the minimum examples are rather big so it's easy to get lost.
Working on a fully self-funded project

This topic is closed to new replies.

Advertisement