]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/syntax/coffee.vim
Remove blinking and reattach-to-user-namespace
[rbdr/dotfiles] / vim / syntax / coffee.vim
... / ...
CommitLineData
1" Language: CoffeeScript
2" Maintainer: Mick Koch <kchmck@gmail.com>
3" URL: http://github.com/kchmck/vim-coffee-script
4" License: WTFPL
5
6" Bail if our syntax is already loaded.
7if exists('b:current_syntax') && b:current_syntax == 'coffee'
8 finish
9endif
10
11if version < 600
12 syn clear
13endif
14
15" Include JavaScript for coffeeEmbed.
16syn include @coffeeJS syntax/javascript.vim
17
18" Highlight long strings.
19syn sync minlines=100
20
21" CoffeeScript identifiers can have dollar signs.
22setlocal isident+=$
23
24" These are `matches` instead of `keywords` because vim's highlighting
25" priority for keywords is higher than matches. This causes keywords to be
26" highlighted inside matches, even if a match says it shouldn't contain them --
27" like with coffeeAssign and coffeeDot.
28syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ display
29hi def link coffeeStatement Statement
30
31syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ display
32hi def link coffeeRepeat Repeat
33
34syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/
35\ display
36hi def link coffeeConditional Conditional
37
38syn match coffeeException /\<\%(try\|catch\|finally\)\>/ display
39hi def link coffeeException Exception
40
41syn match coffeeKeyword /\<\%(new\|in\|of\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|own\|do\)\>/
42\ display
43hi def link coffeeKeyword Keyword
44
45syn match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ display
46hi def link coffeeOperator Operator
47
48" The first case matches symbol operators only if they have an operand before.
49syn match coffeeExtendedOp /\%(\S\s*\)\@<=[+\-*/%&|\^=!<>?.]\+\|--\|++\|::/
50\ display
51syn match coffeeExtendedOp /\%(and\|or\)=/ display
52hi def link coffeeExtendedOp coffeeOperator
53
54" This is separate from `coffeeExtendedOp` to help differentiate commas from
55" dots.
56syn match coffeeSpecialOp /[,;]/ display
57hi def link coffeeSpecialOp SpecialChar
58
59syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ display
60hi def link coffeeBoolean Boolean
61
62syn match coffeeGlobal /\<\%(null\|undefined\)\>/ display
63hi def link coffeeGlobal Type
64
65" A special variable
66syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ display
67" An @-variable
68syn match coffeeSpecialVar /@\%(\I\i*\)\?/ display
69hi def link coffeeSpecialVar Special
70
71" A class-like name that starts with a capital letter
72syn match coffeeObject /\<\u\w*\>/ display
73hi def link coffeeObject Structure
74
75" A constant-like name in SCREAMING_CAPS
76syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ display
77hi def link coffeeConstant Constant
78
79" A variable name
80syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeObject,
81\ coffeeConstant
82
83" A non-interpolated string
84syn cluster coffeeBasicString contains=@Spell,coffeeEscape
85" An interpolated string
86syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp
87
88" Regular strings
89syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/
90\ contains=@coffeeInterpString
91syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/
92\ contains=@coffeeBasicString
93hi def link coffeeString String
94
95" A integer, including a leading plus or minus
96syn match coffeeNumber /\i\@<![-+]\?\d\+\%([eE][+-]\?\d\+\)\?/ display
97" A hex number
98syn match coffeeNumber /\<0[xX]\x\+\>/ display
99hi def link coffeeNumber Number
100
101" A floating-point number, including a leading plus or minus
102syn match coffeeFloat /\i\@<![-+]\?\d*\.\@<!\.\d\+\%([eE][+-]\?\d\+\)\?/
103\ display
104hi def link coffeeFloat Float
105
106" An error for reserved keywords
107if !exists("coffee_no_reserved_words_error")
108 syn match coffeeReservedError /\<\%(case\|default\|function\|var\|void\|with\|const\|let\|enum\|export\|import\|native\|__hasProp\|__extends\|__slice\|__bind\|__indexOf\)\>/
109 \ display
110 hi def link coffeeReservedError Error
111endif
112
113" This is separate from `coffeeExtendedOp` since assignments require it.
114syn match coffeeAssignOp /:/ contained display
115hi def link coffeeAssignOp coffeeOperator
116
117" Strings used in string assignments, which can't have interpolations
118syn region coffeeAssignString start=/"/ skip=/\\\\\|\\"/ end=/"/ contained
119\ contains=@coffeeBasicString
120syn region coffeeAssignString start=/'/ skip=/\\\\\|\\'/ end=/'/ contained
121\ contains=@coffeeBasicString
122hi def link coffeeAssignString String
123
124" A normal object assignment
125syn match coffeeObjAssign /@\?\I\i*\s*:\@<!::\@!/
126\ contains=@coffeeIdentifier,coffeeAssignOp
127hi def link coffeeObjAssign Identifier
128
129" An object-string assignment
130syn match coffeeObjStringAssign /\("\|'\)[^\1]*\1\s*;\@<!::\@!'\@!/
131\ contains=coffeeAssignString,coffeeAssignOp
132" An object-integer assignment
133syn match coffeeObjNumberAssign /\d\+\%(\.\d\+\)\?\s*:\@<!::\@!/
134\ contains=coffeeNumber,coffeeAssignOp
135
136syn keyword coffeeTodo TODO FIXME XXX contained
137hi def link coffeeTodo Todo
138
139syn match coffeeComment /#.*/ contains=@Spell,coffeeTodo
140hi def link coffeeComment Comment
141
142syn region coffeeBlockComment start=/####\@!/ end=/###/
143\ contains=@Spell,coffeeTodo
144hi def link coffeeBlockComment coffeeComment
145
146" A comment in a heregex
147syn region coffeeHeregexComment start=/#/ end=/\ze\/\/\/\|$/ contained
148\ contains=@Spell,coffeeTodo
149hi def link coffeeHeregexComment coffeeComment
150
151" Embedded JavaScript
152syn region coffeeEmbed matchgroup=coffeeEmbedDelim
153\ start=/`/ skip=/\\\\\|\\`/ end=/`/
154\ contains=@coffeeJS
155hi def link coffeeEmbedDelim Delimiter
156
157syn region coffeeInterp matchgroup=coffeeInterpDelim start=/#{/ end=/}/ contained
158\ contains=@coffeeAll
159hi def link coffeeInterpDelim PreProc
160
161" A string escape sequence
162syn match coffeeEscape /\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\./ contained display
163hi def link coffeeEscape SpecialChar
164
165" A regex -- must not follow a parenthesis, number, or identifier, and must not
166" be followed by a number
167syn region coffeeRegex start=/\%(\%()\|\i\@<!\d\)\s*\|\i\)\@<!\/=\@!\s\@!/
168\ skip=/\[[^\]]\{-}\/[^\]]\{-}\]/
169\ end=/\/[gimy]\{,4}\d\@!/
170\ oneline contains=@coffeeBasicString
171hi def link coffeeRegex String
172
173" A heregex
174syn region coffeeHeregex start=/\/\/\// end=/\/\/\/[gimy]\{,4}/
175\ contains=@coffeeInterpString,coffeeHeregexComment
176\ fold
177hi def link coffeeHeregex coffeeRegex
178
179" Heredoc strings
180syn region coffeeHeredoc start=/"""/ end=/"""/ contains=@coffeeInterpString
181\ fold
182syn region coffeeHeredoc start=/'''/ end=/'''/ contains=@coffeeBasicString
183\ fold
184hi def link coffeeHeredoc String
185
186" An error for trailing whitespace, as long as the line isn't just whitespace
187if !exists("coffee_no_trailing_space_error")
188 syn match coffeeSpaceError /\S\@<=\s\+$/ display
189 hi def link coffeeSpaceError Error
190endif
191
192" An error for trailing semicolons, for help transitioning from JavaScript
193if !exists("coffee_no_trailing_semicolon_error")
194 syn match coffeeSemicolonError /;$/ display
195 hi def link coffeeSemicolonError Error
196endif
197
198" Ignore reserved words in dot accesses.
199syn match coffeeDotAccess /\.\@<!\.\s*\I\i*/he=s+1 contains=@coffeeIdentifier
200hi def link coffeeDotAccess coffeeExtendedOp
201
202" Ignore reserved words in prototype accesses.
203syn match coffeeProtoAccess /::\s*\I\i*/he=s+2 contains=@coffeeIdentifier
204hi def link coffeeProtoAccess coffeeExtendedOp
205
206" This is required for interpolations to work.
207syn region coffeeCurlies matchgroup=coffeeCurly start=/{/ end=/}/
208\ contains=@coffeeAll
209syn region coffeeBrackets matchgroup=coffeeBracket start=/\[/ end=/\]/
210\ contains=@coffeeAll
211syn region coffeeParens matchgroup=coffeeParen start=/(/ end=/)/
212\ contains=@coffeeAll
213
214" These are highlighted the same as commas since they tend to go together.
215hi def link coffeeBlock coffeeSpecialOp
216hi def link coffeeBracket coffeeBlock
217hi def link coffeeCurly coffeeBlock
218hi def link coffeeParen coffeeBlock
219
220" This is used instead of TOP to keep things coffee-specific for good
221" embedding. `contained` groups aren't included.
222syn cluster coffeeAll contains=coffeeStatement,coffeeRepeat,coffeeConditional,
223\ coffeeException,coffeeKeyword,coffeeOperator,
224\ coffeeExtendedOp,coffeeSpecialOp,coffeeBoolean,
225\ coffeeGlobal,coffeeSpecialVar,coffeeObject,
226\ coffeeConstant,coffeeString,coffeeNumber,
227\ coffeeFloat,coffeeReservedError,coffeeObjAssign,
228\ coffeeObjStringAssign,coffeeObjNumberAssign,
229\ coffeeComment,coffeeBlockComment,coffeeEmbed,
230\ coffeeRegex,coffeeHeregex,coffeeHeredoc,
231\ coffeeSpaceError,coffeeSemicolonError,
232\ coffeeDotAccess,coffeeProtoAccess,
233\ coffeeCurlies,coffeeBrackets,coffeeParens
234
235if !exists('b:current_syntax')
236 let b:current_syntax = 'coffee'
237endif