1" Vim syntax file
2" Language:	JavaScript
3" Maintainer:	Claudio Fleiner <[email protected]>
4" Updaters:	Scott Shattuck (ss) <[email protected]>
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:	2012 Oct 05
11" 		2013 Jun 12: adjusted javaScriptRegexpString (Kevin Locke)
12
13" For version 5.x: Clear all syntax items
14" For version 6.x: Quit when a syntax file was already loaded
15" tuning parameters:
16" unlet javaScript_fold
17
18if !exists("main_syntax")
19  if version < 600
20    syntax clear
21  elseif exists("b:current_syntax")
22    finish
23  endif
24  let main_syntax = 'javascript'
25endif
26
27let s:cpo_save = &cpo
28set cpo&vim
29
30" Drop fold if it set but vim doesn't support it.
31if version < 600 && exists("javaScript_fold")
32  unlet javaScript_fold
33endif
34
35
36syn keyword javaScriptCommentTodo      TODO FIXME XXX TBD contained
37syn match   javaScriptLineComment      "\/\/.*" contains=@Spell,javaScriptCommentTodo
38syn match   javaScriptCommentSkip      "^[ \t]*\*\($\|[ \t]\+\)"
39syn region  javaScriptComment	       start="/\*"  end="\*/" contains=@Spell,javaScriptCommentTodo
40syn match   javaScriptSpecial	       "\\\d\d\d\|\\."
41syn region  javaScriptStringD	       start=+"+  skip=+\\\\\|\\"+  end=+"\|$+	contains=javaScriptSpecial,@htmlPreproc
42syn region  javaScriptStringS	       start=+'+  skip=+\\\\\|\\'+  end=+'\|$+	contains=javaScriptSpecial,@htmlPreproc
43
44syn match   javaScriptSpecialCharacter "'\\.'"
45syn match   javaScriptNumber	       "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
46syn region  javaScriptRegexpString     start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gim]\{0,2\}\s*$+ end=+/[gim]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
47
48syn keyword javaScriptConditional	if else switch
49syn keyword javaScriptRepeat		while for do in
50syn keyword javaScriptBranch		break continue
51syn keyword javaScriptOperator		new delete instanceof typeof
52syn keyword javaScriptType		Array Boolean Date Function Number Object String RegExp
53syn keyword javaScriptStatement		return with
54syn keyword javaScriptBoolean		true false
55syn keyword javaScriptNull		null undefined
56syn keyword javaScriptIdentifier	arguments this var let
57syn keyword javaScriptLabel		case default
58syn keyword javaScriptException		try catch finally throw
59syn keyword javaScriptMessage		alert confirm prompt status
60syn keyword javaScriptGlobal		self window top parent
61syn keyword javaScriptMember		document event location
62syn keyword javaScriptDeprecated	escape unescape
63syn 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
64
65if exists("javaScript_fold")
66    syn match	javaScriptFunction	"\<function\>"
67    syn region	javaScriptFunctionFold	start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
68
69    syn sync match javaScriptSync	grouphere javaScriptFunctionFold "\<function\>"
70    syn sync match javaScriptSync	grouphere NONE "^}"
71
72    setlocal foldmethod=syntax
73    setlocal foldtext=getline(v:foldstart)
74else
75    syn keyword javaScriptFunction	function
76    syn match	javaScriptBraces	   "[{}\[\]]"
77    syn match	javaScriptParens	   "[()]"
78endif
79
80syn sync fromstart
81syn sync maxlines=100
82
83if main_syntax == "javascript"
84  syn sync ccomment javaScriptComment
85endif
86
87" Define the default highlighting.
88" For version 5.7 and earlier: only when not done already
89" For version 5.8 and later: only when an item doesn't have highlighting yet
90if version >= 508 || !exists("did_javascript_syn_inits")
91  if version < 508
92    let did_javascript_syn_inits = 1
93    command -nargs=+ HiLink hi link <args>
94  else
95    command -nargs=+ HiLink hi def link <args>
96  endif
97  HiLink javaScriptComment		Comment
98  HiLink javaScriptLineComment		Comment
99  HiLink javaScriptCommentTodo		Todo
100  HiLink javaScriptSpecial		Special
101  HiLink javaScriptStringS		String
102  HiLink javaScriptStringD		String
103  HiLink javaScriptCharacter		Character
104  HiLink javaScriptSpecialCharacter	javaScriptSpecial
105  HiLink javaScriptNumber		javaScriptValue
106  HiLink javaScriptConditional		Conditional
107  HiLink javaScriptRepeat		Repeat
108  HiLink javaScriptBranch		Conditional
109  HiLink javaScriptOperator		Operator
110  HiLink javaScriptType			Type
111  HiLink javaScriptStatement		Statement
112  HiLink javaScriptFunction		Function
113  HiLink javaScriptBraces		Function
114  HiLink javaScriptError		Error
115  HiLink javaScrParenError		javaScriptError
116  HiLink javaScriptNull			Keyword
117  HiLink javaScriptBoolean		Boolean
118  HiLink javaScriptRegexpString		String
119
120  HiLink javaScriptIdentifier		Identifier
121  HiLink javaScriptLabel		Label
122  HiLink javaScriptException		Exception
123  HiLink javaScriptMessage		Keyword
124  HiLink javaScriptGlobal		Keyword
125  HiLink javaScriptMember		Keyword
126  HiLink javaScriptDeprecated		Exception
127  HiLink javaScriptReserved		Keyword
128  HiLink javaScriptDebug		Debug
129  HiLink javaScriptConstant		Label
130
131  delcommand HiLink
132endif
133
134let b:current_syntax = "javascript"
135if main_syntax == 'javascript'
136  unlet main_syntax
137endif
138let &cpo = s:cpo_save
139unlet s:cpo_save
140
141" vim: ts=8
142