Lars Gullik Bjønnes wrote: > | Sure. See attached. > > Ok... then add some attributes, mixed-contentent. > > <xml attr1="" attr2=""> > <greeting>Hello</greeting>there. > </xml> > > Would be great seeing an example using the actual xml grammar from > xml.zip? Or is generic parsing frowned upon with spirit?
I haven't looked at that stuff, just forwarded the link in the hope it might be useful. ... Ok, now I've had a quick look. xml_grammar.hpp contains the definition of the full XML grammar, right? It's used here either to just parse a data file or to build an AST. Neither of which you want. However, you can pass in a LyX "Buffer &" variable struct xml_grammar { Buffer & buffer; xml_grammar(Buffer & b) : buffer(b) {} template <typename ScannerT> struct definition { definition(xml_grammar const & self) { using phoenix arg2; using phoenix arg1; using phoenix var; ... some_rule = some-parser [ do_something(var(self.buffer), arg1, arg2) ] ; }; }; where do_something is a lazy function you define whose operator() takes a Buffer & variable together with dum iterators to the begin,end of the parsed string. So, why not try it? Add [ lars_first_func(var(self.buffer), arg1, arg2) ] to any one of the rules in xml_grammar::definition::definition. Eg AttType = StringType [ lars_first_func(var(self.buffer), arg1, arg2) ] | TokenizedType | EnumeratedType; struct lars_first_func_impl { template <typename Arg1, typename Arg2, typename Arg3> struct result { typedef void type; }; template <typename ItT> void operator()(Buffer const &, ItT const & begin, ItT const & end) { std::cout << "lars_first_func: " << std::string(begin, end) << std::endl; } }; phoenix::function<lars_first_func_impl> const lars_first_func = lars_first_func_impl(); I'd resist trying to do anything funky in the grammar itself for the time being. Like defining rules with closures. Delegate everything to external functions and, to begin with, just get 'em to print out what they receive. -- Angus