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: 2006 Jun 19
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")
34 syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
35 syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo
36 syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
37 syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo
38 syn match javaScriptSpecial "\\\d\d\d\|\\."
39 syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc
40 syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc
42 syn match javaScriptSpecialCharacter "'\\.'"
43 syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
44 syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
46 syn keyword javaScriptConditional if else switch
47 syn keyword javaScriptRepeat while for do in
48 syn keyword javaScriptBranch break continue
49 syn keyword javaScriptOperator new delete instanceof typeof
50 syn keyword javaScriptType Array Boolean Date Function Number Object String RegExp
51 syn keyword javaScriptStatement return with
52 syn keyword javaScriptBoolean true false
53 syn keyword javaScriptNull null undefined
54 syn keyword javaScriptIdentifier arguments this var
55 syn keyword javaScriptLabel case default
56 syn keyword javaScriptException try catch finally throw
57 syn keyword javaScriptMessage alert confirm prompt status
58 syn keyword javaScriptGlobal self window top parent
59 syn keyword javaScriptMember document event location
60 syn keyword javaScriptDeprecated escape unescape
61 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
63 if exists("javaScript_fold")
64 syn match javaScriptFunction "\<function\>"
65 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
67 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>"
68 syn sync match javaScriptSync grouphere NONE "^}"
70 setlocal foldmethod=syntax
71 setlocal foldtext=getline(v:foldstart)
73 syn keyword javaScriptFunction function
74 syn match javaScriptBraces "[{}\[\]]"
75 syn match javaScriptParens "[()]"
81 if main_syntax == "javascript"
82 syn sync ccomment javaScriptComment
85 " Define the default highlighting.
86 " For version 5.7 and earlier: only when not done already
87 " For version 5.8 and later: only when an item doesn't have highlighting yet
88 if version >= 508 || !exists("did_javascript_syn_inits")
90 let did_javascript_syn_inits = 1
91 command -nargs=+ HiLink hi link <args>
93 command -nargs=+ HiLink hi def link <args>
95 HiLink javaScriptComment Comment
96 HiLink javaScriptLineComment Comment
97 HiLink javaScriptCommentTodo Todo
98 HiLink javaScriptSpecial Special
99 HiLink javaScriptStringS String
100 HiLink javaScriptStringD String
101 HiLink javaScriptCharacter Character
102 HiLink javaScriptSpecialCharacter javaScriptSpecial
103 HiLink javaScriptNumber javaScriptValue
104 HiLink javaScriptConditional Conditional
105 HiLink javaScriptRepeat Repeat
106 HiLink javaScriptBranch Conditional
107 HiLink javaScriptOperator Operator
108 HiLink javaScriptType Type
109 HiLink javaScriptStatement Statement
110 HiLink javaScriptFunction Function
111 HiLink javaScriptBraces Function
112 HiLink javaScriptError Error
113 HiLink javaScrParenError javaScriptError
114 HiLink javaScriptNull Keyword
115 HiLink javaScriptBoolean Boolean
116 HiLink javaScriptRegexpString String
118 HiLink javaScriptIdentifier Identifier
119 HiLink javaScriptLabel Label
120 HiLink javaScriptException Exception
121 HiLink javaScriptMessage Keyword
122 HiLink javaScriptGlobal Keyword
123 HiLink javaScriptMember Keyword
124 HiLink javaScriptDeprecated Exception
125 HiLink javaScriptReserved Keyword
126 HiLink javaScriptDebug Debug
127 HiLink javaScriptConstant Label
132 let b:current_syntax = "javascript"
133 if main_syntax == 'javascript'