Simple image host.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

coffee.vim 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. " Language: CoffeeScript
  2. " Maintainer: Mick Koch <mick@kochm.co>
  3. " URL: http://github.com/kchmck/vim-coffee-script
  4. " License: WTFPL
  5. " Bail if our syntax is already loaded.
  6. if exists('b:current_syntax') && b:current_syntax == 'coffee'
  7. finish
  8. endif
  9. " Include JavaScript for coffeeEmbed.
  10. syn include @coffeeJS syntax/javascript.vim
  11. silent! unlet b:current_syntax
  12. " Highlight long strings.
  13. syntax sync fromstart
  14. " These are `matches` instead of `keywords` because vim's highlighting
  15. " priority for keywords is higher than matches. This causes keywords to be
  16. " highlighted inside matches, even if a match says it shouldn't contain them --
  17. " like with coffeeAssign and coffeeDot.
  18. syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ display
  19. hi def link coffeeStatement Statement
  20. syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ display
  21. hi def link coffeeRepeat Repeat
  22. syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/
  23. \ display
  24. hi def link coffeeConditional Conditional
  25. syn match coffeeException /\<\%(try\|catch\|finally\)\>/ display
  26. hi def link coffeeException Exception
  27. syn match coffeeKeyword /\<\%(new\|in\|of\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|do\)\>/
  28. \ display
  29. " The `own` keyword is only a keyword after `for`.
  30. syn match coffeeKeyword /\<for\s\+own\>/ contained containedin=coffeeRepeat
  31. \ display
  32. hi def link coffeeKeyword Keyword
  33. syn match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ display
  34. hi def link coffeeOperator Operator
  35. " The first case matches symbol operators only if they have an operand before.
  36. syn match coffeeExtendedOp /\%(\S\s*\)\@<=[+\-*/%&|\^=!<>?.]\{-1,}\|[-=]>\|--\|++\|:/
  37. \ display
  38. syn match coffeeExtendedOp /\<\%(and\|or\)=/ display
  39. hi def link coffeeExtendedOp coffeeOperator
  40. " This is separate from `coffeeExtendedOp` to help differentiate commas from
  41. " dots.
  42. syn match coffeeSpecialOp /[,;]/ display
  43. hi def link coffeeSpecialOp SpecialChar
  44. syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ display
  45. hi def link coffeeBoolean Boolean
  46. syn match coffeeGlobal /\<\%(null\|undefined\)\>/ display
  47. hi def link coffeeGlobal Type
  48. " A special variable
  49. syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ display
  50. hi def link coffeeSpecialVar Special
  51. " An @-variable
  52. syn match coffeeSpecialIdent /@\%(\%(\I\|\$\)\%(\i\|\$\)*\)\?/ display
  53. hi def link coffeeSpecialIdent Identifier
  54. " A class-like name that starts with a capital letter
  55. syn match coffeeObject /\<\u\w*\>/ display
  56. hi def link coffeeObject Structure
  57. " A constant-like name in SCREAMING_CAPS
  58. syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ display
  59. hi def link coffeeConstant Constant
  60. " A variable name
  61. syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeSpecialIdent,
  62. \ coffeeObject,coffeeConstant
  63. " A non-interpolated string
  64. syn cluster coffeeBasicString contains=@Spell,coffeeEscape
  65. " An interpolated string
  66. syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp
  67. " Regular strings
  68. syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/
  69. \ contains=@coffeeInterpString
  70. syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/
  71. \ contains=@coffeeBasicString
  72. hi def link coffeeString String
  73. " A integer, including a leading plus or minus
  74. syn match coffeeNumber /\%(\i\|\$\)\@<![-+]\?\d\+\%([eE][+-]\?\d\+\)\?/ display
  75. " A hex, binary, or octal number
  76. syn match coffeeNumber /\<0[xX]\x\+\>/ display
  77. syn match coffeeNumber /\<0[bB][01]\+\>/ display
  78. syn match coffeeNumber /\<0[oO][0-7]\+\>/ display
  79. syn match coffeeNumber /\<\%(Infinity\|NaN\)\>/ display
  80. hi def link coffeeNumber Number
  81. " A floating-point number, including a leading plus or minus
  82. syn match coffeeFloat /\%(\i\|\$\)\@<![-+]\?\d*\.\@<!\.\d\+\%([eE][+-]\?\d\+\)\?/
  83. \ display
  84. hi def link coffeeFloat Float
  85. " An error for reserved keywords, taken from the RESERVED array:
  86. " http://coffeescript.org/documentation/docs/lexer.html#section-67
  87. syn match coffeeReservedError /\<\%(case\|default\|function\|var\|void\|with\|const\|let\|enum\|export\|import\|native\|__hasProp\|__extends\|__slice\|__bind\|__indexOf\|implements\|interface\|package\|private\|protected\|public\|static\|yield\)\>/
  88. \ display
  89. hi def link coffeeReservedError Error
  90. " A normal object assignment
  91. syn match coffeeObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/ contains=@coffeeIdentifier display
  92. hi def link coffeeObjAssign Identifier
  93. syn keyword coffeeTodo TODO FIXME XXX contained
  94. hi def link coffeeTodo Todo
  95. syn match coffeeComment /#.*/ contains=@Spell,coffeeTodo
  96. hi def link coffeeComment Comment
  97. syn region coffeeBlockComment start=/####\@!/ end=/###/
  98. \ contains=@Spell,coffeeTodo
  99. hi def link coffeeBlockComment coffeeComment
  100. " A comment in a heregex
  101. syn region coffeeHeregexComment start=/#/ end=/\ze\/\/\/\|$/ contained
  102. \ contains=@Spell,coffeeTodo
  103. hi def link coffeeHeregexComment coffeeComment
  104. " Embedded JavaScript
  105. syn region coffeeEmbed matchgroup=coffeeEmbedDelim
  106. \ start=/`/ skip=/\\\\\|\\`/ end=/`/ keepend
  107. \ contains=@coffeeJS
  108. hi def link coffeeEmbedDelim Delimiter
  109. syn region coffeeInterp matchgroup=coffeeInterpDelim start=/#{/ end=/}/ contained
  110. \ contains=@coffeeAll
  111. hi def link coffeeInterpDelim PreProc
  112. " A string escape sequence
  113. syn match coffeeEscape /\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\./ contained display
  114. hi def link coffeeEscape SpecialChar
  115. " A regex -- must not follow a parenthesis, number, or identifier, and must not
  116. " be followed by a number
  117. syn region coffeeRegex start=#\%(\%()\|\%(\i\|\$\)\@<!\d\)\s*\|\i\)\@<!/=\@!\s\@!#
  118. \ end=#/[gimy]\{,4}\d\@!#
  119. \ oneline contains=@coffeeBasicString,coffeeRegexCharSet
  120. syn region coffeeRegexCharSet start=/\[/ end=/]/ contained
  121. \ contains=@coffeeBasicString
  122. hi def link coffeeRegex String
  123. hi def link coffeeRegexCharSet coffeeRegex
  124. " A heregex
  125. syn region coffeeHeregex start=#///# end=#///[gimy]\{,4}#
  126. \ contains=@coffeeInterpString,coffeeHeregexComment,
  127. \ coffeeHeregexCharSet
  128. \ fold
  129. syn region coffeeHeregexCharSet start=/\[/ end=/]/ contained
  130. \ contains=@coffeeInterpString
  131. hi def link coffeeHeregex coffeeRegex
  132. hi def link coffeeHeregexCharSet coffeeHeregex
  133. " Heredoc strings
  134. syn region coffeeHeredoc start=/"""/ end=/"""/ contains=@coffeeInterpString
  135. \ fold
  136. syn region coffeeHeredoc start=/'''/ end=/'''/ contains=@coffeeBasicString
  137. \ fold
  138. hi def link coffeeHeredoc String
  139. " An error for trailing whitespace, as long as the line isn't just whitespace
  140. syn match coffeeSpaceError /\S\@<=\s\+$/ display
  141. hi def link coffeeSpaceError Error
  142. " An error for trailing semicolons, for help transitioning from JavaScript
  143. syn match coffeeSemicolonError /;$/ display
  144. hi def link coffeeSemicolonError Error
  145. " Ignore reserved words in dot accesses.
  146. syn match coffeeDotAccess /\.\@<!\.\s*\%(\I\|\$\)\%(\i\|\$\)*/he=s+1 contains=@coffeeIdentifier
  147. hi def link coffeeDotAccess coffeeExtendedOp
  148. " Ignore reserved words in prototype accesses.
  149. syn match coffeeProtoAccess /::\s*\%(\I\|\$\)\%(\i\|\$\)*/he=s+2 contains=@coffeeIdentifier
  150. hi def link coffeeProtoAccess coffeeExtendedOp
  151. " This is required for interpolations to work.
  152. syn region coffeeCurlies matchgroup=coffeeCurly start=/{/ end=/}/
  153. \ contains=@coffeeAll
  154. syn region coffeeBrackets matchgroup=coffeeBracket start=/\[/ end=/\]/
  155. \ contains=@coffeeAll
  156. syn region coffeeParens matchgroup=coffeeParen start=/(/ end=/)/
  157. \ contains=@coffeeAll
  158. " These are highlighted the same as commas since they tend to go together.
  159. hi def link coffeeBlock coffeeSpecialOp
  160. hi def link coffeeBracket coffeeBlock
  161. hi def link coffeeCurly coffeeBlock
  162. hi def link coffeeParen coffeeBlock
  163. " This is used instead of TOP to keep things coffee-specific for good
  164. " embedding. `contained` groups aren't included.
  165. syn cluster coffeeAll contains=coffeeStatement,coffeeRepeat,coffeeConditional,
  166. \ coffeeException,coffeeKeyword,coffeeOperator,
  167. \ coffeeExtendedOp,coffeeSpecialOp,coffeeBoolean,
  168. \ coffeeGlobal,coffeeSpecialVar,coffeeSpecialIdent,
  169. \ coffeeObject,coffeeConstant,coffeeString,
  170. \ coffeeNumber,coffeeFloat,coffeeReservedError,
  171. \ coffeeObjAssign,coffeeComment,coffeeBlockComment,
  172. \ coffeeEmbed,coffeeRegex,coffeeHeregex,
  173. \ coffeeHeredoc,coffeeSpaceError,
  174. \ coffeeSemicolonError,coffeeDotAccess,
  175. \ coffeeProtoAccess,coffeeCurlies,coffeeBrackets,
  176. \ coffeeParens
  177. if !exists('b:current_syntax')
  178. let b:current_syntax = 'coffee'
  179. endif