vim-jp / vim-cpp

c or cpp syntax files
147 stars 44 forks source link

Add support for chrono literals #42

Open dareg opened 7 years ago

dareg commented 7 years ago

Allow the duration to be highlighted as the numbers.

auto time {1.5ms};
if (time < 100ms){
  time += .0E1ms;
  time -= 0X2Ah;
}

See this link for more informations on chrono literals: http://en.cppreference.com/w/cpp/chrono/duration

rhysd commented 7 years ago

I think these kind of literals can be highlighted more generally. h or ms or s or things are just a library implementation, not a language feature. We can define our original literals as below.

http://en.cppreference.com/w/cpp/language/user_literal

e.g.

int main() {
    1.2_w; // calls operator "" _w(1.2L)
    u"one"_w; // calls operator "" _w(u"one", 3)
    12_w; // calls operator "" _w("12")
    "two"_w; // error: no applicable literal operator
}

If we determine to define the chrono literals, we also need to define highlights for user defined literals. If not, IMO, we should not highlight literals defined in standard library also for consistency.

rhysd commented 7 years ago

The point looks that we should highlight identifiers defined in standard library or not. Currently syntax/cpp.vim highlights no identifier defined in standard library as long as I know.

dareg commented 7 years ago

From my point of view, the chrono literals were just «enhanced numbers», that's why I have proposed to highlight them in the same color than the numbers. But I can understand that my view is too specific and not enough global.

rhysd commented 7 years ago

yeah I understand that standard user-defined literals are near the language core feature and it looks better if they are highlighted as well as builtin literals such as 12ll, 3.14f. This looks tradeoff between persistency (highlights only core features) and usability (standard user-defined literals should be handled as well as builtin ones) for me. I want to leave this decision to @mattn.