blob: c4c4508f12e933396b8bcaba14f11d8cf5391583 [file] [log] [blame]
Pierrick Guillaume280e5b12024-05-31 12:00:49 +02001" Vim syntax file
2" Language: rasi (Rofi Advanced Style Information)
3" Maintainer: Pierrick Guillaume <pierguill@gmail.com>
4" Last Change: 2024 May 21
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +02005" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121)
Pierrick Guillaume280e5b12024-05-31 12:00:49 +02006"
7" Syntax support for rasi config file
8
9" This file is based on syntax defined in rofi-theme man page
10" https://man.archlinux.org/man/community/rofi/rofi-theme.5.en
11
12if exists('b:current_syntax')
13 finish
14endif
15let b:current_syntax = 'rasi'
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +020016let s:cpo_save = &cpo
17set cpo&vim
Pierrick Guillaume280e5b12024-05-31 12:00:49 +020018
19" String {{{
20syn region rasiString start=+"+ skip=+\\"+ end=+"+ oneline contained
21syn match rasiCharacter +L\='[^\\]'+ contained
22
23syn cluster rasiPropertyVals add=rasiString,rasiCharacter
24" }}}
25
26" Integer/Real {{{
27syn match rasiNumber display contained '[+-]\?\d\+\(\.\d\+\)\?'
28
29syn cluster rasiPropertyVals add=rasiNumber
30" }}}
31
32" Boolean {{{
33syn keyword rasiBool contained true false
34
35syn cluster rasiPropertyVals add=rasiBool
36" }}}
37
38" Image {{{
39syn match rasiInvImage display contained 'url([^)]*)'
40syn keyword rasiImageK contained url linear-gradient
41
42syn match rasiImage display contained transparent 'url(\s*"\([^"]\|\\"\)\+"\(\s*,\s*\(none\|both\|width\|height\)\)\?\s*)' contains=rasiImageScale,rasiString,rasiImageK
43syn keyword rasiImageScale contained none both width height
44
45syn match rasiImage display contained transparent 'linear-gradient(\s*\(\(top\|left\|right\|bottom\)\s*,\s*\)\?[^,)]\+\s*\(,\s*[^,)]\+\s*\)\+)' contains=rasiImageDirection,@rasiColors,rasiImageK
46syn keyword rasiImageDirection contained top left right bottom
47
48syn match rasiImage display contained transparent 'linear-gradient(\s*\d\+\(rad\|grad\|deg\)\s*,\s*[^,)]\+\s*\(,\s*[^,)]\+\s*\)\+)' contains=rasiImageUnit,@rasiColor,@rasiInvColor,rasiNumber,rasiImageK
49syn match rasiImageUnit display contained '\(rad\|grad\|deg\)\>'
50
51syn cluster rasiPropertyVals add=rasiInvImage,rasiImage
52" }}}
53
54" Reference {{{
55syn match rasiReference display contained '@[a-zA-Z0-9-]\+'
56
57syn keyword rasiVarReferenceK contained var
58
59syn match rasiInvVarReference display contained 'var([^)]*)'
60syn match rasiVarReference display contained transparent 'var(\s*[a-zA-Z0-9-]\+\s*,\s*\(\a\+\s*([^)]*)\)\?[^),]*)' contains=rasiVarReferenceK,rasiPropertyIdRef,@rasiPropertyVals
61syn match rasiPropertyIdRef display contained '\a[a-zA-Z0-9-]*'
62
63syn cluster rasiPropertyVals add=rasiReference,rasiInvVarReference,rasiVarReference
64" }}}
65
66" Env variable {{{
67syn match rasiInvEnv display contained '${[^}]*}'
68syn match rasiEnv display contained '${\w\+}'hs=s+2,he=e-1
69
70syn keyword rasiEnvVarK contained env
71
72syn match rasiInvEnvVar display contained 'env([^)]*)'
73syn match rasiEnvVar display contained transparent 'env(\s*\w\+\s*,\s*\(\a\+([^)]*)\)\?[^),]*)' contains=rasiEnvVarK,rasiEnvRef,@rasiPropertyVals
74syn match rasiEnvRef display contained '\a\w*'
75
76syn cluster rasiPropertyVals add=rasiEnv,rasiInvEnv,rasiInvEnvVar,rasiEnvVar
77" }}}
78
79" Color {{{
80syn keyword rasiColorK contained rgb[a] hsl[a] hwb[a] cmyk
81
82syn match rasiHexColor display contained '#\x\{3,4}'
83syn match rasiHexColor display contained '#\x\{6}'
84syn match rasiHexColor display contained '#\x\{8}'
85syn match rasiInvHexColor display contained '#\x\{5}\X'he=e-1,me=e-1
86syn match rasiInvHexColor display contained '#\x\{7}\X'he=e-1,me=e-1
87
88syn match rasiInvRGBColor display contained 'rgb\(a\)\?([^)]*)'
89syn match rasiRGBColor display contained transparent 'rgb\(a\)\?(\s*\d\+\s*\(%\)\?\s*,\(\s*\d\+\s*\(%\)\?\s*\){2}\(,\s*\(\d\(\.\d*\)\?\|\d\{,3}%\)\s*\)\?)' contains=rasiColorK,rasiNumber,rasiDistance
90
91syn match rasiInvHSLColor display contained 'h\(sl\|wb\)\(a\)\?([^)]*)'
92syn match rasiHSLColor display contained transparent 'h\(sl\|wb\)\(a\)\?(\s*\d\+\(\.\d*\)\?\(deg\|rad\|grad\|turn\)\?\s*\(,\s*\(\d\(\.\d*\)\?\|\d\{,3}%\)\s*\)\{2,3})' contains=rasiColorK,rasiNumber,rasiDistance
93
94
95"this matches doesn't works properly (too long ?)
96syn match rasiInvCMYKColor display contained 'cmyk([^)]*)'
97syn match rasiCMYKColor display contained transparent 'cmyk(\s*\(\d\(\.\d*\)\?\|\d\{,3}%\)\s*\(,\s*\(\d\(\.\d*\)\?\|\d\{,3}%\)\s*\)\{3,4})' contains=rasiColorK,rasiNumber,rasiDistance
98
99syn case ignore
100syn keyword rasiNamedColor contained
101 \ AliceBlue AntiqueWhite Aqua Aquamarine Azure Beige Bisque Black BlanchedAlmond Blue
102 \ BlueViolet Brown BurlyWood CadetBlue Chartreuse Chocolate Coral CornflowerBlue Cornsilk
103 \ Crimson Cyan DarkBlue DarkCyan DarkGoldenRod DarkGray DarkGrey DarkGreen DarkKhaki DarkMagenta
104 \ DarkOliveGreen DarkOrange DarkOrchid DarkRed DarkSalmon DarkSeaGreen Dark SlateBlue
105 \ DarkSlateGray DarkSlateGrey DarkTurquoise DarkViolet DeepPink DeepSkyBlue DimGray DimGrey
106 \ DodgerBlue FireBrick FloralWhite ForestGreen Fuchsia Gainsboro GhostWhite Gold GoldenRod
107 \ Gray Grey Green GreenYellow HoneyDew HotPink IndianRed Indigo Ivory Khaki Lavender
108 \ LavenderBlush LawnGreen LemonChiffon LightBlue LightCoral LightCyan LightGoldenRodYellow
109 \ LightGray LightGrey LightGreen LightPink LightSalmon LightSeaGreen LightSkyBlue LightSlateGray
110 \ LightSlateGrey LightSteelBlue LightYellow Lime LimeGreen Linen Magenta Maroon MediumAquaMarine
111 \ MediumBlue MediumOrchid MediumPurple MediumSeaGreen MediumSlateBlue MediumSpringGreen
112 \ MediumTurquoise MediumVioletRed MidnightBlue MintCream MistyRose Moccasin NavajoWhite Navy
113 \ OldLace Olive OliveDrab Orange OrangeRed Orchid PaleGoldenRod PaleGreen PaleTurquoise
114 \ PaleVioletRed PapayaWhip PeachPuff Peru Pink Plum PowderBlue Purple RebeccaPurple Red
115 \ RosyBrown RoyalBlue SaddleBrown Salmon SandyBrown SeaGreen SeaShell Sienna Silver SkyBlue
116 \ SlateBlue SlateGray SlateGrey Snow SpringGreen SteelBlue Tan Teal Thistle Tomato Turquoise
117 \ Violet Wheat White WhiteSmoke Yellow YellowGreen transparent[] "uses `[]` to escape keyword
118
119syn cluster rasiColors add=rasiHexColor,rasiRGBColor,rasiHSLColor,rasiCMYKColor,rasiNamedColor
120syn cluster rasiColors add=rasiInvHexColor,rasiInvRGBColor,rasiInvHSLColor,rasiInvCMYKColor
121
122syn cluster rasiPropertyVals add=@rasiColors
123" }}}
124
125" Text-Style {{{
126syn keyword rasiTextStyle contained bold italic underline strikethrough none
127
128syn cluster rasiPropertyVals add=rasiTextStyle
129" }}}
130
131" Line-Style {{{
132syn keyword rasiLineStyle contained dash solid
133
134syn cluster rasiPropertyVals add=rasiLineStyle
135" }}}
136
137" Distance {{{
138syn match rasiDistanceUnit display contained '\(px\|em\|ch\|%\|mm\)'
139
140syn match rasiInvDistance display contained '[+-]\?\d\+\.\d\+\(px\|mm\)'
141syn match rasiDistance display contained transparent '[-+]\?\d\+\(px\|mm\)' contains=rasiDistanceUnit,rasiNumber
142syn match rasiDistance display contained transparent '[+-]\?\d\+\(\.\d\+\)\?\(em\|ch\|%\)' contains=rasiDistanceUnit,rasiNumber
143
144syn keyword rasiDistanceCalc contained calc nextgroup=rasiDistanceCalcBody
145syn region rasiDistanceCalcBody display contained start=+(+ end=+)+ contains=rasiDistanceCalcOp,rasiDistance,rasiInvDistance
146syn match rasiDistanceCalcOp display contained '\(+\|-\|/\|\*\|%\|min\|max\)'
147
148syn cluster rasiPropertyVals add=rasiInvDistance,rasiDistance,rasiDistanceCalc
149" }}}
150
151" Position {{{
152syn keyword rasiPosition contained center east north west south
153
154syn cluster rasiPropertyVals add=rasiPosition
155" }}}
156
157" Orientation {{{
158syn keyword rasiOrientation contained horizontal vertical
159
160syn cluster rasiPropertyVals add=rasiOrientation
161" }}}
162
163" Cursor {{{
164syn keyword rasiCursor contained default pointer text
165
166syn cluster rasiPropertyVals add=rasiCursor
167" }}}
168
169" Keyword List {{{
170syn region rasiKeywordList contained start=+\[+ end=+\]+ contains=rasiPropertyIdRef
171
172syn cluster rasiPropertyVals add=rasiKeywordList
173" }}}
174
175" Inherit {{{
176syn keyword rasiInherit contained inherit children
177
178syn cluster rasiPropertyVals add=rasiInherit
179" }}}
180
181syn match rasiGlobalImport display '^\s*@\(import\|theme\)' nextgroup=rasiString skipwhite
182
183" Section {{{
184" syn region rasiSection transparent start='^[^{]\+{'me=e-1 end='}' contains=rasiSectionOpenning,rasiSectionContent
185syn match rasiSectionOpenning transparent '^[^{]\+{'me=e-1 contains=rasiGlobalSection,rasiWidgetName,rasiGlobalMedia nextgroup=rasiThemeSectionContent
186" syn match rasiThemeInnerSectionOpenning transparent '^[^:${]\+{'me=e-1 contains=rasiWidgetName nextgroup=rasiThemeInnerSectionContent contained
187
188syn match rasiGlobalMedia display contained '^\s*@media' nextgroup=rasiInvMediaBody,rasiMediaBody skipwhite
189syn match rasiInvMediaBody display contained '([^)]*)'
190syn match rasiMediaBody display contained '(\s*[a-z-]\+\s*:\s*\d\+\(px\|mm\)\?\s*)' contains=rasiMediaK,rasiNumber,rasiDistance
191syn keyword rasiMediaK contained min-width max-width min-height max-height min-aspect-ratio max-aspect-ratio monitor-id
192
193syn match rasiGlobalSection display contained '^*'
194syn match rasiWidgetName display contained '[a-zA-Z0-9-]\+' nextgroup=rasiVisibleMod skipwhite
195
196syn keyword rasiVisibleMod contained normal selected alternate nextgroup=rasiVisibleMod,rasiStateWrapper skipwhite
197syn match rasiStateWrapper display contained transparent '\.\(normal\|active\|urgent\)' contains=rasiState
198syn keyword rasiState contained normal active urgent
199
200
201syn region rasiThemeSectionContent transparent start="{" end="}" contains=rasiProperty,rasiComment,rasiCommentL,rasiSectionOpenning contained
202" syn region rasiThemeInnerSectionContent transparent start="{" end="}" contains=rasiProperty,rasiComment,rasiCommentL,rasiThemeInnerSectionOpenning contained
203
204syn match rasiProperty transparent '^\s*\S\+\s*:.*;\s*$' keepend contained contains=rasiPropertyId,rasiInvPropertyId,rasiPropertyVal,rasiComment,rasiCommentL
205syn match rasiInvPropertyId '^\([^:]\&[^/]\{2}\)*:'me=e-1 contained
206syn match rasiPropertyId '^\s*[0-9a-zA-Z-]\+\s*:'me=e-1 contained
207syn match rasiInvPropertyVal ':[^;];\s*\S\+\s*$'ms=s+1,hs=s+1
208syn match rasiPropertyVal ':\s*[^;]\+;\s*$'ms=s+1,hs=s+1 contained contains=@rasiPropertyVals
209" }}}
210
211" Comment {{{
212syn cluster rasiCommentGroup contains=rasiTodo,rasiBadContinuation
213
214syn region rasiCommentL start="//" skip="\\$" end="$" keepend contains=@rasiCommentGroup,@Spell
215syn region rasiComment start="/\*" end="\*/" contains=@rasiCommentGroup,rasiCommentStartError,@Spell fold extend
216
217syn match rasiCommentError display '\*/'
218
219syn keyword rasiTodo contained TODO FIXME XXX NOTE
220
221if exists("rasi_minlines")
222 let b:rasi_minlines = rasi_minlines
223else
224 let b:rasi_minlines = 50
225endif
226exec "syn sync ccomment rasiComment minlines=" . b:rasi_minlines
227" }}}
228
229
230
231" Highlighting: {{{
232hi def link rasiError Error
233
234hi def link rasiTodo Todo
235hi def link rasiComment Comment
236hi def link rasiCommentStart rasiComment
237hi def link rasiCommentL rasiComment
238hi def link rasiCommentError rasiError
239
240hi def link rasiString String
241hi def link rasiNumber Number
242hi def link rasiBool Boolean
243
244hi def link rasiImageK Function
245hi def link rasiImageScale Keyword
246hi def link rasiImageDirection Keyword
247hi def link rasiImageUnit Type
248hi def link rasiInvImage rasiError
249
250hi def link rasiHexColor Number
251hi def link rasiColorK Function
252hi def link rasiNamedColor Number
253hi def link rasiInvColor rasiError
254hi def link rasiInvHexColor rasiInvColor
255hi def link rasiInvRGBColor rasiInvColor
256hi def link rasiInvHSLColor rasiInvColor
257hi def link rasiInvCMYKColor rasiInvColor
258
259hi def link rasiTextStyle Keyword
260hi def link rasiLineStyle Keyword
261
262hi def link rasiDistanceUnit Type
263hi def link rasiDistanceCalc Function
264hi def link rasiDistanceCalcOp Operator
265hi def link rasiInvDistance rasiError
266
267hi def link rasiPosition Keyword
268hi def link rasiOrientation Keyword
269hi def link rasiCursor Keyword
270
271hi def link rasiReference Identifier
272hi def link rasiPropertyIdRef Identifier
273hi def link rasiVarReferenceK Function
274hi def link rasiInvVarReference rasiError
275
276hi def link rasiEnv Identifier
277hi def link rasiEnvRef Identifier
278hi def link rasiEnvVarK Function
279hi def link rasiInvEnv rasiError
280hi def link rasiInvEnvVar rasiError
281
282hi def link rasiWidgetName StorageClass
283hi def link rasiGlobalSection StorageClass
284hi def link rasiVisibleMod Type
285hi def link rasiState Tag
286
287hi def link rasiInherit Identifier
288
289hi def link rasiGlobalImport Include
290
291hi def link rasiGlobalMedia Preproc
292hi def link rasiMediaK Keyword
293hi def link rasiInvMediaBody rasiError
294
295hi def link rasiPropertyId Identifier
296hi def link rasiInvProperty rasiError
297hi def link rasiInvPropertyId rasiError
298hi def link rasiInvPropertyVal rasiError
299" }}}
300
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +0200301let &cpo = s:cpo_save
302unlet s:cpo_save
303
Pierrick Guillaume280e5b12024-05-31 12:00:49 +0200304" vim:ts=8