|
Boost : |
From: Dan Gohman (dgohman_at_[hidden])
Date: 2002-10-20 19:24:00
On Sun, Oct 20, 2002 at 08:35:43AM +0800, Joel de Guzman wrote:
> Any specific reason for the interest in parser contexts? Actually,
> its purpose is to make the framework extensible.
I wanted something a little more convenient than closures. Here's
a rough sketch of what I was doing:
template<typename T>
struct my_context
{
struct base_t
{
T value;
};
typedef T attr_t;
explicit my_context(base_t const& base) : m_base(base) {}
template <typename ParserT, typename ScannerT>
void pre_parse(ParserT const&, ScannerT const&) {}
template <typename ResultT, typename ParserT, typename ScannerT>
ResultT& post_parse(ResultT& hit, ParserT const&, ScannerT const&)
{
hit.value() = m_base.value;
return hit;
}
private:
base_t const& m_base;
};
// node types for AST
struct node_a { /* ... */ };
struct node_b { /* ... */ };
Given the above, I then used this:
rule< ScannerT, my_context<node_a*> > a;
rule< ScannerT, my_context<node_b*> > b;
instead of this:
struct node_a_closure : closure<node_a_closure, node_a*>
{
member1 value;
};
struct node_b_closure : closure<node_b_closure, node_b*>
{
member1 value;
};
rule< ScannerT, node_a_closure > a;
rule< ScannerT, node_b_closure > b;
Dan
-- Dan Gohman dgohman_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk