citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

typescript.vim (18411B)


      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 typeScriptRef /\/\/\/<reference\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
     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 matchgroup=typeScriptComment start="/\*\*\s*$" end="\*/" contains=typeScriptDocTags,typeScriptCommentTodo,typeScriptCvsTag,@typeScriptHtml,@Spell fold
     48   syntax match typeScriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=typeScriptDocParam,typeScriptDocSeeTag skipwhite
     49   syntax match typeScriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|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\|\\."
     60 syn region typeScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+	contains=typeScriptSpecial,@htmlPreproc
     61 syn region typeScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+	contains=typeScriptSpecial,@htmlPreproc
     62 
     63 syn match typeScriptSpecialCharacter "'\\.'"
     64 syn match typeScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
     65 syn region typeScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
     66 " syntax match typeScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
     67 " syntax region typeScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typeScriptSpecial,@htmlPreproc
     68 " syntax region typeScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typeScriptSpecial,@htmlPreproc
     69 " syntax region typeScriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typeScriptSpecial,@htmlPreproc oneline
     70 " syntax match typeScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
     71 syntax match typeScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
     72 " syntax match typeScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
     73 "}}}
     74 "" typeScript Prototype"{{{
     75 syntax keyword typeScriptPrototype prototype
     76 "}}}
     77 " DOM, Browser and Ajax Support {{{
     78 """"""""""""""""""""""""
     79 syntax keyword typeScriptBrowserObjects window navigator screen history location
     80 
     81 syntax keyword typeScriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea
     82 syntax keyword typeScriptDOMMethods 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
     83 syntax keyword typeScriptDOMProperties nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName
     84 
     85 syntax keyword typeScriptAjaxObjects XMLHttpRequest
     86 syntax keyword typeScriptAjaxProperties readyState responseText responseXML statusText
     87 syntax keyword typeScriptAjaxMethods onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader
     88 
     89 syntax keyword typeScriptPropietaryObjects ActiveXObject
     90 syntax keyword typeScriptPropietaryMethods attachEvent detachEvent cancelBubble returnValue
     91 
     92 syntax keyword typeScriptHtmlElemProperties className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title
     93 
     94 syntax keyword typeScriptEventListenerKeywords blur click focus mouseover mouseout load item
     95 
     96 syntax keyword typeScriptEventListenerMethods scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation
     97 " }}}
     98 "" Programm Keywords"{{{
     99 syntax keyword typeScriptSource import export
    100 syntax keyword typeScriptIdentifier arguments this let var void yield
    101 syntax keyword typeScriptOperator delete new instanceof typeof
    102 syntax keyword typeScriptBoolean true false
    103 syntax keyword typeScriptNull null undefined
    104 syntax keyword typeScriptMessage alert confirm prompt status
    105 syntax keyword typeScriptGlobal self top parent
    106 syntax keyword typeScriptDeprecated escape unescape all applets alinkColor bgColor fgColor linkColor vlinkColor xmlEncoding
    107 "}}}
    108 "" Statement Keywords"{{{
    109 syntax keyword typeScriptConditional if else switch
    110 syntax keyword typeScriptRepeat do while for in
    111 syntax keyword typeScriptBranch break continue
    112 syntax keyword typeScriptLabel case default
    113 syntax keyword typeScriptStatement return with
    114 
    115 syntax keyword typeScriptGlobalObjects Array Boolean Date Function Infinity Math Number NaN Object Packages RegExp String netscape
    116 
    117 syntax keyword typeScriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
    118 
    119 syntax keyword typeScriptReserved constructor declare as interface module abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public
    120 "}}}
    121 "" TypeScript/DOM/HTML/CSS specified things"{{{
    122 
    123 " TypeScript Objects"{{{
    124   syn match typeScriptFunction "(super\s*|constructor\s*)" contained nextgroup=typeScriptVars
    125   syn region typeScriptVars start="(" end=")" contained contains=typeScriptParameters transparent keepend
    126   syn match typeScriptParameters "([a-zA-Z0-9_?.$][\w?.$]*)\s*:\s*([a-zA-Z0-9_?.$][\w?.$]*)" contained skipwhite
    127 "}}}
    128 " DOM2 Objects"{{{
    129   syntax keyword typeScriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string bool number
    130   syntax keyword typeScriptExceptions DOMException
    131 "}}}
    132 " DOM2 CONSTANT"{{{
    133   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
    134   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
    135 "}}}
    136 " HTML events and internal variables"{{{
    137   syntax case ignore
    138   syntax keyword typeScriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize onload onsubmit
    139   syntax case match
    140 "}}}
    141 
    142 " Follow stuff should be highligh within a special context
    143 " While it can't be handled with context depended with Regex based highlight
    144 " So, turn it off by default
    145 if exists("typeScript_enable_domhtmlcss")
    146 
    147 " DOM2 things"{{{
    148     syntax match typeScriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
    149     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
    150 "}}}
    151 " HTML things"{{{
    152     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\)\>/
    153     syntax match typeScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=typeScriptParen skipwhite
    154 "}}}
    155 " CSS Styles in typeScript"{{{
    156     syntax keyword typeScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
    157     syntax keyword typeScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
    158     syntax keyword typeScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
    159     syntax keyword typeScriptCssStyles contained bottom height left position right top width zIndex
    160     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
    161     syntax keyword typeScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
    162     syntax keyword typeScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
    163     syntax keyword typeScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
    164     syntax keyword typeScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
    165     syntax keyword typeScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
    166     syntax keyword typeScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
    167 "}}}
    168 " Highlight ways"{{{
    169     syntax match typeScriptDotNotation "\." nextgroup=typeScriptPrototype,typeScriptDomElemAttrs,typeScriptDomElemFuncs,typeScriptHtmlElemAttrs,typeScriptHtmlElemFuncs
    170     syntax match typeScriptDotNotation "\.style\." nextgroup=typeScriptCssStyles
    171 "}}}
    172 endif "DOM/HTML/CSS
    173 
    174 "" end DOM/HTML/CSS specified things""}}}
    175 
    176 
    177 "" Code blocks
    178 syntax cluster typeScriptAll contains=typeScriptComment,typeScriptLineComment,typeScriptDocComment,typeScriptStringD,typeScriptStringS,typeScriptRegexpString,typeScriptNumber,typeScriptFloat,typeScriptLabel,typeScriptSource,typeScriptType,typeScriptOperator,typeScriptBoolean,typeScriptNull,typeScriptFuncKeyword,typeScriptConditional,typeScriptGlobal,typeScriptRepeat,typeScriptBranch,typeScriptStatement,typeScriptGlobalObjects,typeScriptMessage,typeScriptIdentifier,typeScriptExceptions,typeScriptReserved,typeScriptDeprecated,typeScriptDomErrNo,typeScriptDomNodeConsts,typeScriptHtmlEvents,typeScriptDotNotation,typeScriptBrowserObjects,typeScriptDOMObjects,typeScriptAjaxObjects,typeScriptPropietaryObjects,typeScriptDOMMethods,typeScriptHtmlElemProperties,typeScriptDOMProperties,typeScriptEventListenerKeywords,typeScriptEventListenerMethods,typeScriptAjaxProperties,typeScriptAjaxMethods,typeScriptFuncArg
    179 
    180 if main_syntax == "typeScript"
    181   syntax sync clear
    182   syntax sync ccomment typeScriptComment minlines=200
    183 " syntax sync match typeScriptHighlight grouphere typeScriptBlock /{/
    184 endif
    185 
    186 syntax keyword typeScriptFuncKeyword function contained
    187 syntax region typeScriptFuncDef start="function" end="\([^)]*\)" contains=typeScriptFuncKeyword,typeScriptFuncArg keepend
    188 syntax match typeScriptFuncArg "\(([^()]*)\)" contains=typeScriptParens,typeScriptFuncComma contained
    189 syntax match typeScriptFuncComma /,/ contained
    190 " syntax region typeScriptFuncBlock contained matchgroup=typeScriptFuncBlock start="{" end="}" contains=@typeScriptAll,typeScriptParensErrA,typeScriptParensErrB,typeScriptParen,typeScriptBracket,typeScriptBlock fold
    191 
    192 syn match	typeScriptBraces "[{}\[\]]"
    193 syn match	typeScriptParens "[()]"
    194 syn match	typeScriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-="
    195 syn match typeScriptEndColons "[;,]"
    196 syn match typeScriptLogicSymbols "\(&&\)\|\(||\)"
    197 
    198 " typeScriptFold Function {{{
    199 
    200 function! TypeScriptFold()
    201 setl foldmethod=syntax
    202 setl foldlevelstart=1
    203 syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
    204 
    205 setl foldtext=FoldText()
    206 endfunction
    207 
    208 au FileType typeScript call TypeScriptFold()
    209 
    210 " }}}
    211 
    212 " Define the default highlighting.
    213 " For version 5.7 and earlier: only when not done already
    214 " For version 5.8 and later: only when an item doesn't have highlighting yet
    215 if version >= 508 || !exists("did_typeScript_syn_inits")
    216   if version < 508
    217     let did_typeScript_syn_inits = 1
    218     command -nargs=+ HiLink hi link <args>
    219   else
    220     command -nargs=+ HiLink hi def link <args>
    221   endif
    222 
    223   "Typescript highlighting
    224   HiLink typeScriptParameters Operator
    225   HiLink typescriptSuperBlock Operator
    226 
    227   HiLink typeScriptEndColons Exception
    228   HiLink typeScriptOpSymbols Operator
    229   HiLink typeScriptLogicSymbols Boolean
    230   HiLink typeScriptBraces Function
    231   HiLink typeScriptParens Operator
    232   HiLink typeScriptComment Comment
    233   HiLink typeScriptLineComment Comment
    234   HiLink typeScriptRef Include
    235   HiLink typeScriptRefS String
    236   HiLink typeScriptRefD String
    237   HiLink typeScriptDocComment Comment
    238   HiLink typeScriptCommentTodo Todo
    239   HiLink typeScriptCvsTag Function
    240   HiLink typeScriptDocTags Special
    241   HiLink typeScriptDocSeeTag Function
    242   HiLink typeScriptDocParam Function
    243   HiLink typeScriptStringS String
    244   HiLink typeScriptStringD String
    245   HiLink typeScriptRegexpString String
    246   HiLink typeScriptGlobal Constant
    247   HiLink typeScriptCharacter Character
    248   HiLink typeScriptPrototype Type
    249   HiLink typeScriptConditional Conditional
    250   HiLink typeScriptBranch Conditional
    251   HiLink typeScriptIdentifier Identifier
    252   HiLink typeScriptRepeat Repeat
    253   HiLink typeScriptStatement Statement
    254   HiLink typeScriptFuncKeyword Function
    255   HiLink typeScriptMessage Keyword
    256   HiLink typeScriptDeprecated Exception
    257   HiLink typeScriptError Error
    258   HiLink typeScriptParensError Error
    259   HiLink typeScriptParensErrA Error
    260   HiLink typeScriptParensErrB Error
    261   HiLink typeScriptParensErrC Error
    262   HiLink typeScriptReserved Keyword
    263   HiLink typeScriptOperator Operator
    264   HiLink typeScriptType Type
    265   HiLink typeScriptNull Type
    266   HiLink typeScriptNumber Number
    267   HiLink typeScriptFloat Number
    268   HiLink typeScriptBoolean Boolean
    269   HiLink typeScriptLabel Label
    270   HiLink typeScriptSpecial Special
    271   HiLink typeScriptSource Special
    272   HiLink typeScriptGlobalObjects Special
    273   HiLink typeScriptExceptions Special
    274 
    275   HiLink typeScriptDomErrNo Constant
    276   HiLink typeScriptDomNodeConsts Constant
    277   HiLink typeScriptDomElemAttrs Label
    278   HiLink typeScriptDomElemFuncs PreProc
    279 
    280   HiLink typeScriptHtmlElemAttrs Label
    281   HiLink typeScriptHtmlElemFuncs PreProc
    282 
    283   HiLink typeScriptCssStyles Label
    284 " Ajax Highlighting
    285 HiLink typeScriptBrowserObjects Constant
    286 
    287 HiLink typeScriptDOMObjects Constant
    288 HiLink typeScriptDOMMethods Exception
    289 HiLink typeScriptDOMProperties Type
    290 
    291 HiLink typeScriptAjaxObjects htmlH1
    292 HiLink typeScriptAjaxMethods Exception
    293 HiLink typeScriptAjaxProperties Type
    294 
    295 HiLink typeScriptFuncDef Title
    296     HiLink typeScriptFuncArg Special
    297     HiLink typeScriptFuncComma Operator
    298 
    299 HiLink typeScriptHtmlEvents Special
    300 HiLink typeScriptHtmlElemProperties Type
    301 
    302 HiLink typeScriptEventListenerKeywords Keyword
    303 
    304 HiLink typeScriptNumber Number
    305 HiLink typeScriptPropietaryObjects Constant
    306 
    307   delcommand HiLink
    308 endif
    309 
    310 " Define the htmltypeScript for HTML syntax html.vim
    311 "syntax clear htmltypeScript
    312 "syntax clear typeScriptExpression
    313 syntax cluster htmltypeScript contains=@typeScriptAll,typeScriptBracket,typeScriptParen,typeScriptBlock,typeScriptParenError
    314 syntax cluster typeScriptExpression contains=@typeScriptAll,typeScriptBracket,typeScriptParen,typeScriptBlock,typeScriptParenError,@htmlPreproc
    315 
    316 let b:current_syntax = "typeScript"
    317 if main_syntax == 'typeScript'
    318   unlet main_syntax
    319 endif
    320 
    321 " vim: ts=4