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