Ticket #6253: hackfix.patch

File hackfix.patch, 3.6 KB (added by Ryan Molden <ryanmolden@…>, 11 years ago)

This is a hacky fix I have used locally to unblock myself. Don't think it is boost quality or even necessarily the right approach, including mostly for completeness.

  • .hpp

    old new  
    3434        return os_.good();
    3535    }
    3636
     37    template <typename Char>
     38    struct ProperCharTypeStrings {};
     39
     40    template <>
     41    struct ProperCharTypeStrings<char>
     42    {
     43        static char *CharTypeString;
     44        static char *LiteralPrefix;
     45    };
     46    //Not a good idea since this is a header and we don't want multiple definition complaints from the compiler
     47    char * ProperCharTypeStrings<char>::CharTypeString = "char";
     48    char * ProperCharTypeStrings<char>::LiteralPrefix = "";
     49
     50    template<>
     51    struct ProperCharTypeStrings<wchar_t>
     52    {
     53        static char *CharTypeString;
     54        static char *LiteralPrefix;
     55    };
     56    //Not a good idea since this is a header and we don't want multiple definition complaints from the compiler
     57    char * ProperCharTypeStrings<wchar_t>::CharTypeString = "wchar_t";
     58    char * ProperCharTypeStrings<wchar_t>::LiteralPrefix = "L";
     59
    3760    ///////////////////////////////////////////////////////////////////////////
    3861    // Generate a table of the names of the used lexer states, which is a bit
    3962    // tricky, because the table stored with the rules is sorted based on the
     
    4871        typedef typename
    4972            boost::lexer::basic_rules<Char>::string_size_t_map::const_iterator
    5073        state_iterator;
    51         typedef std::map<std::size_t, char const*> reverse_state_map_type;
     74        typedef std::map<std::size_t, Char const*> reverse_state_map_type;
    5275
    5376        reverse_state_map_type reverse_state_map;
    5477        state_iterator send = rules_.statemap().end();
     
    6083
    6184        generate_delimiter(os_);
    6285        os_ << "// this table defines the names of the lexer states\n";
    63         os_ << "char const* const lexer_state_names"
     86        os_ << ProperCharTypeStrings<Char>::CharTypeString << " const* const lexer_state_names"
    6487            << (name_suffix[0] ? "_" : "") << name_suffix
    6588            << "[" << rules_.statemap().size() << "] = \n{\n";
    6689
     
    7396            {
    7497                os_ << "    0,  // \"<undefined state>\"\n";
    7598            }
    76             os_ << "    \"" << (*rit).second << "\"";
     99            os_ << "    " << ProperCharTypeStrings<Char>::LiteralPrefix << "\"" << (*rit).second << "\"";
    77100            if (++rit != rend)
    78101                os_ << ",\n";
    79102            else
     
    89112        return os_.good();
    90113    }
    91114
     115    template <typename Char>
    92116    inline bool
    93117    generate_cpp_state_table (std::ostream &os_, char const* name_suffix
    94118      , bool bol, bool eol)
     
    110134        os_ << "    static std::size_t state_count()\n";
    111135        os_ << "    {\n        return lexer_state_count" << suffix << "; \n    }\n\n";
    112136        os_ << "    // return the name of the lexer state as given by 'idx'\n";
    113         os_ << "    static char const* state_name(std::size_t idx)\n";
     137        os_ << "    static " << ProperCharTypeStrings<Char>::CharTypeString << " const* state_name(std::size_t idx)\n";
    114138        os_ << "    {\n        return lexer_state_names" << suffix << "[idx]; \n    }\n\n";
    115139        os_ << "    // return the next matched token\n";
    116140        os_ << "    template<typename Iterator>\n";
     
    896920            return false;
    897921        os_ << "}\n\n";
    898922
    899         if (!generate_cpp_state_table(os_, name_suffix
     923        if (!generate_cpp_state_table<Char>(os_, name_suffix
    900924            , sm_.data()._seen_BOL_assertion, sm_.data()._seen_EOL_assertion))
    901925        {
    902926            return false;