Boost logo

Boost :

Subject: Re: [boost] [wave] limited extensibility
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-02-07 11:07:50


Christopher,

> that sounds perfect.
>
> When passing the line, i think, possible comments should be stripped
> to prevent problems when this line is stripped from the output. The
> on_illformed hook should also have a boolean return value signaling to
> pass the line to the output or to strip it (similar to other hooks).

Ok, I added the following preprocessing hook to Wave:

///////////////////////////////////////////////////////////////////////////
//
// The function 'found_unknown_directive' is called whenever an unknown
// preprocessor directive was encountered.
//
// The parameter 'ctx' is a reference to the context object used for
// instantiating the preprocessing iterators by the user.
//
// The parameter 'line' holds the tokens of the entire source line
// containing the unknown directive.
//
// The parameter 'pending' may be used to push tokens back into the input
// stream, which are to be used as the replacement text for the whole
// line containing the unknown directive.
//
// The return value defines whether the given expression has been
// properly interpreted by the hook function or not. If this function
// returns 'false', the library will raise an 'ill_formed_directive'
// preprocess_exception. Otherwise the tokens pushed back into 'pending'
// are passed on to the user program.
//
///////////////////////////////////////////////////////////////////////////
template <typename Context, typename Container>
bool found_unknown_directive(Context const& ctx, Container const& line,
    Container& pending)
{
    return false; // by default we never interpret unknown directives
}

Depending on the settings comments are either retained or stripped _before_
invoking this hook function. For instance for a line:

    #version 150 core // some comment

the parameter 'line' will contain the following tokens:

    T_POUND "#"
    T_IDENTIFIER "version"
    T_SPACE " "
    T_PP_NUMBER "150"
    T_SPACE " "
    T_IDENTIFIER "core"
    T_NEWLINE "\n"

(if comments are to be stripped), or:

    T_POUND "#"
    T_IDENTIFIER "version"
    T_SPACE " "
    T_PP_NUMBER "150"
    T_SPACE " "
    T_IDENTIFIER "core"
    T_CPPCOMMENT "// some comment\n"

if those are to be retained.

A new example (custom_directives.cpp) demonstrates its usage.

HTH
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