comparison vendor/vim-syntax/typescript.vim @ 620:7ac088ee101a

Add typescript vim syntax
author nanaya <me@nanaya.pro>
date Tue, 30 Oct 2018 19:04:56 +0900
parents
children 11e00204fb18
comparison
equal deleted inserted replaced
619:7045cd713864 620:7ac088ee101a
1 " Vim syntax file
2 " Language: typescript
3 " Author: MicroSoft Open Technologies Inc.
4 " Version: 0.1
5 " Credits: Zhao Yi, Claudio Fleiner, Scott Shattuck, Jose Elera Campana
6
7 if !exists("main_syntax")
8 if version < 600
9 syntax clear
10 elseif exists("b:current_syntax")
11 finish
12 endif
13 let main_syntax = "typescript"
14 endif
15
16 " Drop fold if it set but vim doesn't support it.
17 if version < 600 && exists("typescript_fold")
18 unlet typescript_fold
19 endif
20
21 "" dollar sign is permitted anywhere in an identifier
22 setlocal iskeyword+=$
23
24 syntax sync fromstart
25
26 "" syntax coloring for Node.js shebang line
27 syn match shebang "^#!.*/bin/env\s\+node\>"
28 hi link shebang Comment
29
30 "" typescript comments"{{{
31 syn keyword typescriptCommentTodo TODO FIXME XXX TBD contained
32 syn match typescriptLineComment "\/\/.*" contains=@Spell,typescriptCommentTodo,typescriptRef
33 syn match typescriptRefComment /\/\/\/<\(reference\|amd-\(dependency\|module\)\)\s\+.*\/>$/ contains=typescriptRefD,typescriptRefS
34 syn region typescriptRefD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+
35 syn region typescriptRefS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+
36
37 syn match typescriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
38 syn region typescriptComment start="/\*" end="\*/" contains=@Spell,typescriptCommentTodo extend
39 "}}}
40 "" JSDoc support start"{{{
41 if !exists("typescript_ignore_typescriptdoc")
42 syntax case ignore
43
44 " syntax coloring for JSDoc comments (HTML)
45 "unlet b:current_syntax
46
47 syntax region typescriptDocComment start="/\*\*\s*$" end="\*/" contains=typescriptDocTags,typescriptCommentTodo,typescriptCvsTag,@typescriptHtml,@Spell fold extend
48 syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\|returns\=\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite
49 syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
50 syntax match typescriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
51 syntax region typescriptDocSeeTag contained matchgroup=typescriptDocSeeTag start="{" end="}" contains=typescriptDocTags
52
53 syntax case match
54 endif "" JSDoc end
55 "}}}
56 syntax case match
57
58 "" Syntax in the typescript code"{{{
59 syn match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}" contained containedin=typescriptStringD,typescriptStringS,typescriptStringB display
60 syn region typescriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=typescriptSpecial,@htmlPreproc extend
61 syn region typescriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=typescriptSpecial,@htmlPreproc extend
62 syn region typescriptStringB start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=typescriptInterpolation,typescriptSpecial,@htmlPreproc extend
63
64 syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter
65 \ start=/${/ end=/}/ contained
66 \ contains=@typescriptExpression
67
68 syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>" display
69 syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display
70 syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display
71 syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display
72 syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
73 " syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
74 " syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc
75 " syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc
76 " syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline
77 " syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
78 syntax match typescriptFloat /\<-\=\%(\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\.\|\.\d[0-9]*\)\%([eE][+-]\=\d[0-9_]*\)\=\>/
79 " syntax match typescriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
80
81 syn match typescriptDecorators /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/
82 "}}}
83 "" typescript Prototype"{{{
84 syntax keyword typescriptPrototype contained prototype
85 "}}}
86 " DOM, Browser and Ajax Support {{{
87 """"""""""""""""""""""""
88 if get(g:, 'typescript_ignore_browserwords', 0)
89 syntax keyword typescriptBrowserObjects window navigator screen history location
90
91 syntax keyword typescriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea
92 syntax keyword typescriptDOMMethods contained createTextNode createElement insertBefore replaceChild removeChild appendChild hasChildNodes cloneNode normalize isSupported hasAttributes getAttribute setAttribute removeAttribute getAttributeNode setAttributeNode removeAttributeNode getElementsByTagName hasAttribute getElementById adoptNode close compareDocumentPosition createAttribute createCDATASection createComment createDocumentFragment createElementNS createEvent createExpression createNSResolver createProcessingInstruction createRange createTreeWalker elementFromPoint evaluate getBoxObjectFor getElementsByClassName getSelection getUserData hasFocus importNode
93 syntax keyword typescriptDOMProperties contained nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName
94
95 syntax keyword typescriptAjaxObjects XMLHttpRequest
96 syntax keyword typescriptAjaxProperties contained readyState responseText responseXML statusText
97 syntax keyword typescriptAjaxMethods contained onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader
98
99 syntax keyword typescriptPropietaryObjects ActiveXObject
100 syntax keyword typescriptPropietaryMethods contained attachEvent detachEvent cancelBubble returnValue
101
102 syntax keyword typescriptHtmlElemProperties contained className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title
103
104 syntax keyword typescriptEventListenerKeywords contained blur click focus mouseover mouseout load item
105
106 syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation
107 endif
108 " }}}
109 "" Programm Keywords"{{{
110 syntax keyword typescriptSource import export from as
111 syntax keyword typescriptIdentifier arguments this void
112 syntax keyword typescriptStorageClass let var const
113 syntax keyword typescriptOperator delete new instanceof typeof
114 syntax keyword typescriptBoolean true false
115 syntax keyword typescriptNull null undefined
116 syntax keyword typescriptMessage alert confirm prompt status
117 syntax keyword typescriptGlobal self top parent
118 syntax keyword typescriptDeprecated escape unescape all applets alinkColor bgColor fgColor linkColor vlinkColor xmlEncoding
119 "}}}
120 "" Statement Keywords"{{{
121 syntax keyword typescriptConditional if else switch
122 syntax keyword typescriptRepeat do while for in of
123 syntax keyword typescriptBranch break continue yield await
124 syntax keyword typescriptLabel case default async readonly
125 syntax keyword typescriptStatement return with
126
127 syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity Math Number NaN Object Packages RegExp String Symbol netscape
128
129 syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
130
131 syntax keyword typescriptReserved constructor declare as interface module abstract enum int short export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public type namespace from get set keyof
132 "}}}
133 "" typescript/DOM/HTML/CSS specified things"{{{
134
135 " typescript Objects"{{{
136 syn match typescriptFunction "(super\s*|constructor\s*)" contained nextgroup=typescriptVars
137 syn region typescriptVars start="(" end=")" contained contains=typescriptParameters transparent keepend
138 syn match typescriptParameters "([a-zA-Z0-9_?.$][\w?.$]*)\s*:\s*([a-zA-Z0-9_?.$][\w?.$]*)" contained skipwhite
139 "}}}
140 " DOM2 Objects"{{{
141 syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never object unknown
142 syntax keyword typescriptExceptions DOMException
143 "}}}
144 " DOM2 CONSTANT"{{{
145 syntax keyword typescriptDomErrNo INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR
146 syntax keyword typescriptDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
147 "}}}
148 " HTML events and internal variables"{{{
149 syntax case ignore
150 syntax keyword typescriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize onload onsubmit
151 syntax case match
152 "}}}
153
154 " Follow stuff should be highligh within a special context
155 " While it can't be handled with context depended with Regex based highlight
156 " So, turn it off by default
157 if exists("typescript_enable_domhtmlcss")
158
159 " DOM2 things"{{{
160 syntax match typescriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
161 syntax match typescriptDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=typescriptParen skipwhite
162 "}}}
163 " HTML things"{{{
164 syntax match typescriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
165 syntax match typescriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=typescriptParen skipwhite
166 "}}}
167 " CSS Styles in typescript"{{{
168 syntax keyword typescriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
169 syntax keyword typescriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
170 syntax keyword typescriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
171 syntax keyword typescriptCssStyles contained bottom height left position right top width zIndex
172 syntax keyword typescriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout
173 syntax keyword typescriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
174 syntax keyword typescriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
175 syntax keyword typescriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
176 syntax keyword typescriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
177 syntax keyword typescriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
178 syntax keyword typescriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
179 "}}}
180 endif "DOM/HTML/CSS
181
182 " Highlight ways"{{{
183 syntax match typescriptDotNotation "\." nextgroup=typescriptPrototype,typescriptDomElemAttrs,typescriptDomElemFuncs,typescriptDOMMethods,typescriptDOMProperties,typescriptHtmlElemAttrs,typescriptHtmlElemFuncs,typescriptHtmlElemProperties,typescriptAjaxProperties,typescriptAjaxMethods,typescriptPropietaryMethods,typescriptEventListenerMethods skipwhite skipnl
184 syntax match typescriptDotNotation "\.style\." nextgroup=typescriptCssStyles
185 "}}}
186
187 "" end DOM/HTML/CSS specified things""}}}
188
189
190 "" Code blocks
191 syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptStorageClass,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg
192
193 if main_syntax == "typescript"
194 syntax sync clear
195 syntax sync ccomment typescriptComment minlines=200
196 " syntax sync match typescriptHighlight grouphere typescriptBlock /{/
197 endif
198
199 syntax keyword typescriptFuncKeyword function
200 "syntax region typescriptFuncDef start="function" end="\(.*\)" contains=typescriptFuncKeyword,typescriptFuncArg keepend
201 "syntax match typescriptFuncArg "\(([^()]*)\)" contains=typescriptParens,typescriptFuncComma contained
202 "syntax match typescriptFuncComma /,/ contained
203 " syntax region typescriptFuncBlock contained matchgroup=typescriptFuncBlock start="{" end="}" contains=@typescriptAll,typescriptParensErrA,typescriptParensErrB,typescriptParen,typescriptBracket,typescriptBlock fold
204
205 syn match typescriptBraces "[{}\[\]]"
206 syn match typescriptParens "[()]"
207 syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-="
208 syn match typescriptEndColons "[;,]"
209 syn match typescriptLogicSymbols "\(&&\)\|\(||\)"
210
211 " typescriptFold Function {{{
212
213 " function! typescriptFold()
214
215 " skip curly braces inside RegEx's and comments
216 syn region foldBraces start=/{/ skip=/\(\/\/.*\)\|\(\/.*\/\)/ end=/}/ transparent fold keepend extend
217
218 " setl foldtext=FoldText()
219 " endfunction
220
221 " au FileType typescript call typescriptFold()
222
223 " }}}
224
225 " Define the default highlighting.
226 " For version 5.7 and earlier: only when not done already
227 " For version 5.8 and later: only when an item doesn't have highlighting yet
228 if version >= 508 || !exists("did_typescript_syn_inits")
229 if version < 508
230 let did_typescript_syn_inits = 1
231 command -nargs=+ HiLink hi link <args>
232 else
233 command -nargs=+ HiLink hi def link <args>
234 endif
235
236 "typescript highlighting
237 HiLink typescriptParameters Operator
238 HiLink typescriptSuperBlock Operator
239
240 HiLink typescriptEndColons Exception
241 HiLink typescriptOpSymbols Operator
242 HiLink typescriptLogicSymbols Boolean
243 HiLink typescriptBraces Function
244 HiLink typescriptParens Operator
245 HiLink typescriptComment Comment
246 HiLink typescriptLineComment Comment
247 HiLink typescriptRefComment Include
248 HiLink typescriptRefS String
249 HiLink typescriptRefD String
250 HiLink typescriptDocComment Comment
251 HiLink typescriptCommentTodo Todo
252 HiLink typescriptCvsTag Function
253 HiLink typescriptDocTags Special
254 HiLink typescriptDocSeeTag Function
255 HiLink typescriptDocParam Function
256 HiLink typescriptStringS String
257 HiLink typescriptStringD String
258 HiLink typescriptStringB String
259 HiLink typescriptInterpolationDelimiter Delimiter
260 HiLink typescriptRegexpString String
261 HiLink typescriptGlobal Constant
262 HiLink typescriptCharacter Character
263 HiLink typescriptPrototype Type
264 HiLink typescriptConditional Conditional
265 HiLink typescriptBranch Conditional
266 HiLink typescriptIdentifier Identifier
267 HiLink typescriptStorageClass StorageClass
268 HiLink typescriptRepeat Repeat
269 HiLink typescriptStatement Statement
270 HiLink typescriptFuncKeyword Function
271 HiLink typescriptMessage Keyword
272 HiLink typescriptDeprecated Exception
273 HiLink typescriptError Error
274 HiLink typescriptParensError Error
275 HiLink typescriptParensErrA Error
276 HiLink typescriptParensErrB Error
277 HiLink typescriptParensErrC Error
278 HiLink typescriptReserved Keyword
279 HiLink typescriptOperator Operator
280 HiLink typescriptType Type
281 HiLink typescriptNull Type
282 HiLink typescriptNumber Number
283 HiLink typescriptFloat Number
284 HiLink typescriptDecorators Special
285 HiLink typescriptBoolean Boolean
286 HiLink typescriptLabel Label
287 HiLink typescriptSpecial Special
288 HiLink typescriptSource Special
289 HiLink typescriptGlobalObjects Special
290 HiLink typescriptExceptions Special
291
292 HiLink typescriptDomErrNo Constant
293 HiLink typescriptDomNodeConsts Constant
294 HiLink typescriptDomElemAttrs Label
295 HiLink typescriptDomElemFuncs PreProc
296
297 HiLink typescriptHtmlElemAttrs Label
298 HiLink typescriptHtmlElemFuncs PreProc
299
300 HiLink typescriptCssStyles Label
301
302 " Ajax Highlighting
303 HiLink typescriptBrowserObjects Constant
304
305 HiLink typescriptDOMObjects Constant
306 HiLink typescriptDOMMethods Function
307 HiLink typescriptDOMProperties Special
308
309 HiLink typescriptAjaxObjects Constant
310 HiLink typescriptAjaxMethods Function
311 HiLink typescriptAjaxProperties Special
312
313 HiLink typescriptFuncDef Title
314 HiLink typescriptFuncArg Special
315 HiLink typescriptFuncComma Operator
316
317 HiLink typescriptHtmlEvents Special
318 HiLink typescriptHtmlElemProperties Special
319
320 HiLink typescriptEventListenerKeywords Keyword
321
322 HiLink typescriptNumber Number
323 HiLink typescriptPropietaryObjects Constant
324
325 delcommand HiLink
326 endif
327
328 " Define the htmltypescript for HTML syntax html.vim
329 "syntax clear htmltypescript
330 "syntax clear typescriptExpression
331 syntax cluster htmltypescript contains=@typescriptAll,typescriptBracket,typescriptParen,typescriptBlock,typescriptParenError
332 syntax cluster typescriptExpression contains=@typescriptAll,typescriptBracket,typescriptParen,typescriptBlock,typescriptParenError,@htmlPreproc
333
334 let b:current_syntax = "typescript"
335 if main_syntax == 'typescript'
336 unlet main_syntax
337 endif
338
339 " vim: ts=4