File: cangjie.vim

package info (click to toggle)
vim 2%3A9.1.2103-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 93,456 kB
  • sloc: ansic: 433,730; cpp: 6,399; makefile: 4,597; sh: 2,397; java: 2,312; xml: 2,099; python: 1,595; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; sed: 8; csh: 6; haskell: 1
file content (225 lines) | stat: -rw-r--r-- 9,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
" Vim syntax file
" Language: Cangjie
" Maintainer: Wu Junkai <wu.junkai@qq.com>
" URL: https://github.com/WuJunkai2004/cangjie.vim
" Last Change: 2026 Jan 5
"
" The Cangjie programming language is a new-generation programming
" language oriented to full-scenario intelligence. It features
" native intelligence, being naturally suitable for all scenarios,
" high performance and strong security. It is mainly applied in
" scenarios such as native applications and service applications
" of HarmonyOS NEXT, providing developers with a good programming
" experience.
"
" For more information, see:
" - https://cangjie-lang.cn/
" - https://gitcode.com/Cangjie

" quit when a syntax file was already loaded
if exists("b:current_syntax")
	finish
endif

let s:save_cpo = &cpo
set cpo&vim

" 0. check the user's settings
" use let g:cangjie_<item>_color to enable/disable syntax highlighting
function! s:enabled(item) abort
	return get(g:, 'cangjie_' . a:item . '_color', 1)
endfunction

syn case match

" 1. comments
syn keyword	cangjieTodo	TODO FIXME XXX NOTE BUG contained
syn match	cangjieDocKeyword /\v\c\@(brief|param|return|note|warning|deprecated)/ contained
syn match	cangjieDocKeyword /\v\c\@(author|version|date|since|file|copyright)/ contained
syn match	cangjieDocKeyword /\v\c\@(details|link|see|throws|exception|example)/ contained
syn match	cangjieDocKeyword /\v\c\@(private|protected|public|internal)/ contained
syn match	cangjieComment /\v\/\/.*/		contains=cangjieTodo,cangjieDocKeyword
syn region	cangjieComment start=/\/\*/ end=/\*\//	contains=cangjieTodo,cangjieDocKeyword,@spell

" 2. keywords
syn keyword cangjieDeclaration	abstract extend macro foreign
syn keyword cangjieDeclaration	interface open operator override private prop protected
syn keyword cangjieDeclaration	public redef static type
syn keyword cangjieStatement	as break case catch continue do else finally for in
syn keyword cangjieStatement	if in is match quote return spawn super synchronized
syn keyword cangjieStatement	throw try unsafe where while
syn keyword cangjieIdentlike	false init main this true
syn keyword cangjieVariable	const let var
syn keyword cangjieOption	Option Some None
syn keyword cangjieDeclaration	func struct class enum import package nextgroup=cangjieTypeName skipwhite
syn cluster cangjieKeywordCluster contains=
	\ cangjieDeclaration,
	\ cangjieStatement,
	\ cangjieIdentlike,
	\ cangjieVariable,
	\ cangjieOption

" 3. macro (e.g., @override)
syn match cangjieMacro /@\h\w*/

" 4. Type and Function Names
syn match cangjieTypeName /\h\w*/ contained

" 5. specail identifiers
syn region cangjieSpIdentifier start=/`/ end=/`/ oneline

" 6. types
syn keyword cangjieSpType	Nothing Range Unit LibC Duration DefaultHasher
syn keyword cangjieArrayType	Array VArray
syn keyword cangjieCommonType	Bool Byte Rune String
syn keyword cangjieFloatType	Float16 Float32 Float64
syn keyword cangjieIntType	Int Int8 Int16 Int32 Int64 IntNative
syn keyword cangjieUIntType	UInt UInt8 UInt16 UInt32 UInt64 UIntNative
syn keyword cangjieFFIType	CPointer CPointerHandle CPointerResource CString CStringResource
syn cluster cangjieTypeCluster contains=
	\ cangjieSpType,
	\ cangjieArrayType,
	\ cangjieCommonType,
	\ cangjieFloatType,
	\ cangjieIntType,
	\ cangjieUIntType,
	\ cangjieFFIType

" 6.1. builtin function/interface/class
syn keyword cangjieCoreFunc	acquireArrayRawData alignOf eprint eprintln ifNone ifSome max min
syn keyword cangjieCoreFunc	print println readln refEq releaseArrayRawData sizeOf sleep zeroValue
syn keyword cangjieCoreItf	Any Hasher ThreadContext Countable Collection Less Greater
syn keyword cangjieCoreItf	LessOrEqual GreaterOrEqual Comparable Equal NotEqual Equatable
syn keyword cangjieCoreItf	Hashable Iterable Resource ToString CType
syn keyword cangjieCoreClass	ArrayIterator Box Future Iterator Object RangeIterator
syn keyword cangjieCoreClass	StackTraceElement StringBuilder Thread ThreadLocal
syn keyword cangjieCoreError	ArithmeticException Error Exception IllegalArgumentException
syn keyword cangjieCoreError	IllegalFormatException IllegalMemoryException IllegalStateException
syn keyword cangjieCoreError	IncompatiblePackageException IndexOutOfBoundsException InternalError
syn keyword cangjieCoreError	NegativeArraySizeException NoneValueException OutOfMemoryError
syn keyword cangjieCoreError	OverflowException SpawnException StackOverflowError
syn keyword cangjieCoreError	TimeoutException UnsupportedException
syn cluster cangjieBuiltinCluster contains=
	\ cangjieCoreFunc,
	\ cangjieCoreItf,
	\ cangjieCoreClass,
	\ cangjieCoreError

" 7. character and strings
syn cluster cangjieInterpolatedPart contains=
	\ @cangjieKeywordCluster,
	\ cangjieSpIdentifier,
	\ @cangjieTypeCluster,
	\ @cangjieBuiltinCluster,
	\ @cangjieNumberCluster,
	\ cangjieOperator
syn region  cangjieInterpolation contained keepend start=/\${/ end=/}/ contains=@cangjieInterpolatedPart
syn match cangjieEscape /\v\\u\{[0-9a-fA-F]{1,8}\}|\\./ contained
syn match cangjieRuneError /\v[rb]'([^'\\]|\\.)*'/
syn match cangjieRuneError /\v[rb]"([^"\\]|\\.)*"/
syn match cangjieRune /\vr'(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^'\\])'/ contains=cangjieEscape
syn match cangjieRune /\vr"(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^"\\])"/ contains=cangjieEscape
syn match cangjieRune /\vb'(\\u\{[0-9a-fA-F]{1,8}\}|\\.|[^'\\])'/ contains=cangjieEscape
syn region cangjieString start=/"/ skip=/\\\\\|\\"/ end=/"/ oneline contains=cangjieInterpolation,cangjieEscape
syn region cangjieString start=/'/ skip=/\\\\\|\\'/ end=/'/ oneline contains=cangjieInterpolation,cangjieEscape
syn region cangjieString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=cangjieInterpolation,cangjieEscape keepend
syn region cangjieString start=/'''/ skip=/\\\\\|\\'/ end=/'''/ contains=cangjieInterpolation,cangjieEscape keepend
syn region cangjieRawString start='\z(#*\)#"'  end='"#\z1'
syn region cangjieRawString start='\z(#*\)#\'' end='\'#\z1'

" 8. number
syn match cangjieHexFloatNumber	/\v\c<0x([0-9a-f_]+\.?|[0-9a-f_]*\.[0-9a-f_]+)[p][-+]?\d[0-9_]*>/
syn match cangjieFloatNumber	/\v\c<\d[0-9_]*\.\d[0-9_]*([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/
syn match cangjieFloatNumber	/\v\c<\d[0-9_]*\.([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/
syn match cangjieFloatNumber	/\v\c\.\d[0-9_]*([ep][-+]?\d[0-9_]*)?(f(16|32|64))?>/
syn match cangjieScienceNumber	/\v\c<\d[0-9_]*[e][-+]?\d[0-9_]*(f(16|32|64))?>/
syn match cangjieHexNumber	/\v\c<0x[0-9a-f_]+([iu](8|16|32|64))?>/
syn match cangjieOctalNumber	/\v\c<0o[0-7_]+([iu](8|16|32|64))?>/
syn match cangjieBinaryNumber	/\v\c<0b[01_]+([iu](8|16|32|64))?>/
syn match cangjieDecimalNumber	/\v\c<\d[0-9_]*([iu](8|16|32|64))?>/
syn cluster cangjieNumberCluster contains=
	\ cangjieHexFloatNumber,
	\ cangjieFloatNumber,
	\ cangjieScienceNumber,
	\ cangjieHexNumber,
	\ cangjieOctalNumber,
	\ cangjieBinaryNumber,
	\ cangjieDecimalNumber

" 9. operators
syn match cangjieOperator /[-+%<>!&|^*=]=\?/
syn match cangjieOperator /\/\%(=\|\ze[^/*]\)/
syn match cangjieOperator /\%(<<\|>>\|&^\)=\?/
syn match cangjieOperator /:=\|||\|<-\|++\|--/
syn match cangjieOperator /[~]/
syn match cangjieOperator /[:]/
syn match cangjieOperator /\.\./
syn match cangjieVarArgs  /\.\.\./

" 10. folding
syn region cangjieFoldBraces transparent fold start='{' end='}' contains=ALLBUT,cangjieComment
syn region cangjieFoldParens transparent fold start='(' end=')' contains=ALLBUT,cangjieComment
syn region cangjieFoldBrackets transparent fold start='\[' end='\]' contains=ALLBUT,cangjieComment

" finally, link the syntax groups to the highlight groups
if s:enabled('comment')
	hi def link cangjieTodo			Todo
	hi def link cangjieDocKeyword		SpecialComment
	hi def link cangjieComment		Comment
endif
if s:enabled('identifier')
	hi def link cangjieSpIdentifier		Identifier
endif
if s:enabled('keyword')
	hi def link cangjieDeclaration		Keyword
	hi def link cangjieStatement		Statement
	hi def link cangjieIdentlike		Keyword
	hi def link cangjieVariable		Keyword
	hi def link cangjieOption		Keyword
endif
if s:enabled('builtin')
	hi def link cangjieCoreFunc		Function
	hi def link cangjieCoreItf		Type
	hi def link cangjieCoreClass		Type
	hi def link cangjieCoreError		Structure
endif
if s:enabled('macro')
	hi def link cangjieMacro		PreProc
endif
if s:enabled('number')
	hi def link cangjieHexFloatNumber	Number
	hi def link cangjieFloatNumber		Float
	hi def link cangjieScienceNumber	Float
	hi def link cangjieHexNumber		Number
	hi def link cangjieOctalNumber		Number
	hi def link cangjieBinaryNumber		Number
	hi def link cangjieDecimalNumber	Number
endif
if s:enabled('operator')
	hi def link cangjieOperator		Operator
	hi def link cangjieVarArgs		Operator
endif
if s:enabled('string')
	hi def link cangjieRune			Character
	hi def link cangjieRuneError		Error
	hi def link cangjieString		String
	hi def link cangjieRawString		String
	hi def link cangjieEscape		SpecialChar
endif
if s:enabled('type')
	hi def link cangjieTypeName		Type
	hi def link cangjieSpType		Type
	hi def link cangjieArrayType		Type
	hi def link cangjieCommonType		Type
	hi def link cangjieFloatType		Type
	hi def link cangjieIntType		Type
	hi def link cangjieUIntType		Type
	hi def link cangjieFFIType		Type
endif

let b:current_syntax = "cangjie"

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: ts=8 sw=8 noet