Not sure where you are stuck at, given your description, but I'll give
it a try.
In order to hook semantic actions into your grammar:
1. You should create a grammar object that houses your grammar.
2. You should use functor action operators.
The first provides a way to expose application objects to the grammar in
a maintainable way.
For instance:
struct My_grammar : public grammar
{
My_grammar(State& state) : state_(state) {}
template <typename ScannerT>
struct definition
{
definition(My_grammar const& self)
{
// define grammar here
rule<ScannerT> outerRule;
rule<ScannerT> const&
start() const { return outerRule; }
};
State& state_;
}
In the object example, the action objects can get mutable access to the
State object to record what needs recording.
The second "should" involves the actual action operators. These can be
either functions or functors. I sugguest using only the later in that
they can be used like:
struct captureSA
{
captureSA(State *pState) : m_pState(pState) {}
void operator()(iterator_t first, const iterator_t& last) const;
State *m_pState;
};
This functor can be attached to a rule like (note: within the body of
definition above):
outerRule[captureSA(self.state)]
There is one caviot to this. The signature of the operator() method
changes to:
void operator()(const char& ch)
when the rule matches single characters.
Sometimes its necessary to define both methods in an action functor.
Hope that helps.
Cory Nelson wrote:
Okay, I'm trying to learn Spirit and I've got the grammar down. I've
tried looking at the documentation but still can not find out how to
make a custom parser (that will let me use the [action] operator).
Could someone give an example of a pascal string parser (one byte for
length, string follows) to get me started?