/*=============================================================================
Wave: A Standard compliant C++ preprocessor
Copyright (c) 2001-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Permission to copy, use, modify, sell and distribute this software
is granted provided this copyright notice appears in all copies.
This software is provided "as is" without express or implied
warranty, and with no claim as to its suitability for any purpose.
See Copyright.txt for full copyright notices and acknowledgements.
=============================================================================*/
#if !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)
#define CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/core/assert.hpp>
#include <boost/spirit/attribute/closure.hpp>
#include "wave/cpplexer/cpp_token_ids.hpp"
#include "wave/util/pattern_parser.hpp"
#include "wave/grammars/cpp_defined_grammar_gen.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CPP_DEFINED_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR) \
/**/
template <typename ContainerT>
struct defined_grammar :
public boost::spirit::grammar<defined_grammar<ContainerT> >
{
defined_grammar(ContainerT &result_seq_)
: result_seq(result_seq_)
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "defined_grammar",
TRACE_CPP_DEFINED_GRAMMAR);
}
template <typename ScannerT>
struct definition
{
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t defined_op;
rule_t qualified_name;
rule_t identifier;
definition(defined_grammar const &self)
{
using namespace boost::spirit;
using namespace wave::cpplexer;
using namespace wave::util;
defined_op // parens not required, see C++ standard 16.1.1
= ch_p(T_IDENTIFIER) // token contains 'defined'
>> (
( ch_p(T_LEFTPAREN)
>> qualified_name
>> ch_p(T_RIGHTPAREN)
)
| qualified_name
)
;
qualified_name
= !ch_p(T_COLON_COLON)
[
append(self.result_seq)
]
>> identifier
>> *( ch_p(T_COLON_COLON)
[
append(self.result_seq)
]
>> identifier
)
;
identifier
= ch_p(T_IDENTIFIER)
[
append(self.result_seq)
]
| pattern_p(KeywordTokenType, TokenTypeMask)
[
append(self.result_seq)
]
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(defined_op, TRACE_CPP_DEFINED_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(qualified_name, TRACE_CPP_DEFINED_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(identifier, TRACE_CPP_DEFINED_GRAMMAR);
}
// start rule of this grammar
rule_t const& start() const
{ return defined_op; }
};
ContainerT &result_seq;
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_CPP_DEFINED_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following parse function is defined here, to allow the separation of
// the compilation of the defined_grammar from the function
// using it.
//
///////////////////////////////////////////////////////////////////////////////
#if defined(WAVE_SEPARATE_GRAMMAR_INSTANTIATION)
#define WAVE_DEFINED_GRAMMAR_GEN_INLINE
#else
#define WAVE_DEFINED_GRAMMAR_GEN_INLINE inline
#endif
// The parse_operator_define function is instantiated manually twice two
// simplify the explicit specialization of this template. This way the user
// has only to specify one template parameter (the token type) to correctly
// formulate the required explicit specialization.
// This results in no code overhead, because otherwise the function would be
// generated by the compiler twice anyway.
template <typename TokenT>
WAVE_DEFINED_GRAMMAR_GEN_INLINE
boost::spirit::parse_info<typename defined_grammar_gen<TokenT>::iterator1_t>
defined_grammar_gen<TokenT>::parse_operator_defined (
iterator1_t const &first, iterator1_t const &last,
std::list<TokenT> &found_qualified_name)
{
using namespace boost::spirit;
using namespace wave::cpplexer;
defined_grammar<std::list<TokenT> > g(found_qualified_name);
return boost::spirit::parse (
first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
}
template <typename TokenT>
WAVE_DEFINED_GRAMMAR_GEN_INLINE
boost::spirit::parse_info<typename defined_grammar_gen<TokenT>::iterator2_t>
defined_grammar_gen<TokenT>::parse_operator_defined (
iterator2_t const &first, iterator2_t const &last,
std::list<TokenT> &found_qualified_name)
{
using namespace boost::spirit;
using namespace wave::cpplexer;
defined_grammar<std::list<TokenT> > g(found_qualified_name);
return boost::spirit::parse (
first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
}
#undef WAVE_DEFINED_GRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
#endif // !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)