robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:77a59be: runtime(cangjie): Update syntax script (#37267)7eb14ba0ba

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