3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
4 " Updaters: Scott Shattuck (ss) <ss@technicalpursuit.com>
5 " URL: http://www.fleiner.com/vim/syntax/javascript.vim
6 " Changes: (ss) added keywords, reserved words, and other identifiers
7 " (ss) repaired several quoting and grouping glitches
8 " (ss) fixed regex parsing issue with multiple qualifiers [gi]
9 " (ss) additional factoring of keywords, globals, and members
10 " Last Change: 2010 Mar 25
12 " For version 5.x: Clear all syntax items
13 " For version 6.x: Quit when a syntax file was already loaded
15 " unlet javaScript_fold
17 if !exists("main_syntax")
20 elseif exists("b:current_syntax")
23 let main_syntax = 'javascript'
26 " Drop fold if it set but vim doesn't support it.
27 if version < 600 && exists("javaScript_fold")
32 syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
33 syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo
34 syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
35 syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo
36 syn match javaScriptSpecial "\\\d\d\d\|\\."
37 syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc
38 syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc
40 syn match javaScriptSpecialCharacter "'\\.'"
41 syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
42 syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
44 syn keyword javaScriptConditional if else switch
45 syn keyword javaScriptRepeat while for do in
46 syn keyword javaScriptBranch break continue
47 syn keyword javaScriptOperator new delete instanceof typeof
48 syn keyword javaScriptType Array Boolean Date Function Number Object String RegExp
49 syn keyword javaScriptStatement return with
50 syn keyword javaScriptBoolean true false
51 syn keyword javaScriptNull null undefined
52 syn keyword javaScriptIdentifier arguments this var let
53 syn keyword javaScriptLabel case default
54 syn keyword javaScriptException try catch finally throw
55 syn keyword javaScriptMessage alert confirm prompt status
56 syn keyword javaScriptGlobal self window top parent
57 syn keyword javaScriptMember document event location
58 syn keyword javaScriptDeprecated escape unescape
59 syn keyword javaScriptReserved abstract boolean byte char class const debugger double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile
61 if exists("javaScript_fold")
62 syn match javaScriptFunction "\<function\>"
63 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
65 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>"
66 syn sync match javaScriptSync grouphere NONE "^}"
68 setlocal foldmethod=syntax
69 setlocal foldtext=getline(v:foldstart)
71 syn keyword javaScriptFunction function
72 syn match javaScriptBraces "[{}\[\]]"
73 syn match javaScriptParens "[()]"
79 if main_syntax == "javascript"
80 syn sync ccomment javaScriptComment
83 " Define the default highlighting.
84 " For version 5.7 and earlier: only when not done already
85 " For version 5.8 and later: only when an item doesn't have highlighting yet
86 if version >= 508 || !exists("did_javascript_syn_inits")
88 let did_javascript_syn_inits = 1
89 command -nargs=+ HiLink hi link <args>
91 command -nargs=+ HiLink hi def link <args>
93 HiLink javaScriptComment Comment
94 HiLink javaScriptLineComment Comment
95 HiLink javaScriptCommentTodo Todo
96 HiLink javaScriptSpecial Special
97 HiLink javaScriptStringS String
98 HiLink javaScriptStringD String
99 HiLink javaScriptCharacter Character
100 HiLink javaScriptSpecialCharacter javaScriptSpecial
101 HiLink javaScriptNumber javaScriptValue
102 HiLink javaScriptConditional Conditional
103 HiLink javaScriptRepeat Repeat
104 HiLink javaScriptBranch Conditional
105 HiLink javaScriptOperator Operator
106 HiLink javaScriptType Type
107 HiLink javaScriptStatement Statement
108 HiLink javaScriptFunction Function
109 HiLink javaScriptBraces Function
110 HiLink javaScriptError Error
111 HiLink javaScrParenError javaScriptError
112 HiLink javaScriptNull Keyword
113 HiLink javaScriptBoolean Boolean
114 HiLink javaScriptRegexpString String
116 HiLink javaScriptIdentifier Identifier
117 HiLink javaScriptLabel Label
118 HiLink javaScriptException Exception
119 HiLink javaScriptMessage Keyword
120 HiLink javaScriptGlobal Keyword
121 HiLink javaScriptMember Keyword
122 HiLink javaScriptDeprecated Exception
123 HiLink javaScriptReserved Keyword
124 HiLink javaScriptDebug Debug
125 HiLink javaScriptConstant Label
130 let b:current_syntax = "javascript"
131 if main_syntax == 'javascript'