gift.vim 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. if version < 600
  9. syntax clear
  10. elseif exists("b:current_syntax")
  11. finish
  12. endif
  13. setlocal conceallevel=1
  14. "-----------------------------------------------
  15. " GIFT entities
  16. syn match giftS "\~" contained "GIFT special characters
  17. syn match giftS "=" contained
  18. syn match giftS "#" contained
  19. syn match giftS "{" contained
  20. syn match giftS "}" contained
  21. syn match giftS ":" contained
  22. syn match giftES "\\\~" contained conceal cchar=~ "GIFT escaped special characters
  23. syn match giftES "\\=" contained conceal cchar==
  24. syn match giftES "\\#" contained conceal cchar=#
  25. syn match giftES "\\{" contained conceal cchar={
  26. syn match giftES "\\}" contained conceal cchar=}
  27. syn match giftES "\\:" contained conceal cchar=:
  28. syn match giftEN "\\n" contained conceal cchar=n "GIFT escaped newline
  29. syn match giftFormat "\[html]" contained "GIFT formats
  30. syn match giftFormat "\[plain]" contained
  31. syn match giftFormat "\[moodle]" contained
  32. syn match giftFormat "\[markdown]" contained
  33. "--------------------------------------------------------
  34. " HTML entities
  35. syn match giftH "<" contained "HTML characters that might need to be handled/escaped
  36. syn match giftH ">" contained
  37. syn match giftH "&" contained
  38. syn match giftEH "&lt;" contained conceal cchar=< "HTML escaped characters
  39. syn match giftEH "&gt;" contained conceal cchar=>
  40. syn match giftEH "&amp;" contained conceal cchar=&
  41. syn match giftEH "&nbsp;" contained conceal cchar=_
  42. "-------------------------------------------------------
  43. " Answer components: Feedback and general feedback
  44. syn match giftFB "#\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|#\|####\|}\)" contained contains=giftF "Feedback block
  45. syn match giftF "#\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|#\|####\|}\)" contained contains=@giftCEF "Feedback
  46. syn match giftGFB "####\_.\{-}\(\_^\|[^\\]\)\ze}" contained contains=giftGF "General feedback block
  47. syn match giftGF "####\zs\_.\{-}\(\_^\|[^\\]\)\ze}" contained contains=@giftCEF "General feedback
  48. "------------------------------------------------------
  49. " Answer components: Other components
  50. syn keyword giftTF T TRUE F FALSE contained
  51. syn match giftNum1 "[-+]\=[.0-9]\+" contained "Something matching a number
  52. syn match giftNum2 "[-+]\=[.0-9]\+\s*:\s*[-+]\=[.0-9]\+" contained contains=giftNum2D "Number with error margin
  53. syn match giftNum2D ":" contained "Associated delimiter
  54. syn match giftNum3 "[-+]\=[.0-9]\+\s*\.\.\s*[-+]\=[.0-9]\+" contained contains=giftNum3D "Number as min/max range
  55. syn match giftNum3D "\.\." contained "Associated delimiter
  56. syn match giftWeightB "%-*[0-9]\{1,2}\.\?[0-9]*%" contained contains=giftWeight "Weight block
  57. syn match giftWeight "%\zs-*[0-9]\{1,2}\.\?[0-9]*\ze%" contained "Weight
  58. "-----------------------------------------------------
  59. " Answer choices
  60. syn match giftWrongNum "\~\zs\_.\{-}\(\_^\|[^\\]\)\ze\(####\|}\)" contained contains=@giftCEFF "Wrong numeric choice
  61. syn match giftRightNum "=\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCEFFW,@giftNums "Right numeric choice
  62. syn match giftWrong "\~\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCEFFW "Wrong choice
  63. syn match giftRight "=\zs\_.\{-}\(\ze->\|\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)\)" contained contains=@giftCEFFW "Right choice
  64. syn match giftMatchB "->\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=giftMatch "Match choice block
  65. syn match giftMatch "->\zs\_.\{-}\(\_^\|[^\\]\)\ze\(=\|\~\|####\|}\)" contained contains=@giftCE "Match choice
  66. "----------------------------------------------------
  67. " Answer
  68. syn match giftAnswer "{\_.\{-}\(\_^\|[^\\]\)}" contained keepend contains=@giftA "General answer
  69. syn match giftAnswer "{}" contained "Minimal answer
  70. syn match giftAnswerNum "{\_[[:space:]]*#\_[^#]\_.\{-}\(\_^\|[^\\]\)}" contained keepend contains=@giftANum "Numeric answer
  71. syn match giftAnswerNumD "{\zs\_[[:space:]]*#" contained "Associated delimiter
  72. "---------------------------------------------------
  73. " Question
  74. " The first pattern matches the last question at the end of the file (in case there is no empty line coming after).
  75. " However, it slows down parsing (and especially scrolling up), therefore it is commented out.
  76. "syn match giftQuestion "[^{[:space:]]\_.\{-}\%$" keepend contains=@giftCEF,giftAnswer,giftAnswerNum
  77. syn match giftQuestion "[^{[:space:]]\_.\{-}\n\(\s*\n\)\+" keepend contains=@giftCEF,giftAnswer,giftAnswerNum
  78. "--------------------------------------------------
  79. " Question name
  80. syn match giftName "::\_.\{-}::" contains=@giftCE,giftNameD "Question name
  81. syn match giftNameD "::" contained "Associated delimiter
  82. "-------------------------------------------------
  83. " Category
  84. syn match giftCategoryB "^\s*\$CATEGORY:.*\n\+" contains=giftCategory "Category block
  85. syn match giftCategory "^\s*\$CATEGORY:\zs.*\ze\n" contained "Category
  86. "------------------------------------------------
  87. " Comments (may need to be the last entity)
  88. syn keyword giftTodo FIXME TODO NOTE FIX XXX contained
  89. syn match giftIdB "\[id:\(\\]\|[^][:cntrl:]]\)\+]" contained contains=giftId "Id block
  90. syn match giftId "\[id:\zs\(\\]\|[^][:cntrl:]]\)\+\ze]" contained "Id
  91. syn match giftTagB "\[tag:\(\\]\|[^]<>`[:cntrl:]]\)\+]" contained contains=giftTag "Tag block
  92. syn match giftTag "\[tag:\zs\(\\]\|[^]<>`[:cntrl:]]\)\+\ze]" contained "Tag
  93. syn match giftComment "^\s*//.*" contains=giftTodo,giftIdB,giftTagB
  94. "-----------------------------------------------
  95. " Clusters
  96. "Comments and entities (to be escaped)
  97. syn cluster giftCE contains=giftComment,giftS,giftES,giftEN,giftH,giftEH
  98. "The above plus format
  99. syn cluster giftCEF contains=@giftCE,giftFormat
  100. "The above plus feedback block
  101. syn cluster giftCEFF contains=@giftCEF,giftFB
  102. "The above plus weight block
  103. syn cluster giftCEFFW contains=@giftCEFF,giftWeightB
  104. "Possible numerical representations
  105. syn cluster giftNums contains=giftNum1,giftNum2,giftNum3
  106. "Possible contents of answers
  107. syn cluster giftA contains=giftComment,giftTF,giftWrong,giftRight,giftMatchB,giftFB,giftGFB
  108. "Possible contents of numerical answers
  109. syn cluster giftANum contains=giftAnswerNumD,giftComment,@giftNums,giftWrongNum,giftRightNum,giftFB,giftGFB
  110. "-----------------------------------------------
  111. let b:current_syntax = "gift"
  112. "-----------------------------------------------
  113. hi Conceal ctermbg=NONE ctermfg=Blue guibg=NONE guifg=Blue
  114. hi Feedback ctermbg=NONE ctermfg=DarkCyan guibg=NONE guifg=DarkCyan
  115. hi GFeedback ctermbg=NONE ctermfg=DarkGreen guibg=NONE guifg=DarkGreen
  116. hi WeightB ctermbg=NONE ctermfg=DarkYellow guibg=NONE guifg=DarkYellow
  117. "-----------------------------------------------
  118. hi def link giftS Error
  119. hi def link giftES Conceal
  120. hi def link giftEN Conceal
  121. hi def link giftFormat LineNr
  122. hi def link giftH Error
  123. hi def link giftEH Conceal
  124. hi def link giftFB PreProc
  125. hi def link giftF Feedback
  126. hi def link giftGFB Title
  127. hi def link giftGF GFeedback
  128. hi def link giftTF Question
  129. hi def link giftNum1 Question
  130. hi def link giftNum2 Question
  131. hi def link giftNum2D Special
  132. hi def link giftNum3 Question
  133. hi def link giftNum3D Special
  134. hi def link giftWeightB WeightB
  135. hi def link giftWeight Identifier
  136. hi def link giftWrongNum Constant
  137. hi def link giftRightNum Question
  138. hi def link giftWrong Constant
  139. hi def link giftRight Question
  140. hi def link giftMatchB ModeMsg
  141. hi def link giftMatch Constant
  142. hi def link giftAnswer MoreMsg
  143. hi def link giftAnswerNum MoreMsg
  144. hi def link giftAnswerNumD Identifier
  145. hi def link giftQuestion Identifier
  146. hi def link giftName PreProc
  147. hi def link giftNameD Directory
  148. hi def link giftCategoryB LineNr
  149. hi def link giftCategory Directory
  150. hi def link giftTodo Todo
  151. hi def link giftIdB LineNr
  152. hi def link giftId Title
  153. hi def link giftTagB LineNr
  154. hi def link giftTag Constant
  155. hi def link giftComment Comment