cangjie.vim (9264B)
1 " Vim syntax file 2 " Language: Cangjie 3 " Maintainer: Wu Junkai <wu.junkai@qq.com> 4 " URL: https://github.com/WuJunkai2004/cangjie.vim 5 " Last Change: 2026 Jan 5 6 " 7 " The Cangjie programming language is a new-generation programming 8 " language oriented to full-scenario intelligence. It features 9 " native intelligence, being naturally suitable for all scenarios, 10 " high performance and strong security. It is mainly applied in 11 " scenarios such as native applications and service applications 12 " of HarmonyOS NEXT, providing developers with a good programming 13 " experience. 14 " 15 " For more information, see: 16 " - https://cangjie-lang.cn/ 17 " - https://gitcode.com/Cangjie 18 19 " quit when a syntax file was already loaded 20 if exists("b:current_syntax") 21 finish 22 endif 23 24 let s:save_cpo = &cpo 25 set cpo&vim 26 27 " 0. check the user's settings 28 " use let g:cangjie_<item>_color to enable/disable syntax highlighting 29 function! s:enabled(item) abort 30 return get(g:, 'cangjie_' . a:item . '_color', 1) 31 endfunction 32 33 syn case match 34 35 " 1. comments 36 syn keyword cangjieTodo TODO FIXME XXX NOTE BUG contained 37 syn match cangjieDocKeyword /\v\c\@(brief|param|return|note|warning|deprecated)/ contained 38 syn match cangjieDocKeyword /\v\c\@(author|version|date|since|file|copyright)/ contained 39 syn match cangjieDocKeyword /\v\c\@(details|link|see|throws|exception|example)/ contained 40 syn match cangjieDocKeyword /\v\c\@(private|protected|public|internal)/ contained 41 syn match cangjieComment /\v\/\/.*/ contains=cangjieTodo,cangjieDocKeyword 42 syn region cangjieComment start=/\/\*/ end=/\*\// contains=cangjieTodo,cangjieDocKeyword,@spell 43 44 " 2. keywords 45 syn keyword cangjieDeclaration abstract extend macro foreign 46 syn keyword cangjieDeclaration interface open operator override private prop protected 47 syn keyword cangjieDeclaration public redef static type 48 syn keyword cangjieStatement as break case catch continue do else finally for in 49 syn keyword cangjieStatement if in is match quote return spawn super synchronized 50 syn keyword cangjieStatement throw try unsafe where while 51 syn keyword cangjieIdentlike false init main this true 52 syn keyword cangjieVariable const let var 53 syn keyword cangjieOption Option Some None 54 syn keyword cangjieDeclaration func struct class enum import package nextgroup=cangjieTypeName skipwhite 55 syn cluster cangjieKeywordCluster contains= 56 \ cangjieDeclaration, 57 \ cangjieStatement, 58 \ cangjieIdentlike, 59 \ cangjieVariable, 60 \ cangjieOption 61 62 " 3. macro (e.g., @override) 63 syn match cangjieMacro /@\h\w*/ 64 65 " 4. Type and Function Names 66 syn match cangjieTypeName /\h\w*/ contained 67 68 " 5. specail identifiers 69 syn region cangjieSpIdentifier start=/`/ end=/`/ oneline 70 71 " 6. types 72 syn keyword cangjieSpType Nothing Range Unit LibC Duration DefaultHasher 73 syn keyword cangjieArrayType Array VArray 74 syn keyword cangjieCommonType Bool Byte Rune String 75 syn keyword cangjieFloatType Float16 Float32 Float64 76 syn keyword cangjieIntType Int Int8 Int16 Int32 Int64 IntNative 77 syn keyword cangjieUIntType UInt UInt8 UInt16 UInt32 UInt64 UIntNative 78 syn keyword cangjieFFIType CPointer CPointerHandle CPointerResource CString CStringResource 79 syn cluster cangjieTypeCluster contains= 80 \ cangjieSpType, 81 \ cangjieArrayType, 82 \ cangjieCommonType, 83 \ cangjieFloatType, 84 \ cangjieIntType, 85 \ cangjieUIntType, 86 \ cangjieFFIType 87 88 " 6.1. builtin function/interface/class 89 syn keyword cangjieCoreFunc acquireArrayRawData alignOf eprint eprintln ifNone ifSome max min 90 syn keyword cangjieCoreFunc print println readln refEq releaseArrayRawData sizeOf sleep zeroValue 91 syn keyword cangjieCoreItf Any Hasher ThreadContext Countable Collection Less Greater 92 syn keyword cangjieCoreItf LessOrEqual GreaterOrEqual Comparable Equal NotEqual Equatable 93 syn keyword cangjieCoreItf Hashable Iterable Resource ToString CType 94 syn keyword cangjieCoreClass ArrayIterator Box Future Iterator Object RangeIterator 95 syn keyword cangjieCoreClass StackTraceElement StringBuilder Thread ThreadLocal 96 syn keyword cangjieCoreError ArithmeticException Error Exception IllegalArgumentException 97 syn keyword cangjieCoreError IllegalFormatException IllegalMemoryException IllegalStateException 98 syn keyword cangjieCoreError IncompatiblePackageException IndexOutOfBoundsException InternalError 99 syn keyword cangjieCoreError NegativeArraySizeException NoneValueException OutOfMemoryError 100 syn keyword cangjieCoreError OverflowException SpawnException StackOverflowError 101 syn keyword cangjieCoreError TimeoutException UnsupportedException 102 syn cluster cangjieBuiltinCluster contains= 103 \ cangjieCoreFunc, 104 \ cangjieCoreItf, 105 \ cangjieCoreClass, 106 \ cangjieCoreError 107 108 " 7. character and strings 109 syn cluster cangjieInterpolatedPart contains= 110 \ @cangjieKeywordCluster, 111 \ cangjieSpIdentifier, 112 \ @cangjieTypeCluster, 113 \ @cangjieBuiltinCluster, 114 \ @cangjieNumberCluster, 115 \ cangjieOperator 116 syn region cangjieInterpolation contained keepend start=/\${/ end=/}/ contains=@cangjieInterpolatedPart 117 syn match cangjieEscape /\v\\u\{[0-9a-fA-F]{1,8}\}|\\./ contained 118 syn match cangjieRuneError /\v[rb]'([^'\\]|\\.)*'/ 119 syn match cangjieRuneError /\v[rb]"([^"\\]|\\.)*"/ 120 syn match cangjieRune /\vr'(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^'\\])'/ contains=cangjieEscape 121 syn match cangjieRune /\vr"(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^"\\])"/ contains=cangjieEscape 122 syn match cangjieRune /\vb'(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^'\\])'/ contains=cangjieEscape 123 syn region cangjieString start=/"/ skip=/\\\\\|\\"/ end=/"/ oneline contains=cangjieInterpolation,cangjieEscape 124 syn region cangjieString start=/'/ skip=/\\\\\|\\'/ end=/'/ oneline contains=cangjieInterpolation,cangjieEscape 125 syn region cangjieString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=cangjieInterpolation,cangjieEscape keepend 126 syn region cangjieString start=/'''/ skip=/\\\\\|\\'/ end=/'''/ contains=cangjieInterpolation,cangjieEscape keepend 127 syn region cangjieRawString start='\z(#*\)#"' end='"#\z1' 128 syn region cangjieRawString start='\z(#*\)#\'' end='\'#\z1' 129 130 " 8. number 131 syn match cangjieHexFloatNumber /\v\c<0x([0-9a-f_]+\.?|[0-9a-f_]*\.[0-9a-f_]+)[p][-+]?\d[0-9_]*>/ 132 syn match cangjieFloatNumber /\v\c<\d[0-9_]*\.\d[0-9_]*([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/ 133 syn match cangjieFloatNumber /\v\c<\d[0-9_]*\.([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/ 134 syn match cangjieFloatNumber /\v\c\.\d[0-9_]*([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/ 135 syn match cangjieScienceNumber /\v\c<\d[0-9_]*[e][-+]?\d[0-9_]*(f(16|32|64))?>/ 136 syn match cangjieHexNumber /\v\c<0x[0-9a-f_]+([iu](8|16|32|64))?>/ 137 syn match cangjieOctalNumber /\v\c<0o[0-7_]+([iu](8|16|32|64))?>/ 138 syn match cangjieBinaryNumber /\v\c<0b[01_]+([iu](8|16|32|64))?>/ 139 syn match cangjieDecimalNumber /\v\c<\d[0-9_]*([iu](8|16|32|64))?>/ 140 syn cluster cangjieNumberCluster contains= 141 \ cangjieHexFloatNumber, 142 \ cangjieFloatNumber, 143 \ cangjieScienceNumber, 144 \ cangjieHexNumber, 145 \ cangjieOctalNumber, 146 \ cangjieBinaryNumber, 147 \ cangjieDecimalNumber 148 149 " 9. operators 150 syn match cangjieOperator /[-+%<>!&|^*=]=\?/ 151 syn match cangjieOperator /\/\%(=\|\ze[^/*]\)/ 152 syn match cangjieOperator /\%(<<\|>>\|&^\)=\?/ 153 syn match cangjieOperator /:=\|||\|<-\|++\|--/ 154 syn match cangjieOperator /[~]/ 155 syn match cangjieOperator /[:]/ 156 syn match cangjieOperator /\.\./ 157 syn match cangjieVarArgs /\.\.\./ 158 159 " 10. folding 160 syn region cangjieFoldBraces transparent fold start='{' end='}' contains=ALLBUT,cangjieComment 161 syn region cangjieFoldParens transparent fold start='(' end=')' contains=ALLBUT,cangjieComment 162 syn region cangjieFoldBrackets transparent fold start='\[' end='\]' contains=ALLBUT,cangjieComment 163 164 " finally, link the syntax groups to the highlight groups 165 if s:enabled('comment') 166 hi def link cangjieTodo Todo 167 hi def link cangjieDocKeyword SpecialComment 168 hi def link cangjieComment Comment 169 endif 170 if s:enabled('identifier') 171 hi def link cangjieSpIdentifier Identifier 172 endif 173 if s:enabled('keyword') 174 hi def link cangjieDeclaration Keyword 175 hi def link cangjieStatement Statement 176 hi def link cangjieIdentlike Keyword 177 hi def link cangjieVariable Keyword 178 hi def link cangjieOption Keyword 179 endif 180 if s:enabled('builtin') 181 hi def link cangjieCoreFunc Function 182 hi def link cangjieCoreItf Type 183 hi def link cangjieCoreClass Type 184 hi def link cangjieCoreError Structure 185 endif 186 if s:enabled('macro') 187 hi def link cangjieMacro PreProc 188 endif 189 if s:enabled('number') 190 hi def link cangjieHexFloatNumber Number 191 hi def link cangjieFloatNumber Float 192 hi def link cangjieScienceNumber Float 193 hi def link cangjieHexNumber Number 194 hi def link cangjieOctalNumber Number 195 hi def link cangjieBinaryNumber Number 196 hi def link cangjieDecimalNumber Number 197 endif 198 if s:enabled('operator') 199 hi def link cangjieOperator Operator 200 hi def link cangjieVarArgs Operator 201 endif 202 if s:enabled('string') 203 hi def link cangjieRune Character 204 hi def link cangjieRuneError Error 205 hi def link cangjieString String 206 hi def link cangjieRawString String 207 hi def link cangjieEscape SpecialChar 208 endif 209 if s:enabled('type') 210 hi def link cangjieTypeName Type 211 hi def link cangjieSpType Type 212 hi def link cangjieArrayType Type 213 hi def link cangjieCommonType Type 214 hi def link cangjieFloatType Type 215 hi def link cangjieIntType Type 216 hi def link cangjieUIntType Type 217 hi def link cangjieFFIType Type 218 endif 219 220 let b:current_syntax = "cangjie" 221 222 let &cpo = s:save_cpo 223 unlet s:save_cpo 224 225 " vim: ts=8 sw=8 noet