bool found_unknown_directive(ContextT const& ctx, ContainerT const& line, ContainerT& pending) { namespace wave = boost::wave; typedef typename ContainerT::const_iterator iterator_type; iterator_type it = line.begin(); wave::token_id id = wave::util::impl::skip_whitespace(it, line.end()); if (id != wave::T_IDENTIFIER) return false; // nothing we could do if ((*it).get_value() == "version" || (*it).get_value() == "extension") { // handle #version and #extension directives std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } return false; // unknown directive }
inline bool definition_equals(ContainerT const &definition, ContainerT const &new_definition) { typedef typename ContainerT::const_iterator const_iterator_type; const_iterator_type first1 = definition.begin(); const_iterator_type last1 = definition.end(); const_iterator_type first2 = new_definition.begin(); const_iterator_type last2 = new_definition.end(); while (first1 != last1 && first2 != last2 && token_equals(*first1, *first2)) { // skip whitespace, if both sequences have a whitespace next token_id id1 = next_token<const_iterator_type>::peek(first1, last1, false); token_id id2 = next_token<const_iterator_type>::peek(first2, last2, false); if (IS_CATEGORY(id1, WhiteSpaceTokenType) && IS_CATEGORY(id2, WhiteSpaceTokenType)) { // all consecutive whitespace tokens count as one whitespace // adjust first1 and first2 accordingly skip_whitespace(first1, last1); skip_whitespace(first2, last2); } else if (!IS_CATEGORY(id1, WhiteSpaceTokenType) && !IS_CATEGORY(id2, WhiteSpaceTokenType)) { ++first1; ++first2; } else { // the sequences differ break; } } return (first1 == last1 && first2 == last2) ? true : false; }
inline bool is_whitespace_only (ContainerT const &argument) { using namespace cpplexer; typename ContainerT::const_iterator end = argument.end(); for (typename ContainerT::const_iterator it = argument.begin(); it != end; ++it) { if (!IS_CATEGORY(*it, WhiteSpaceTokenType)) return false; } return true; }
inline typename ContainerT::value_type::string_type as_stringlit (ContainerT const &token_sequence, PositionT const &pos) { using namespace boost::wave; typedef typename ContainerT::value_type::string_type string_type; string_type result("\""); bool was_whitespace = false; typename ContainerT::const_iterator end = token_sequence.end(); for (typename ContainerT::const_iterator it = token_sequence.begin(); it != end; ++it) { token_id id = token_id(*it); if (IS_CATEGORY(*it, WhiteSpaceTokenType) || T_NEWLINE == id) { if (!was_whitespace) { // C++ standard 16.3.2.2 [cpp.stringize] // Each occurrence of white space between the argument's // preprocessing tokens becomes a single space character in the // character string literal. result += " "; was_whitespace = true; } } else if (T_STRINGLIT == id || T_CHARLIT == id) { // string literals and character literals have to be escaped result += impl::escape_lit((*it).get_value()); was_whitespace = false; } else #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 if (T_PLACEMARKER != id) #endif { // now append this token to the string result += (*it).get_value(); was_whitespace = false; } } result += "\""; // validate the resulting literal to contain no invalid universal character // value (throws if invalid chars found) boost::wave::cpplexer::impl::validate_literal(result, pos.get_line(), pos.get_column(), pos.get_file()); return result; }
void replace_ellipsis (std::vector<ContainerT> const &arguments, typename ContainerT::size_type index, ContainerT &expanded, PositionT const &pos) { using namespace cpplexer; typedef typename ContainerT::value_type token_type; token_type comma(T_COMMA, ",", pos); for (/**/; index < arguments.size(); ++index) { ContainerT const &arg = arguments[index]; std::copy(arg.begin(), arg.end(), std::inserter(expanded, expanded.end())); if (index < arguments.size()-1) expanded.push_back(comma); } }
void push_front_test() { using namespace boost::spirit; const char* cp = "one,two,three"; const char* cp_first = cp; const char* cp_last = cp + test_impl::string_length(cp); const char* cp_i[] = {"one","two","three"};; int i; ContainerT c; typename ContainerT::const_iterator it; scanner<char const*> scan( cp_first, cp_last ); match<> hit; hit = list_p( (*alpha_p)[ push_front_a(c)] , ch_p(',') ).parse(scan); BOOST_CHECK(hit); BOOST_CHECK_EQUAL(scan.first, scan.last); BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3)); for (i=2, it = c.begin();i>=0 && it != c.end();--i, ++it) BOOST_CHECK_EQUAL( cp_i[i], *it); scan.first = cp; }
bool CPreProcessor::found_unknown_directive(ContextT const& ctx, ContainerT const& line, ContainerT& pending) { typedef typename ContainerT::const_iterator iterator_type; iterator_type it = line.begin(); wave::token_id id = wave::util::impl::skip_whitespace(it, line.end()); if ( id != wave::T_IDENTIFIER ) { // nothing we could do return false; } if ((*it).get_value() == "version" || (*it).get_value() == "extension" ) { // Handle #version and #extension directives std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } if ((*it).get_value() == "type" ) { // Handle type directive typedef typename ContextT::token_type result_type; for ( result_type t : line ) { const char* text = t.get_value().c_str(); if ( strcmp("#", text) != 0 && strcmp("type", text) != 0 && strcmp("na", text) != 0 ) { type_ += t.get_value().c_str(); } } alg::trim(type_); //std::cout << type_ << std::endl; return true; } if ((*it).get_value() == "name") { // Once the name is set, we ignore #name directives if ( name_.size() == 0 ) { // Handle name directive typedef typename ContextT::token_type result_type; for ( result_type t : line ) { const char* text = t.get_value().c_str(); if ( strcmp("#", text) != 0 && strcmp("name", text) != 0 ) { name_ += t.get_value().c_str(); } } alg::trim(name_); } //std::cout << name_ << std::endl; return true; } if ((*it).get_value() == "bind" ) { // Handle bind directive //typedef typename ContextT::token_type result_type; //for ( result_type t : line) { // std::cout << t.get_value() << std::endl; //} std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } // Unknown directive return false; }
std::string containerStr (const ContainerT& c, int wrapLengthParam = 0, int numIndentationSpaces = 0) { return elemsStr(c.begin(), c.end(), wrapLengthParam, numIndentationSpaces); }
void visit( ContainerT& v, ::boost::any* data ){ for( typename ContainerT::iterator it = v.begin(); it != v.end(); ++it ){ SAFE_ACCEPT( *it ); } }
std::string stringJoin(ContainerT const & a, C const & padding) { return stringJoin(a.begin(), a.end(), padding); }
inline long toNumber(ContainerT& digits) { return toNumber(digits.begin(), digits.end()); }
void erase_if(ContainerT& items, const PredicateT& predicate) { for(auto it = items.begin(); it != items.end();) { if(predicate(*it)) it = items.erase(it); else ++it; } };
template<class ContainerT, class PredicateT> inline auto find_if(const ContainerT& _container, const PredicateT& _pred) { return sq::algo::find_if(_container.begin(), _container.end(), _pred); }
template<class ContainerT, class ValueT> inline auto find_first(const ContainerT& _container, const ValueT& _value) { return sq::algo::find_first(_container.begin(), _container.end(), _value); }