robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
4.8 KiB115 linesraw
1" Vim syntax file
2" Language:             iCalendar
3" Maintainer:           Anakin Childerhose <anakin@childerhose.ca>
4" Latest Change:        2026 Sept 22
5" License:              Vim (see :h license)
6
7if exists("b:current_syntax")
8  finish
9endif
10
11let s:cpo_save = &cpo
12set cpo&vim
13
14syntax sync minlines=150
15
16" component delineating content lines {{{
17"
18"  BEGIN:VCALENDAR
19"  ^^^^^ icalendarComponentBegin
20"       ^ icalendarComponentSeparator
21"        ^^^^^^^^^ icalendarComponentType
22"  END:VCALENDAR
23"  ^^^ icalendarComponentEnd
24"     ^ icalendarComponentSeparator
25"      ^^^^^^^^^ icalendarComponentType
26"
27" Line folding in these lines is technically valid but rare so it is ignored to
28" keep the following lines simpler
29syntax keyword icalendarComponentBegin BEGIN nextgroup=icalendarComponentSeparator
30syntax keyword icalendarComponentEnd END nextgroup=icalendarComponentSeparator
31syntax match icalendarComponentSeparator ":" contained nextgroup=icalendarComponentType
32syntax match icalendarComponentType "\w\+" contained
33" component delineating content lines }}}
34
35
36" property content lines {{{
37"
38"  TRIGGER;RELATED=START:-PT10M
39"  ^^^^^^^ icalendarPropertyName
40"         ^ icalendarParamSeparator
41"          ^^^^^^^ icalendarPropertyParamName
42"                 ^ icalendarParamEquals
43"                  ^^^^^ icalendarPropertyParamValue
44"                       ^ icalendarPropertySeparator
45"                        ^^^^^^ icalendarPropertyValue
46"
47" Line folding can occur between any two characters so practically every match
48" needs to support possible folds
49
50let s:fold = '\n[ \t]'
51let s:prop_chars = '[A-Za-z0-9-]'
52let s:name_regex = $'\({s:prop_chars}\|{s:fold}\)*'
53let s:safe_chars = '[^";:,]'
54
55execute $'syntax match icalendarPropertyName "^{s:name_regex}" nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
56execute $'syntax match icalendarParamSeparator ";\({s:fold}\)*" contained nextgroup=icalendarPropertyParamName'
57execute $'syntax match icalendarPropertyParamName "{s:name_regex}" contained nextgroup=icalendarParamEquals'
58execute $'syntax match icalendarParamEquals "=\({s:fold}\)*" contained nextgroup=icalendarPropertyParamValue'
59" collect safe chars and folds
60execute $'syntax match icalendarPropertyParamValue "\({s:safe_chars}\|{s:fold}\)\+" contained nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
61" unsafe chars need to be quoted:
62" if a value starts with a double quote, ", collect all characters upto the next
63" double quote, [^"]*, including newlines, \_ followed by zero or more folds
64execute $'syntax match icalendarPropertyParamValue "\"\_[^\"]*\"\({s:fold}\)*" contained nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
65execute $'syntax match icalendarPropertySeparator ":\({s:fold}\)*" contained nextgroup=icalendarPropertyValue'
66execute $'syntax match icalendarPropertyValue "\([^\n]\|{s:fold}\)*" contained'
67" property content lines }}}
68
69
70" recurring rules {{{
71"
72"  RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU
73"  ^^^^^ icalendarRrule
74"       ^ icalendarRruleSeparator
75"        ^^^^ icalendarRruleParamName
76"            ^ icalendarRruleEquals
77"             ^^^^^^ icalendarRruleParamValue
78"                   ^ icalendarRruleParamSeparator
79"
80let s:rrule_chars = '[A-Za-z0-9-+,]'
81
82syntax keyword icalendarRrule RRULE nextgroup=icalendarRruleSeparator
83execute $'syntax match icalendarRruleSeparator ":\({s:fold}\)*" contained nextgroup=icalendarRruleParamName'
84execute $'syntax match icalendarRruleParamName "{s:name_regex}" contained nextgroup=icalendarRruleEquals'
85execute $'syntax match icalendarRruleEquals "=\({s:fold}\)*" contained nextgroup=icalendarRruleParamValue'
86execute $'syntax match icalendarRruleParamValue "\({s:rrule_chars}\|{s:fold}\)\+" contained nextgroup=icalendarRruleParamSeparator'
87execute $'syntax match icalendarRruleParamSeparator ";\({s:fold}\)*" contained nextgroup=icalendarRruleParamName'
88" recurring rules }}}
89
90highlight default link icalendarComponentBegin Structure
91highlight default link icalendarComponentEnd Structure
92highlight default link icalendarComponentSeparator Operator
93highlight default link icalendarComponentType Type
94
95highlight default link icalendarPropertyName Identifier
96highlight default link icalendarParamSeparator Operator
97highlight default link icalendarPropertyParamName Type
98highlight default link icalendarParamEquals Operator
99highlight default link icalendarPropertyParamValue String
100highlight default link icalendarPropertySeparator Operator
101highlight default link icalendarPropertyValue Constant
102
103highlight default link icalendarRrule Identifier
104highlight default link icalendarRruleSeparator Operator
105highlight default link icalendarRruleParamName Type
106highlight default link icalendarRruleEquals Operator
107highlight default link icalendarRruleParamValue String
108highlight default link icalendarRruleParamSeparator Operator
109
110let b:current_syntax = "icalendar"
111
112let &cpo = s:cpo_save
113unlet s:cpo_save
114
115" vim: fdm=marker