7
|
1 " Vim syntax file
|
|
2 " Language: JavaScript
|
|
3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
|
|
4 " URL: http://www.fleiner.com/vim/syntax/javascript.vim
|
36
|
5 " Last Change: 2004 Nov 20
|
7
|
6
|
|
7 " For version 5.x: Clear all syntax items
|
|
8 " For version 6.x: Quit when a syntax file was already loaded
|
|
9 " tuning parameters:
|
|
10 " unlet javaScript_fold
|
|
11
|
|
12 if !exists("main_syntax")
|
|
13 if version < 600
|
|
14 syntax clear
|
|
15 elseif exists("b:current_syntax")
|
|
16 finish
|
|
17 endif
|
|
18 let main_syntax = 'javascript'
|
|
19 endif
|
|
20
|
|
21 " Drop fold if it set but vim doesn't support it.
|
|
22 if version < 600 && exists("javaScript_fold")
|
|
23 unlet javaScript_fold
|
|
24 endif
|
|
25
|
|
26 syn case ignore
|
|
27
|
|
28
|
|
29 syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
|
|
30 syn match javaScriptLineComment "\/\/.*$" contains=javaScriptCommentTodo
|
|
31 syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
|
|
32 syn region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo
|
|
33 syn match javaScriptSpecial "\\\d\d\d\|\\."
|
|
34 syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc
|
|
35 syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
|
|
36 syn match javaScriptSpecialCharacter "'\\.'"
|
|
37 syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
|
36
|
38 syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\?\s*$+ end=+/[gi]\?\s*[;.,)]+me=e-1 contains=@htmlPreproc oneline
|
|
39 syn keyword javaScriptConditional if else
|
|
40 syn keyword javaScriptRepeat while for
|
|
41 syn keyword javaScriptBranch break continue switch case default
|
|
42 syn keyword javaScriptOperator new in
|
|
43 syn keyword javaScriptType this var const
|
|
44 syn keyword javaScriptStatement return with
|
|
45 syn keyword javaScriptBoolean true false
|
|
46 syn keyword javaScriptNull null
|
7
|
47
|
|
48 if exists("javaScript_fold")
|
|
49 syn match javaScriptFunction "\<function\>"
|
|
50 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
|
|
51
|
|
52 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>"
|
|
53 syn sync match javaScriptSync grouphere NONE "^}"
|
|
54
|
|
55 setlocal foldmethod=syntax
|
|
56 setlocal foldtext=getline(v:foldstart)
|
|
57 else
|
|
58 syn keyword javaScriptFunction function
|
|
59 syn match javaScriptBraces "[{}]"
|
|
60 endif
|
|
61
|
|
62 syn sync fromstart
|
|
63 syn sync maxlines=100
|
|
64
|
|
65 " catch errors caused by wrong parenthesis
|
36
|
66 syn region javaScriptParen transparent start="(" end=")" contains=javaScriptParen,javaScriptComment,javaScriptSpecial,javaScriptStringD,javaScriptStringS,javaScriptSpecialCharacter,javaScriptNumber,javaScriptRegexpString,javaScriptBoolean,javaScriptBraces,javaScriptFunction,javaScriptFunctionFold,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptOperator,javaScriptType,javaScriptStatement,javaScriptBoolean,javaScriptConstant
|
|
67 syn region javaScriptParen transparent start="(" end=")" contains=javaScriptParen,javaScriptComment,javaScriptSpecial,javaScriptStringD,javaScriptStringS,javaScriptSpecialCharacter,javaScriptNumber,javaScriptRegexpString,javaScriptBoolean,javaScriptBraces
|
7
|
68 syn match javaScrParenError ")"
|
|
69
|
|
70 if main_syntax == "javascript"
|
|
71 syn sync ccomment javaScriptComment
|
|
72 endif
|
|
73
|
|
74 " Define the default highlighting.
|
|
75 " For version 5.7 and earlier: only when not done already
|
|
76 " For version 5.8 and later: only when an item doesn't have highlighting yet
|
|
77 if version >= 508 || !exists("did_javascript_syn_inits")
|
|
78 if version < 508
|
|
79 let did_javascript_syn_inits = 1
|
|
80 command -nargs=+ HiLink hi link <args>
|
|
81 else
|
|
82 command -nargs=+ HiLink hi def link <args>
|
|
83 endif
|
36
|
84 HiLink javaScriptComment Comment
|
|
85 HiLink javaScriptLineComment Comment
|
|
86 HiLink javaScriptCommentTodo Todo
|
|
87 HiLink javaScriptSpecial Special
|
|
88 HiLink javaScriptStringS String
|
|
89 HiLink javaScriptStringD String
|
|
90 HiLink javaScriptCharacter Character
|
|
91 HiLink javaScriptSpecialCharacter javaScriptSpecial
|
|
92 HiLink javaScriptNumber javaScriptValue
|
|
93 HiLink javaScriptConditional Conditional
|
|
94 HiLink javaScriptRepeat Repeat
|
|
95 HiLink javaScriptBranch Conditional
|
|
96 HiLink javaScriptOperator Operator
|
|
97 HiLink javaScriptType Type
|
|
98 HiLink javaScriptStatement Statement
|
|
99 HiLink javaScriptFunction Function
|
|
100 HiLink javaScriptBraces Function
|
|
101 HiLink javaScriptError Error
|
|
102 HiLink javaScrParenError javaScriptError
|
|
103 HiLink javaScriptNull Keyword
|
|
104 HiLink javaScriptBoolean Boolean
|
|
105 HiLink javaScriptRegexpString String
|
7
|
106 delcommand HiLink
|
|
107 endif
|
|
108
|
|
109 let b:current_syntax = "javascript"
|
|
110 if main_syntax == 'javascript'
|
|
111 unlet main_syntax
|
|
112 endif
|
|
113
|
|
114 " vim: ts=8
|