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