Boost logo

Boost :

Subject: Re: [boost] [wave] limited extensibility
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-02-06 13:00:08


> i am trying to use boost.wave as a preprocessor for OpenGL Shading
> Language shader files (GLSL). GLSL uses a limited C/C++ preprocessor
> (no included etc.). I want to use boost.wave to handle the includes
> correctly besides generally gaining a more powerful preprocessor.
>
> Now the problem is that there a special preprocessor directives in
> GLSL that the compiler itself has to handle. I am speaking of the
> #version and #extension directives. I hoped boost.wave would provide
> the possibility to add special directives that the client code then
> can handle properly.
>
> Currently I use the context hook as follows:
>
> class glsl_preprocessing_hook
> : public boost::wave::context_policies::default_preprocessing_hooks
> {
> public:
> template <typename ContextT>
> void
> throw_exception(ContextT const &ctx, std::exception const& e) {
> throw e;
> }
> template <typename ContextT>
> void
> throw_exception(ContextT const &ctx,
> boost::wave::preprocess_exception const& e) {
> // just ignore ill formed directives (version, exception...)
> and let the glsl compiler handle these
> if(e.get_errorcode() !=
> boost::wave::preprocess_exception::ill_formed_directive) {
> throw e;
> }
> }
> };
>
> This just ignores the ill formed directives, but may still let
> unwanted errors through.
>
> Would it be possible to extend boost.wave in a way to be able feed the
> lexer or context regular expressions of the new custom directives?
> These could be pushed into a special hook method with the appropriate
> context information. I think this functionality would greatly increase
> the usability for C++ like languages with custom extensions to the
> preprocessor.

Extending Wave to recognize more preprocessor directives without involving
changes to the lexer seems possible by introducing a on_illformed()
preprocessing hook and pass it the whole line starting with the faulty
token. This would allow you to do the parsing on your own, instructing Wave
to continue preprocessing afterwards. The default behavior of on_illformed
would be to throw the ill_formed_directive exception as before.

Does this make sense to you?

Regards Hartmut

---------------
Meet me at BoostCon
www.boostcon.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk