vim/syntax/cpp.vim

117 lines
4.1 KiB
VimL

" Language: C++
" Description:
" Current Maintainer: Kenneth Benzie (Benie) <k.benzie83@gmail.com>
" Created: December 23, 2016
" Quit when a syntax file was already loaded
if exists('b:current_syntax')
finish
endif
" Disable C syntax options to improve performance
let b:c_no_curly_error = 1
let b:c_no_bracket_error = 1
let b:c_no_cformat = 1
let b:c_no_c11 = 1
let b:c_no_ansi = 1
let b:c_no_bsd = 1
let b:c_gnu = 0
let b:c_no_operators = 1
" Read the C syntax to start with
runtime! syntax/c.vim
unlet b:current_syntax
" C++98
syn keyword cppStatement this friend using
syn keyword cppAccess public protected private
syn keyword cppModifier inline virtual explicit export
syn keyword cppType bool wchar_t
syn keyword cppExceptions throw try catch
syn keyword cppOperator new delete typeid and bitor or xor compl bitand and_eq
\ or_eq xor_eq not not_eq
if exists('c_no_operators')
syn keyword cppOperator operator
endif
syn keyword cppCast const_cast static_cast dynamic_cast reinterpret_cast
syn keyword cppStorageClass mutable
syn keyword cppStructure class typename template namespace
syn keyword cppBoolean true false
syn keyword cppConstant __cplusplus
" C++11
if !exists('cpp_no_cpp11')
syn keyword cppModifier override final
syn keyword cppType char16_t char32_t nullptr_t
syn keyword cppExceptions noexcept
syn keyword cppStorageClass constexpr decltype thread_local
syn keyword cppConstant nullptr
syn keyword cppOperator alignas alignof decltype static_assert
syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell display
" Match: = delete; and = default;
" ^^^^^^ ^^^^^^^
" Both `delete` and `default` are keywords which normally take precidence,
" however if the match starts before the beginning of the keyword it will be
" chosen instead so we can specialze for this case.
syn match cppStatement '=\s\+\(delete\|default\)\ze\s*;\?' contains=cOperator display
endif
" C++14
if !exists('cpp_no_cpp14')
syn match cppNumber display '\<0b[01]\+\(u\=l\{0,2}\|ll\=u\)\>'
endif
if !exists('cpp_no_delimiters')
" Match: delimiter expressions: <expr>, ex::pr
" ^ ^ ^^
syn match cppDelimiter '\(<\|>\|::\)' display
" Match: nested namespace expressions: expr::
" ^^^^
syn match cppNestedName '\a\w*::' display contains=cppDelimiter
" Match: label: as a Label and public: protected: private: as a Statement
" ^^^^^ ^^^^^^ ^^^^^^^^^ ^^^^^^^
syn match cUserCont "^\s*\I\i*\s*:$" contains=cppAccess display
hi default link cppDelimiter cDelimiter
hi default link cppNestedName cInclude
endif
if !exists('cpp_no_operators') && !exists('cpp_no_delimiters')
" Match: single character operators if they are surrounded by white space: / < >
" ^ ^ ^
syn match cppOperator '\(\s\zs\/\s\ze\|\s\zs<\s\ze\|\s\zs>\s\ze\)' display
" Match: <= >= -> << >> <<= >>= ->*
" ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^^
syn match cppOperator '\(<=\|>=\|->\|<<\ze\s\|\s\zs>>\|>>=\|<<=\|->\*\)' display
" Match: operator<< operator>> operator< operator> operator[]
" ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^
" operator new operator delete operator new[] operator delete[]
" ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
syn match cppOperator 'operator\s*\(\/\|<<\|>>\|<\|>\|\(new\|delete\)\?\s*\[\s*\]\)\?' display
endif
" Default highlighting
hi def link cppAccess cppStatement
hi def link cppCast cppOperator
hi def link cppExceptions Exception
hi def link cppOperator Operator
hi def link cppStatement Statement
hi def link cppModifier cppStatement
hi def link cppType Type
hi def link cppStorageClass StorageClass
hi def link cppStructure Structure
hi def link cppBoolean Boolean
hi def link cppConstant Constant
hi def link cppRawStringDelimiter Delimiter
hi def link cppRawString String
hi def link cppNumber Number
let b:current_syntax = 'cpp'
" vim: ts=8