comparison vendor/vim-syntax/coffee.vim @ 508:bbcffc594d1e

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