Complete rewrite of C++ syntax additions.

Now it's region based and uses keywords mode.  Hopefully this is
faster.  It also enables support for multiple libraries with partially
overlapping symbol sets.  (E.g.: Boost and STL.)
This commit is contained in:
2021-02-24 23:44:29 -05:00
parent 33ef042adb
commit 438257749f
2 changed files with 79 additions and 53 deletions

View File

@ -23,67 +23,84 @@ syn match cxxErrorNames "\<[A-Z][A-Za-z0-9_]*Error\>"
syn match cxxCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*\(<\)\@="
syn match cxxStlPrefix "\<std\(::\)\@="
syn cluster cxxLibraryBits contains=cxxStlKeywords,cxxStlFunctions,cxxStlService,cxxStlTypes,cxxStlConstant,cxxStlExceptionNames
syn cluster cxxIgnoreCGroupingErrors contains=NONE
syn cluster cParenGroup add=@cxxIgnoreCGroupingErrors
syn cluster cxxIgnoreCGroupingErrors add=@cxxLibraryBits
"syn cluster cxxLibrary contains=cxxStlLibrary,cxxBoostLibrary
"syn region cxxStlLibrary start="\<std\(::\)\@<=" end="\( \|<\|(\)"
"syn region cxxBoostLibrary start="\<boost\(::\)\@<=" end="\( \|<\|(\)"
"syn region cxxStlLibrary start="\<std\(::\)\@<=" end="\( \|<\|(\|;\)\@="
syn region cxxStlLibrary matchgroup=cxxLibPrefix start="\<\(std\)\z(::\)\@=" matchgroup=NONE skip="\z1" end="\>" transparent
syn region cxxBoostLibrary matchgroup=cxxLibPrefix start="\<\(boost\)\z(::\)\@=" matchgroup=NONE skip="\z1" end="\>" transparent
"syn match "::" containedin=@cxxLibrary contained
"end="::\(.*\)\@>\>"
" Broken?
"syn region cxxStlLibrary start="\(\<std\)\(::\)" end="\( \|;\|(\|<\|$\)\@="
"syn region cxxBoostLibrary start="\(\<\(bp_\)\?boost\)\(::\)\@=" end="\( \|;\|(\|<\|$\)\@="
syn match cxxStlTypes "\(\<std::\)\@<=\(\(i\|o\)\(f\|string\)\?stream\)\>"
syn match cxxStlTypes "\(\<std::\)\@<=\(iostream\)\>"
syn match cxxStlTypes "\(\<std::\)\@<=basic_string\(<\)\@="
syn match cxxStlTypes "\(std::\)\@<=\(vector\|array\|deque\|list\|pair\|\(priority_\)\?queue\|stack\|\(unordered_\)\?\(multi\)\?\(set\|map\)\)\(<\|;\| \)\@="
syn match cxxStlService "\(std::\)\@<=\(cout\|clog\|cerr\)\>"
syn match cxxStlConstant "\(std::\)\@<=\(endl\|flush\)\>"
syn keyword cxxStlKeywords containedin=cxxStlLibrary,cxxBoostLibrary string_view mutex thread contained
syn keyword cxxStlKeywords containedin=cxxStlLibrary string contained
syn match cxxStlKeywords "\(\<std::\)\@<=string\>"
syn match cxxStlKeywords "\(\<std::\)\@<=mutex\>"
" syn match cxxStlTypes "\(std::\)\@<=\(vector\|array\|deque\|list\|pair\|\(priority_\)\?queue\|stack\|\(unordered_\)\?\(multi\)\?\(set\|map\)\)\(<\|;\| \)\@="
syn match cxxStlKeywords "\(std::\)\@<=\(unique_ptr\)\(<\|;\| \|\>\)\@="
syn match cxxStlKeywords "\(std::\)\@<=\(shared_ptr\)\(<\|;\| \|\>\)\@="
syn match cxxStlKeywords "\(std::\)\@<=\(weak_ptr\)\(<\|;\| \|\>\)\@="
syn match cxxStlKeywords "\(std::\)\@<=nullptr_t\>"
syn match cxxStlKeywords "\(std::\)\@<=function\>"
syn keyword cxxStlKeywords containedin=cxxStlLibrary,cxxBoostLibrary shared_ptr weak_ptr contained
syn keyword cxxStlKeywords containedin=cxxStlLibrary unique_ptr nullptr_t contained
syn keyword cxxStlKeywords containedin=cxxStlLibrary,cxxBoostLibrary function contained
syn match cxxStlFunctions "\(std::\)\@<=make_\(unique\|shared\)\(<\)\@="
syn match cxxStlFunctions "\(std::\)\@<=make_\(pair\|tuple\)\((\|<\)\@="
syn keyword cxxStlTypes containedin=cxxStlLibrary iostream istream ostream fstream ifstream ofstream contained
syn keyword cxxStlTypes containedin=cxxStlLibrary stringstream istringstream ostringstream contained
syn keyword cxxStlTypes containedin=cxxStlLibrary iostream basic_string vector deque list pair queue priority_queue stack map multimap set multiset contained
syn match cxxStlFunctions "\(std::\)\@<=addressof\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=tie\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=copy\(_\(n\|backward\|if\)\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=find\(_\(if\|first_of\|end\)\?\)\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=count\(_if\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(transform\|mismatch\|equal\|accumulate\|move\)\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=search\(_n\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=fill\(_n\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=generate\(_n\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=replace\(_copy\)\?\(_if\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(unique\|reverse\|rotate\)\(_copy\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(stable_\)\?\(partition\|sort\)\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=partial_sort\(_copy\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(inplace_\)\?merge\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(inplace_\)\?merge\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=set_\(union\|intersection\|\(symmetric_\)\?difference\)\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(push\|pop\|make\|is\|sort\)_heap\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(min\|max\)\(_element\)\?\((\)\@="
syn match cxxStlFunctions "\(std::\)\@<=\(front_\|back_\)\?\(inserter\)\((\)\@="
syn keyword cxxStlTypes containedin=cxxStlLibrary,cxxBoostLibrary array contained
syn keyword cxxStlTypes containedin=cxxStlLibrary,cxxBoostLibrary unordered_map unordered_multimap contained
syn keyword cxxStlTypes containedin=cxxStlLibrary,cxxBoostLibrary unordered_set unordered_multiset contained
syn match cxxStlTraits "\(std::\)\@<=\(is_convertible\)\(<\)\@="
syn match cxxStlTraits "\(std::\)\@<=\(is_\(default_\)\?constructible\)\(<\)\@="
syn match cxxStlFunctions "\<\(back_inserter\|begin\|end\)\((\)\@="
syn keyword cxxStlService containedin=cxxStlLibrary cout clog cerr contained
syn keyword cxxStlConstant containedin=cxxStlLibrary endl flush contained
syn match cxxStlExceptionNames "\(std::\)\@<=exception\>"
syn match cxxStlExceptionNames "\(std::\)\@<=runtime_error\>"
syn match cxxStlExceptionNames "\(std::\)\@<=logic_error\>"
syn match cxxStlExceptionNames "\(std::\)\@<=bad_typeid\>"
syn match cxxStlExceptionNames "\(std::\)\@<=bad_cast\>"
syn match cxxStlExceptionNames "\(std::\)\@<=bad_alloc\>"
syn match cxxStlExceptionNames "\(std::\)\@<=bad_array_new_length\>"
syn match cxxStlExceptionNames "\(std::\)\@<=bad_exception\>"
syn match cxxStlExceptionNames "\(std::\)\@<=invalid_argument\>"
syn match cxxStlExceptionNames "\(std::\)\@<=domain_error\>"
syn match cxxStlExceptionNames "\(std::\)\@<=out_of_range\>"
syn match cxxStlExceptionNames "\(std::\)\@<=range_error\>"
syn match cxxStlExceptionNames "\(std::\)\@<=\(overflow\|underflow\)_error\>"
syn keyword cxxStlFunctions containedin=cxxStlLibrary,cxxBoostLibrary make_shared make_tuple contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary make_unique make_pair tie addressof contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary copy copy_n copy_if copy_backward replace_copy_if replace_copy contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary find find_if find_first_of find_end contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary count count_if search search_n contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary transform mismatch equal accumulate move contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary generate generate_n fill fill_n contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary unique reverse rotate contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary unique_copy reverse_copy rotate_copy contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary sort stable_sort partition stable_partition contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary partial_sort partial_sort_copy contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary merge inplace_merge contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary set_union set_intersection contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary set_difference set_symmetric_difference contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary make_heap is_heap sort_heap push_heap pop_heap contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary min max min_element max_element contained
syn keyword cxxStlFunctions containedin=cxxStlLibrary getline contained
syn keyword cxxStlTraits containedin=cxxStlLibrary is_convertible contained
syn keyword cxxStlTraits containedin=cxxStlLibrary is_constructible is_default_constructible contained
syn keyword cxxStlFreeFunctions back_inserter front_inserter inserter begin end
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary exception contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary runtime_error contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary logic_error contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary bad_typeid contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary bad_cast contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary bad_alloc contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary bad_array_new_length contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary bad_exception contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary invalid_argument contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary domain_error contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary out_of_range contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary range_error contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary overflow_error contained
syn keyword cxxStlExceptionNames containedin=cxxStlLibrary underflow_error contained
syn match cxxStlDangerousFunction "\(\.\)\@<=release()"
@ -99,6 +116,9 @@ if version >= 508 || !exists("did_cxx_syntax_inits")
command -nargs=+ HiLink hi def link <args>
endif
"HiLink cxxStlLibrary cxxLibPrefix
"HiLink cxxBoostLibrary cxxLibPrefix
HiLink cxxObjects Object
HiLink cxxCast cxxStatement
@ -116,7 +136,10 @@ if version >= 508 || !exists("did_cxx_syntax_inits")
HiLink cxxStlTypes Object
HiLink cxxStlKeywords cppType
HiLink cxxStlFunctions cppStatement
HiLink cxxStlPrefix Caller
HiLink cxxStlFreeFunctions cppStatement
HiLink cxxLibPrefix Caller
HiLink cxxStlTraits MetaFunction
HiLink cxxMetaFunction MetaFunction

View File

@ -16,6 +16,9 @@ au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h set tw=150
au BufNewFile,BufRead */cshenv/tcshrc.* set filetype=tcsh
au BufNewFile,BufRead */src/bp/*.cpp,*/src/bp/*.hpp syn region cxxBoostLibrary matchgroup=cxxLibPrefix start="\<\(bp_boost\)\z(::\)\@=" matchgroup=NONE skip="\z1" end="\>" transparent
au BufNewFile,BufRead */src/bp/*.cpp,*/src/bp/*.hpp syn region cxxBoostVerbotenLibrary matchgroup=cxxStlDangerousFunction start="\<\(boost\)\z(::\)\@=" matchgroup=NONE skip="\z1" end="\>" transparent
" falcish
"au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h set ts=3
"au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h set sts=3