Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for chrono literals #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add support for chrono literals #42

wants to merge 4 commits into from

Conversation

dareg
Copy link

@dareg dareg commented Feb 2, 2017

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

syntax/cpp.vim Outdated
@@ -71,6 +77,12 @@ hi def link cppConstant Constant
hi def link cppRawStringDelimiter Delimiter
hi def link cppRawString String
hi def link cppNumber Number
hi def link cppChronoLiteralsDecimal Number
hi def link cppChronoLiteralsFloat Number
hi def link cppChronoLiteralsFloat Number
Copy link
Member

@mattn mattn Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line dup

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rhysd
Copy link
Contributor

rhysd commented Feb 11, 2017

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.

syn match cppChronoLiteralsFloat display "\.\d\+\([eE][\-+]\=\d\+\)\=\(h\|min\|s\|ms\|us\|ns\)\>"
syn match cppChronoLiteralsBinary display "\<0b[01]\('\=[01]\+\)*\(h\|min\|s\|ms\|us\|ns\)\>"
syn match cppChronoLiteralsHexa display "\<0x\x\('\=\x\+\)*\(h\|min\|s\|ms\|us\|ns\)\>"
syn match cppChronoLiteralsOctal display "\<0\o\+\(h\|min\|s\|ms\|us\|ns\)\>" contains=cOctalZero
Copy link
Contributor

@rhysd rhysd Feb 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we determine to highlight them, how about adding them to existing number highlights as below?

syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\|h\|min\|s\|ms\|us\|ns\)\>"

@rhysd
Copy link
Contributor

rhysd commented Feb 11, 2017

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
Copy link
Author

dareg commented Feb 21, 2017

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
Copy link
Contributor

rhysd commented Feb 27, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants