]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/syntax/javascript.vim
91d250691cc403b1ea79583a62380b843a8a94da
[rbdr/dotfiles] / vim / syntax / javascript.vim
1 " Vim syntax file
2 " Language: JavaScript
3 " Maintainer: Yi Zhao (ZHAOYI) <zzlinux AT hotmail DOT com>
4 " Last Change By: Marc Harter
5 " Last Change: February 18, 2011
6 " Version: 0.7.9
7 " Changes: Updates JSDoc syntax
8 "
9 " TODO:
10 " - Add the HTML syntax inside the JSDoc
11
12 if !exists("main_syntax")
13 if version < 600
14 syntax clear
15 elseif exists("b:current_syntax")
16 finish
17 endif
18 let main_syntax = 'javascript'
19 endif
20
21 "" Drop fold if it set but VIM doesn't support it.
22 let b:javascript_fold='true'
23 if version < 600 " Don't support the old version
24 unlet! b:javascript_fold
25 endif
26
27 "" dollar sigh is permittd anywhere in an identifier
28 setlocal iskeyword+=$
29
30 syntax sync fromstart
31
32 "" JavaScript comments
33 syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
34 syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell
35 syntax region javaScriptEnvComment start="\%^#!" end="$" display
36 syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold
37 syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained
38 syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold
39
40 "" JSDoc / JSDoc Toolkit
41 if !exists("javascript_ignore_javaScriptdoc")
42 syntax case ignore
43
44 "" syntax coloring for javadoc comments (HTML)
45 "syntax include @javaHtml <sfile>:p:h/html.vim
46 "unlet b:current_syntax
47
48 syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
49
50 " tags containing a param
51 syntax match javaScriptDocTags contained "@\(augments\|base\|borrows\|class\|constructs\|default\|exception\|exports\|extends\|file\|member\|memberOf\|module\|name\|namespace\|optional\|requires\|title\|throws\|version\)\>" nextgroup=javaScriptDocParam skipwhite
52 " tags containing type and param
53 syntax match javaScriptDocTags contained "@\(argument\|param\|property\)\>" nextgroup=javaScriptDocType skipwhite
54 " tags containing type but no param
55 syntax match javaScriptDocTags contained "@\(type\|return\|returns\)\>" nextgroup=javaScriptDocTypeNoParam skipwhite
56 " tags containing references
57 syntax match javaScriptDocTags contained "@\(lends\|link\|see\)\>" nextgroup=javaScriptDocSeeTag skipwhite
58 " other tags (no extra syntax)
59 syntax match javaScriptDocTags contained "@\(access\|addon\|alias\|author\|beta\|constant\|constructor\|copyright\|deprecated\|description\|event\|example\|exec\|field\|fileOverview\|fileoverview\|function\|global\|ignore\|inner\|license\|overview\|private\|protected\|project\|public\|readonly\|since\|static\)\>"
60
61 syntax region javaScriptDocType start="{" end="}" oneline contained nextgroup=javaScriptDocParam skipwhite
62 syntax match javaScriptDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" nextgroup=javaScriptDocParam skipwhite
63 syntax region javaScriptDocTypeNoParam start="{" end="}" oneline contained
64 syntax match javaScriptDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+"
65 syntax match javaScriptDocParam contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+"
66 syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags
67
68 syntax case match
69 endif "" JSDoc end
70
71 syntax case match
72
73 "" Syntax in the JavaScript code
74 syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
75 syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc
76 syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
77 syntax region javaScriptRegexpCharClass start=+\[\]\|\[^\]\|\[+ end=+\]+ contained
78 syntax region javaScriptRegexpString start=+\(\(\(return\|case\)\s\+\)\@<=\|\(\([)\]"']\|\d\|\w\)\s*\)\@<!\)/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,javaScriptRegexpCharClass,@htmlPreproc oneline
79 syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
80 syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
81 syntax match javaScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
82
83 "" JavaScript Prototype
84 syntax keyword javaScriptPrototype prototype
85
86 "" Programm Keywords
87 syntax keyword javaScriptSource import export
88 syntax keyword javaScriptType const undefined var void yield
89 syntax keyword javaScriptOperator delete new in instanceof let typeof
90 syntax keyword javaScriptBoolean true false
91 syntax keyword javaScriptNull null
92 syntax keyword javaScriptThis this
93
94 "" Statement Keywords
95 syntax keyword javaScriptConditional if else
96 syntax keyword javaScriptRepeat do while for
97 syntax keyword javaScriptBranch break continue switch case default return
98 syntax keyword javaScriptStatement try catch throw with finally
99
100 syntax keyword javaScriptGlobalObjects Array Boolean Date Function Infinity JavaArray JavaClass JavaObject JavaPackage Math Number NaN Object Packages RegExp String Undefined java netscape sun
101
102 syntax keyword javaScriptExceptions Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
103
104 syntax keyword javaScriptFutureKeys abstract enum int short boolean 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
105
106 "" DOM/HTML/CSS specified things
107
108 " DOM2 Objects
109 syntax keyword javaScriptGlobalObjects DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
110 syntax keyword javaScriptExceptions DOMException
111
112 " DOM2 CONSTANT
113 syntax keyword javaScriptDomErrNo 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
114 syntax keyword javaScriptDomNodeConsts 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
115
116 " HTML events and internal variables
117 syntax case ignore
118 syntax keyword javaScriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize
119 syntax case match
120
121 " Follow stuff should be highligh within a special context
122 " While it can't be handled with context depended with Regex based highlight
123 " So, turn it off by default
124 if exists("javascript_enable_domhtmlcss")
125
126 " DOM2 things
127 syntax match javaScriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
128 syntax match javaScriptDomElemFuncs 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=javaScriptParen skipwhite
129 " HTML things
130 syntax match javaScriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
131 syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite
132
133 " CSS Styles in JavaScript
134 syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
135 syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
136 syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
137 syntax keyword javaScriptCssStyles contained bottom height left position right top width zIndex
138 syntax keyword javaScriptCssStyles 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
139 syntax keyword javaScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
140 syntax keyword javaScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
141 syntax keyword javaScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
142 syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
143 syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
144 syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
145
146 " Highlight ways
147 syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs
148 syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles
149
150 endif "DOM/HTML/CSS
151
152 "" end DOM/HTML/CSS specified things
153
154
155 "" Code blocks
156 syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptThis,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation
157 syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc
158 syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
159 syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
160
161 "" catch errors caused by wrong parenthesis
162 syntax match javaScriptParensError ")\|}\|\]"
163 syntax match javaScriptParensErrA contained "\]"
164 syntax match javaScriptParensErrB contained ")"
165 syntax match javaScriptParensErrC contained "}"
166
167 if main_syntax == "javascript"
168 syntax sync clear
169 syntax sync ccomment javaScriptComment minlines=200
170 syntax sync match javaScriptHighlight grouphere javaScriptBlock /{/
171 endif
172
173 "" Fold control
174 if exists("b:javascript_fold")
175 syntax match javaScriptFunction /\<function\>/ nextgroup=javaScriptFuncName skipwhite
176 syntax match javaScriptOpAssign /=\@<!=/ nextgroup=javaScriptFuncBlock skipwhite skipempty
177 syntax region javaScriptFuncName contained matchgroup=javaScriptFuncName start=/\%(\$\|\w\)*\s*(/ end=/)/ contains=javaScriptLineComment,javaScriptComment nextgroup=javaScriptFuncBlock skipwhite skipempty
178 syntax region javaScriptFuncBlock contained matchgroup=javaScriptFuncBlock start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock fold
179 else
180 syntax keyword javaScriptFunction function
181 endif
182
183 " Define the default highlighting.
184 " For version 5.7 and earlier: only when not done already
185 " For version 5.8 and later: only when an item doesn't have highlighting yet
186 if version >= 508 || !exists("did_javascript_syn_inits")
187 if version < 508
188 let did_javascript_syn_inits = 1
189 command -nargs=+ HiLink hi link <args>
190 else
191 command -nargs=+ HiLink hi def link <args>
192 endif
193 HiLink javaScriptComment Comment
194 HiLink javaScriptLineComment Comment
195 HiLink javaScriptEnvComment PreProc
196 HiLink javaScriptDocComment Comment
197 HiLink javaScriptCommentTodo Todo
198 HiLink javaScriptCvsTag Function
199 HiLink javaScriptDocTags Special
200 HiLink javaScriptDocSeeTag Function
201 HiLink javaScriptDocType Type
202 HiLink javaScriptDocTypeNoParam Type
203 HiLink javaScriptDocParam Label
204 HiLink javaScriptStringS String
205 HiLink javaScriptStringD String
206 HiLink javaScriptRegexpString String
207 HiLink javaScriptRegexpCharClass Character
208 HiLink javaScriptCharacter Character
209 HiLink javaScriptPrototype Type
210 HiLink javaScriptConditional Conditional
211 HiLink javaScriptBranch Conditional
212 HiLink javaScriptRepeat Repeat
213 HiLink javaScriptStatement Statement
214 HiLink javaScriptFunction Function
215 HiLink javaScriptError Error
216 HiLink javaScriptParensError Error
217 HiLink javaScriptParensErrA Error
218 HiLink javaScriptParensErrB Error
219 HiLink javaScriptParensErrC Error
220 HiLink javaScriptOperator Operator
221 HiLink javaScriptType Type
222 HiLink javaScriptThis Type
223 HiLink javaScriptNull Type
224 HiLink javaScriptNumber Number
225 HiLink javaScriptFloat Number
226 HiLink javaScriptBoolean Boolean
227 HiLink javaScriptLabel Label
228 HiLink javaScriptSpecial Special
229 HiLink javaScriptSource Special
230 HiLink javaScriptGlobalObjects Special
231 HiLink javaScriptExceptions Special
232
233 HiLink javaScriptDomErrNo Constant
234 HiLink javaScriptDomNodeConsts Constant
235 HiLink javaScriptDomElemAttrs Label
236 HiLink javaScriptDomElemFuncs PreProc
237
238 HiLink javaScriptHtmlEvents Special
239 HiLink javaScriptHtmlElemAttrs Label
240 HiLink javaScriptHtmlElemFuncs PreProc
241
242 HiLink javaScriptCssStyles Label
243
244 delcommand HiLink
245 endif
246
247 " Define the htmlJavaScript for HTML syntax html.vim
248 "syntax clear htmlJavaScript
249 "syntax clear javaScriptExpression
250 syntax cluster htmlJavaScript contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError
251 syntax cluster javaScriptExpression contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError,@htmlPreproc
252
253 let b:current_syntax = "javascript"
254 if main_syntax == 'javascript'
255 unlet main_syntax
256 endif
257
258 " vim: ts=4