23466
|
1 " Vim syntax file
|
|
2 "
|
|
3 " Language: Moodle GIFT (General Import Format Template)
|
|
4 " Maintainer: Selim Temizer (http://selimtemizer.com)
|
|
5 " Creation: November 28, 2020
|
|
6 " Latest Revision: December 21, 2020
|
|
7 " Note: The order of entities in this file is important!
|
|
8
|
|
9 if version < 600
|
|
10 syntax clear
|
|
11 elseif exists("b:current_syntax")
|
|
12 finish
|
|
13 endif
|
|
14
|
|
15
|
|
16 setlocal conceallevel=1
|
|
17
|
|
18 "-----------------------------------------------
|
|
19 " GIFT entities
|
|
20
|
|
21 syn match giftS "\~" contained "GIFT special characters
|
|
22 syn match giftS "=" contained
|
|
23 syn match giftS "#" contained
|
|
24 syn match giftS "{" contained
|
|
25 syn match giftS "}" contained
|
|
26 syn match giftS ":" contained
|
|
27
|
|
28 syn match giftES "\\\~" contained conceal cchar=~ "GIFT escaped special characters
|
|
29 syn match giftES "\\=" contained conceal cchar==
|
|
30 syn match giftES "\\#" contained conceal cchar=#
|
|
31 syn match giftES "\\{" contained conceal cchar={
|
|
32 syn match giftES "\\}" contained conceal cchar=}
|
|
33 syn match giftES "\\:" contained conceal cchar=:
|
|
34
|
|
35 syn match giftEN "\\n" contained conceal cchar=n "GIFT escaped newline
|
|
36
|
|
37 syn match giftFormat "\[html]" contained "GIFT formats
|
|
38 syn match giftFormat "\[plain]" contained
|
|
39 syn match giftFormat "\[moodle]" contained
|
|
40 syn match giftFormat "\[markdown]" contained
|
|
41
|
|
42 "--------------------------------------------------------
|
|
43 " HTML entities
|
|
44
|
|
45 syn match giftH "<" contained "HTML characters that might need to be handled/escaped
|
|
46 syn match giftH ">" contained
|
|
47 syn match giftH "&" contained
|
|
48
|
|
49 syn match giftEH "<" contained conceal cchar=< "HTML escaped characters
|
|
50 syn match giftEH ">" contained conceal cchar=>
|
|
51 syn match giftEH "&" contained conceal cchar=&
|
|
52 syn match giftEH " " contained conceal cchar=_
|
|
53
|
|
54 "-------------------------------------------------------
|
|
55 " Answer components: Feedback and general feedback
|
|
56
|
|
57 syn match giftFB "#\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|#\|####\|}\)" contained contains=giftF "Feedback block
|
|
58 syn match giftF "#\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|#\|####\|}\)" contained contains=@giftCEF "Feedback
|
|
59
|
|
60 syn match giftGFB "####\_.\{-}\(\_^\|[^\\]\)\ze}" contained contains=giftGF "General feedback block
|
|
61 syn match giftGF "####\zs\_.\{-}\(\_^\|[^\\]\)\ze}" contained contains=@giftCEF "General feedback
|
|
62
|
|
63 "------------------------------------------------------
|
|
64 " Answer components: Other components
|
|
65
|
|
66 syn keyword giftTF T TRUE F FALSE contained
|
|
67
|
|
68 syn match giftNum1 "[-+]\=[.0-9]\+" contained "Something matching a number
|
|
69
|
|
70 syn match giftNum2 "[-+]\=[.0-9]\+\s*:\s*[-+]\=[.0-9]\+" contained contains=giftNum2D "Number with error margin
|
|
71 syn match giftNum2D ":" contained "Associated delimiter
|
|
72
|
|
73 syn match giftNum3 "[-+]\=[.0-9]\+\s*\.\.\s*[-+]\=[.0-9]\+" contained contains=giftNum3D "Number as min/max range
|
|
74 syn match giftNum3D "\.\." contained "Associated delimiter
|
|
75
|
|
76 syn match giftWeightB "%-*[0-9]\{1,2}\.\?[0-9]*%" contained contains=giftWeight "Weight block
|
|
77 syn match giftWeight "%\zs-*[0-9]\{1,2}\.\?[0-9]*\ze%" contained "Weight
|
|
78
|
|
79 "-----------------------------------------------------
|
|
80 " Answer choices
|
|
81
|
|
82 syn match giftWrongNum "\~\zs\_.\{-}\(\_^\|[^\\]\)\ze\(####\|}\)" contained contains=@giftCEFF "Wrong numeric choice
|
|
83 syn match giftRightNum "=\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCEFFW,@giftNums "Right numeric choice
|
|
84
|
|
85 syn match giftWrong "\~\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCEFFW "Wrong choice
|
|
86 syn match giftRight "=\zs\_.\{-}\(\ze->\|\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)\)" contained contains=@giftCEFFW "Right choice
|
|
87 syn match giftMatchB "->\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=giftMatch "Match choice block
|
|
88 syn match giftMatch "->\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCE "Match choice
|
|
89
|
|
90 "----------------------------------------------------
|
|
91 " Answer
|
|
92
|
|
93 syn match giftAnswer "{\_.\{-}\(\_^\|[^\\]\)}" contained keepend contains=@giftA "General answer
|
|
94 syn match giftAnswer "{}" contained "Minimal answer
|
|
95
|
|
96 syn match giftAnswerNum "{\_[[:space:]]*#\_[^#]\_.\{-}\(\_^\|[^\\]\)}" contained keepend contains=@giftANum "Numeric answer
|
|
97 syn match giftAnswerNumD "{\zs\_[[:space:]]*#" contained "Associated delimiter
|
|
98
|
|
99 "---------------------------------------------------
|
|
100 " Question
|
|
101
|
|
102 " The first pattern matches the last question at the end of the file (in case there is no empty line coming after).
|
|
103 " However, it slows down parsing (and especially scrolling up), therefore it is commented out.
|
|
104
|
|
105 "syn match giftQuestion "[^{[:space:]]\_.\{-}\%$" keepend contains=@giftCEF,giftAnswer,giftAnswerNum
|
|
106 syn match giftQuestion "[^{[:space:]]\_.\{-}\n\(\s*\n\)\+" keepend contains=@giftCEF,giftAnswer,giftAnswerNum
|
|
107
|
|
108 "--------------------------------------------------
|
|
109 " Question name
|
|
110
|
|
111 syn match giftName "::\_.\{-}::" contains=@giftCE,giftNameD "Question name
|
|
112 syn match giftNameD "::" contained "Associated delimiter
|
|
113
|
|
114 "-------------------------------------------------
|
|
115 " Category
|
|
116
|
|
117 syn match giftCategoryB "^\s*\$CATEGORY:.*\n\+" contains=giftCategory "Category block
|
|
118 syn match giftCategory "^\s*\$CATEGORY:\zs.*\ze\n" contained "Category
|
|
119
|
|
120 "------------------------------------------------
|
|
121 " Comments (may need to be the last entity)
|
|
122
|
|
123 syn keyword giftTodo FIXME TODO NOTE FIX XXX contained
|
|
124
|
|
125 syn match giftIdB "\[id:\(\\]\|[^][:cntrl:]]\)\+]" contained contains=giftId "Id block
|
|
126 syn match giftId "\[id:\zs\(\\]\|[^][:cntrl:]]\)\+\ze]" contained "Id
|
|
127
|
|
128 syn match giftTagB "\[tag:\(\\]\|[^]<>`[:cntrl:]]\)\+]" contained contains=giftTag "Tag block
|
|
129 syn match giftTag "\[tag:\zs\(\\]\|[^]<>`[:cntrl:]]\)\+\ze]" contained "Tag
|
|
130
|
|
131 syn match giftComment "^\s*//.*" contains=giftTodo,giftIdB,giftTagB
|
|
132
|
|
133 "-----------------------------------------------
|
|
134 " Clusters
|
|
135
|
|
136 "Comments and entities (to be escaped)
|
|
137 syn cluster giftCE contains=giftComment,giftS,giftES,giftEN,giftH,giftEH
|
|
138
|
|
139 "The above plus format
|
|
140 syn cluster giftCEF contains=@giftCE,giftFormat
|
|
141
|
|
142 "The above plus feedback block
|
|
143 syn cluster giftCEFF contains=@giftCEF,giftFB
|
|
144
|
|
145 "The above plus weight block
|
|
146 syn cluster giftCEFFW contains=@giftCEFF,giftWeightB
|
|
147
|
|
148 "Possible numerical representations
|
|
149 syn cluster giftNums contains=giftNum1,giftNum2,giftNum3
|
|
150
|
|
151 "Possible contents of answers
|
|
152 syn cluster giftA contains=giftComment,giftTF,giftWrong,giftRight,giftMatchB,giftFB,giftGFB
|
|
153
|
|
154 "Possible contents of numerical answers
|
|
155 syn cluster giftANum contains=giftAnswerNumD,giftComment,@giftNums,giftWrongNum,giftRightNum,giftFB,giftGFB
|
|
156
|
|
157 "-----------------------------------------------
|
|
158
|
|
159 let b:current_syntax = "gift"
|
|
160
|
|
161 "-----------------------------------------------
|
|
162
|
|
163 hi Conceal ctermbg=NONE ctermfg=Blue guibg=NONE guifg=Blue
|
|
164 hi Feedback ctermbg=NONE ctermfg=DarkCyan guibg=NONE guifg=DarkCyan
|
|
165 hi GFeedback ctermbg=NONE ctermfg=DarkGreen guibg=NONE guifg=DarkGreen
|
|
166 hi WeightB ctermbg=NONE ctermfg=DarkYellow guibg=NONE guifg=DarkYellow
|
|
167
|
|
168 "-----------------------------------------------
|
|
169
|
|
170 hi def link giftS Error
|
|
171 hi def link giftES Conceal
|
|
172 hi def link giftEN Conceal
|
|
173 hi def link giftFormat LineNr
|
|
174
|
|
175 hi def link giftH Error
|
|
176 hi def link giftEH Conceal
|
|
177
|
|
178 hi def link giftFB PreProc
|
|
179 hi def link giftF Feedback
|
|
180 hi def link giftGFB Title
|
|
181 hi def link giftGF GFeedback
|
|
182
|
|
183 hi def link giftTF Question
|
|
184 hi def link giftNum1 Question
|
|
185 hi def link giftNum2 Question
|
|
186 hi def link giftNum2D Special
|
|
187 hi def link giftNum3 Question
|
|
188 hi def link giftNum3D Special
|
|
189 hi def link giftWeightB WeightB
|
|
190 hi def link giftWeight Identifier
|
|
191
|
|
192 hi def link giftWrongNum Constant
|
|
193 hi def link giftRightNum Question
|
|
194 hi def link giftWrong Constant
|
|
195 hi def link giftRight Question
|
|
196 hi def link giftMatchB ModeMsg
|
|
197 hi def link giftMatch Constant
|
|
198
|
|
199 hi def link giftAnswer MoreMsg
|
|
200 hi def link giftAnswerNum MoreMsg
|
|
201 hi def link giftAnswerNumD Identifier
|
|
202
|
|
203 hi def link giftQuestion Identifier
|
|
204
|
|
205 hi def link giftName PreProc
|
|
206 hi def link giftNameD Directory
|
|
207
|
|
208 hi def link giftCategoryB LineNr
|
|
209 hi def link giftCategory Directory
|
|
210
|
|
211 hi def link giftTodo Todo
|
|
212 hi def link giftIdB LineNr
|
|
213 hi def link giftId Title
|
|
214 hi def link giftTagB LineNr
|
|
215 hi def link giftTag Constant
|
|
216 hi def link giftComment Comment
|