Esempio n. 1
0
data::colored_string::color_t color_of_token(const data::token& t) {
  switch (t.category())
  {
  case data::token_category::character_literal:
  case data::token_category::floating_literal:
  case data::token_category::integer_literal:
  case data::token_category::string_literal:
  case data::token_category::bool_literal:
  case data::token_category::preprocessor:
    return data::color::magenta;
  case data::token_category::keyword:
    return data::color::bright_green;
  case data::token_category::comment:
    return data::color::green;
  default:
    return boost::none;
  }
}
Esempio n. 2
0
bool metashell::is_environment_setup_command(
    data::command::iterator begin_, const data::command::iterator& end_)
{
  try
  {
    begin_ = skip_whitespace(begin_, end_);

    if (begin_ == end_)
    {
      // empty input is not a query
      return true;
    }
    else
    {
      const data::token t = *begin_;
      switch (t.category())
      {
      case data::token_category::keyword:
        switch (t.type())
        {
        case data::token_type::keyword_bool:
        case data::token_type::keyword_char:
        case data::token_type::keyword_const:
        case data::token_type::keyword_double:
        case data::token_type::keyword_float:
        case data::token_type::keyword_int:
        case data::token_type::keyword_long:
        case data::token_type::keyword_short:
        case data::token_type::keyword_signed:
        case data::token_type::keyword_unsigned:
        case data::token_type::keyword_void:
        case data::token_type::keyword_volatile:
        case data::token_type::keyword_wchar_t:
          if (has_typedef(begin_, end_))
          {
            return true;
          }
          else
          {
            const data::token_type lt =
                last_non_whitespace_token_type(begin_, end_);
            return lt == data::token_type::operator_semicolon ||
                   lt == data::token_type::operator_right_brace;
          }
        case data::token_type::keyword_sizeof:
        case data::token_type::keyword_const_cast:
        case data::token_type::keyword_static_cast:
        case data::token_type::keyword_dynamic_cast:
        case data::token_type::keyword_reinterpret_cast:
          return false;
        default:
          return true;
        }
        assert(false);
      case data::token_category::identifier:
        return has_typedef(begin_, end_) ||
               last_non_whitespace_token_type(begin_, end_) ==
                   data::token_type::operator_semicolon;
      case data::token_category::preprocessor:
        return true;
      default:
        return false;
      }
    }
  }
  catch (...)
  {
    return false;
  }
}