PageRenderTime 62ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/syntax/lua.vim

https://github.com/silentdragonz/vim
Vim Script | 304 lines | 232 code | 30 blank | 42 comment | 38 complexity | 3582e98c4324b13e88e8adfa88895aab MD5 | raw file
  1. " Vim syntax file
  2. " Language: Lua 4.0, Lua 5.0 and Lua 5.1
  3. " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol com br>
  4. " First Author: Carlos Augusto Teixeira Mendes <cmendes 'at' inf puc-rio br>
  5. " Last Change: 2006 Aug 10
  6. " Options: lua_version = 4 or 5
  7. " lua_subversion = 0 (4.0, 5.0) or 1 (5.1)
  8. " default 5.1
  9. " For version 5.x: Clear all syntax items
  10. " For version 6.x: Quit when a syntax file was already loaded
  11. if version < 600
  12. syntax clear
  13. elseif exists("b:current_syntax")
  14. finish
  15. endif
  16. if !exists("lua_version")
  17. " Default is lua 5.1
  18. let lua_version = 5
  19. let lua_subversion = 1
  20. elseif !exists("lua_subversion")
  21. " lua_version exists, but lua_subversion doesn't. So, set it to 0
  22. let lua_subversion = 0
  23. endif
  24. syn case match
  25. " syncing method
  26. syn sync minlines=100
  27. " Comments
  28. syn keyword luaTodo contained TODO FIXME XXX
  29. syn match luaComment "--.*$" contains=luaTodo,@Spell
  30. if lua_version == 5 && lua_subversion == 0
  31. syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment,@Spell
  32. syn region luaInnerComment contained transparent start="\[\[" end="\]\]"
  33. elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1)
  34. " Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc.
  35. syn region luaComment matchgroup=luaComment start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaTodo,@Spell
  36. endif
  37. " First line may start with #!
  38. syn match luaComment "\%^#!.*"
  39. " catch errors caused by wrong parenthesis and wrong curly brackets or
  40. " keywords placed outside their respective blocks
  41. syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaError,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
  42. syn match luaError ")"
  43. syn match luaError "}"
  44. syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>"
  45. " Function declaration
  46. syn region luaFunctionBlock transparent matchgroup=luaFunction start="\<function\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
  47. " if then else elseif end
  48. syn keyword luaCond contained else
  49. " then ... end
  50. syn region luaCondEnd contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaRepeat
  51. " elseif ... then
  52. syn region luaCondElseif contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
  53. " if ... then
  54. syn region luaCondStart transparent matchgroup=luaCond start="\<if\>" end="\<then\>"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaCondEnd skipwhite skipempty
  55. " do ... end
  56. syn region luaBlock transparent matchgroup=luaStatement start="\<do\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
  57. " repeat ... until
  58. syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
  59. " while ... do
  60. syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<while\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaBlock skipwhite skipempty
  61. " for ... do and for ... in ... do
  62. syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<for\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd nextgroup=luaBlock skipwhite skipempty
  63. " Following 'else' example. This is another item to those
  64. " contains=ALLBUT,... because only the 'for' luaRepeatBlock contains it.
  65. syn keyword luaRepeat contained in
  66. " other keywords
  67. syn keyword luaStatement return local break
  68. syn keyword luaOperator and or not
  69. syn keyword luaConstant nil
  70. if lua_version > 4
  71. syn keyword luaConstant true false
  72. endif
  73. " Strings
  74. if lua_version < 5
  75. syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}"
  76. elseif lua_version == 5 && lua_subversion == 0
  77. syn match luaSpecial contained "\\[\\abfnrtv\'\"[\]]\|\\\d\{,3}"
  78. syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell
  79. elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1)
  80. syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}"
  81. syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell
  82. endif
  83. syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell
  84. syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell
  85. " integer number
  86. syn match luaNumber "\<\d\+\>"
  87. " floating point number, with dot, optional exponent
  88. syn match luaFloat "\<\d\+\.\d*\%(e[-+]\=\d\+\)\=\>"
  89. " floating point number, starting with a dot, optional exponent
  90. syn match luaFloat "\.\d\+\%(e[-+]\=\d\+\)\=\>"
  91. " floating point number, without dot, with exponent
  92. syn match luaFloat "\<\d\+e[-+]\=\d\+\>"
  93. " hex numbers
  94. if lua_version > 5 || (lua_version == 5 && lua_subversion >= 1)
  95. syn match luaNumber "\<0x\x\+\>"
  96. endif
  97. " tables
  98. syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
  99. syn keyword luaFunc assert collectgarbage dofile error next
  100. syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION
  101. if lua_version == 4
  102. syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo
  103. syn keyword luaFunc call copytagmethods dostring
  104. syn keyword luaFunc foreach foreachi getglobal getn
  105. syn keyword luaFunc gettagmethod globals newtag
  106. syn keyword luaFunc setglobal settag settagmethod sort
  107. syn keyword luaFunc tag tinsert tremove
  108. syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR
  109. syn keyword luaFunc openfile closefile flush seek
  110. syn keyword luaFunc setlocale execute remove rename tmpname
  111. syn keyword luaFunc getenv date clock exit
  112. syn keyword luaFunc readfrom writeto appendto read write
  113. syn keyword luaFunc PI abs sin cos tan asin
  114. syn keyword luaFunc acos atan atan2 ceil floor
  115. syn keyword luaFunc mod frexp ldexp sqrt min max log
  116. syn keyword luaFunc log10 exp deg rad random
  117. syn keyword luaFunc randomseed strlen strsub strlower strupper
  118. syn keyword luaFunc strchar strrep ascii strbyte
  119. syn keyword luaFunc format strfind gsub
  120. syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook
  121. elseif lua_version == 5
  122. " Not sure if all these functions need to be highlighted...
  123. syn keyword luaFunc _G getfenv getmetatable ipairs loadfile
  124. syn keyword luaFunc loadstring pairs pcall rawequal
  125. syn keyword luaFunc require setfenv setmetatable unpack xpcall
  126. if lua_subversion == 0
  127. syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME
  128. elseif lua_subversion == 1
  129. syn keyword luaFunc load module select
  130. syn match luaFunc /package\.cpath/
  131. syn match luaFunc /package\.loaded/
  132. syn match luaFunc /package\.loadlib/
  133. syn match luaFunc /package\.path/
  134. syn match luaFunc /package\.preload/
  135. syn match luaFunc /package\.seeall/
  136. syn match luaFunc /coroutine\.running/
  137. endif
  138. syn match luaFunc /coroutine\.create/
  139. syn match luaFunc /coroutine\.resume/
  140. syn match luaFunc /coroutine\.status/
  141. syn match luaFunc /coroutine\.wrap/
  142. syn match luaFunc /coroutine\.yield/
  143. syn match luaFunc /string\.byte/
  144. syn match luaFunc /string\.char/
  145. syn match luaFunc /string\.dump/
  146. syn match luaFunc /string\.find/
  147. syn match luaFunc /string\.len/
  148. syn match luaFunc /string\.lower/
  149. syn match luaFunc /string\.rep/
  150. syn match luaFunc /string\.sub/
  151. syn match luaFunc /string\.upper/
  152. syn match luaFunc /string\.format/
  153. syn match luaFunc /string\.gsub/
  154. if lua_subversion == 0
  155. syn match luaFunc /string\.gfind/
  156. syn match luaFunc /table\.getn/
  157. syn match luaFunc /table\.setn/
  158. syn match luaFunc /table\.foreach/
  159. syn match luaFunc /table\.foreachi/
  160. elseif lua_subversion == 1
  161. syn match luaFunc /string\.gmatch/
  162. syn match luaFunc /string\.match/
  163. syn match luaFunc /string\.reverse/
  164. syn match luaFunc /table\.maxn/
  165. endif
  166. syn match luaFunc /table\.concat/
  167. syn match luaFunc /table\.sort/
  168. syn match luaFunc /table\.insert/
  169. syn match luaFunc /table\.remove/
  170. syn match luaFunc /math\.abs/
  171. syn match luaFunc /math\.acos/
  172. syn match luaFunc /math\.asin/
  173. syn match luaFunc /math\.atan/
  174. syn match luaFunc /math\.atan2/
  175. syn match luaFunc /math\.ceil/
  176. syn match luaFunc /math\.sin/
  177. syn match luaFunc /math\.cos/
  178. syn match luaFunc /math\.tan/
  179. syn match luaFunc /math\.deg/
  180. syn match luaFunc /math\.exp/
  181. syn match luaFunc /math\.floor/
  182. syn match luaFunc /math\.log/
  183. syn match luaFunc /math\.log10/
  184. syn match luaFunc /math\.max/
  185. syn match luaFunc /math\.min/
  186. if lua_subversion == 0
  187. syn match luaFunc /math\.mod/
  188. elseif lua_subversion == 1
  189. syn match luaFunc /math\.fmod/
  190. syn match luaFunc /math\.modf/
  191. syn match luaFunc /math\.cosh/
  192. syn match luaFunc /math\.sinh/
  193. syn match luaFunc /math\.tanh/
  194. endif
  195. syn match luaFunc /math\.pow/
  196. syn match luaFunc /math\.rad/
  197. syn match luaFunc /math\.sqrt/
  198. syn match luaFunc /math\.frexp/
  199. syn match luaFunc /math\.ldexp/
  200. syn match luaFunc /math\.random/
  201. syn match luaFunc /math\.randomseed/
  202. syn match luaFunc /math\.pi/
  203. syn match luaFunc /io\.stdin/
  204. syn match luaFunc /io\.stdout/
  205. syn match luaFunc /io\.stderr/
  206. syn match luaFunc /io\.close/
  207. syn match luaFunc /io\.flush/
  208. syn match luaFunc /io\.input/
  209. syn match luaFunc /io\.lines/
  210. syn match luaFunc /io\.open/
  211. syn match luaFunc /io\.output/
  212. syn match luaFunc /io\.popen/
  213. syn match luaFunc /io\.read/
  214. syn match luaFunc /io\.tmpfile/
  215. syn match luaFunc /io\.type/
  216. syn match luaFunc /io\.write/
  217. syn match luaFunc /os\.clock/
  218. syn match luaFunc /os\.date/
  219. syn match luaFunc /os\.difftime/
  220. syn match luaFunc /os\.execute/
  221. syn match luaFunc /os\.exit/
  222. syn match luaFunc /os\.getenv/
  223. syn match luaFunc /os\.remove/
  224. syn match luaFunc /os\.rename/
  225. syn match luaFunc /os\.setlocale/
  226. syn match luaFunc /os\.time/
  227. syn match luaFunc /os\.tmpname/
  228. syn match luaFunc /debug\.debug/
  229. syn match luaFunc /debug\.gethook/
  230. syn match luaFunc /debug\.getinfo/
  231. syn match luaFunc /debug\.getlocal/
  232. syn match luaFunc /debug\.getupvalue/
  233. syn match luaFunc /debug\.setlocal/
  234. syn match luaFunc /debug\.setupvalue/
  235. syn match luaFunc /debug\.sethook/
  236. syn match luaFunc /debug\.traceback/
  237. if lua_subversion == 1
  238. syn match luaFunc /debug\.getfenv/
  239. syn match luaFunc /debug\.getmetatable/
  240. syn match luaFunc /debug\.getregistry/
  241. syn match luaFunc /debug\.setfenv/
  242. syn match luaFunc /debug\.setmetatable/
  243. endif
  244. endif
  245. " Define the default highlighting.
  246. " For version 5.7 and earlier: only when not done already
  247. " For version 5.8 and later: only when an item doesn't have highlighting yet
  248. if version >= 508 || !exists("did_lua_syntax_inits")
  249. if version < 508
  250. let did_lua_syntax_inits = 1
  251. command -nargs=+ HiLink hi link <args>
  252. else
  253. command -nargs=+ HiLink hi def link <args>
  254. endif
  255. HiLink luaStatement Statement
  256. HiLink luaRepeat Repeat
  257. HiLink luaString String
  258. HiLink luaString2 String
  259. HiLink luaNumber Number
  260. HiLink luaFloat Float
  261. HiLink luaOperator Operator
  262. HiLink luaConstant Constant
  263. HiLink luaCond Conditional
  264. HiLink luaFunction Function
  265. HiLink luaComment Comment
  266. HiLink luaTodo Todo
  267. HiLink luaTable Structure
  268. HiLink luaError Error
  269. HiLink luaSpecial SpecialChar
  270. HiLink luaFunc Identifier
  271. delcommand HiLink
  272. endif
  273. let b:current_syntax = "lua"
  274. " vim: et ts=8