I am trying to declare a recursive AST for a spirit x3 parser. The parser grammar is working, and since it is recommended to avoid semantic actions I am trying to adapt the Rexpr official documentation example.
In the main documentation, the parsed structure can be represented by a map where keys are strings and values are either a string or another map.
In my case, the structure being parsed is a simple n-ary tree, and I hoped I could get my way out with a recursive struct and forward_ast
:
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
namespace ast
{
struct node
{
std::string name;
double length;
std::vector<boost::spirit::x3::forward_ast<node>> children;
};
}
BOOST_FUSION_ADAPT_STRUCT(ast::node, name, length, children)
But I did not succeed having this compile - boost fusion tells me that
error: explicit specialization of undeclared template struct 'tag_of'
BOOST_FUSION_ADAPT_STRUCT(ast::node, name, length, children)
So I guess I failed to understand either:
- the logic of recursive ast,
- the syntax to use to tell boost fusion about this nested type?
- or both?