-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: master
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line dup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I think these kind of literals can be highlighted more generally. 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 |
There was a problem hiding this comment.
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\)\>"
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. |
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. |
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 |
Allow the duration to be highlighted as the numbers.
See this link for more informations on chrono literals:
http://en.cppreference.com/w/cpp/chrono/duration