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