]>
Commit | Line | Data |
---|---|---|
efb89a59 JR |
1 | " Vim syntax file |
2 | " Language: JavaScript | |
3 | " Maintainer: Yi Zhao <zzlinux AT hotmail DOT com> | |
4 | " Last Change: 2006 March 10 | |
5 | " Version: 0.3 | |
6 | " Based On: javascript.vim from Claudio Fleiner <claudio@fleiner.com> | |
7 | " Changes: Include all JavaScript Global Objects; and jsLabel support | |
8 | " | |
9 | " TODO | |
10 | " - internal function hightlight | |
11 | " - code fold support | |
12 | " | |
13 | ||
14 | if !exists("main_syntax") | |
15 | if version < 600 | |
16 | syntax clear | |
17 | elseif exists("b:current_syntax") | |
18 | finish | |
19 | endif | |
20 | let main_syntax = 'javascript' | |
21 | endif | |
22 | ||
23 | " Drop fold if it set but vim doesn't support it. | |
24 | if version < 600 && exists("javaScript_fold") | |
25 | unlet javaScript_fold | |
26 | endif | |
27 | ||
28 | syntax case match | |
29 | ||
30 | syntax match jsSpecial "\\\d\d\d\|\\." | |
31 | syntax region jsStringD start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsSpecial,@htmlPreproc | |
32 | syntax region jsStringS start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=jsSpecial,@htmlPreproc | |
33 | syntax region jsRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\?\s*$+ end=+/[gi]\?\s*[;.,)]+me=e-1 contains=@htmlPreproc oneline | |
34 | syntax match jsNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" | |
35 | ||
36 | syntax keyword jsCommentTodo TODO FIXME XXX TBD contained | |
37 | syntax region jsLineComment start=+\/\/+ end=/$/ contains=jsCommentTodo oneline | |
38 | syntax region jsComment start="/\*" end="\*/" contains=jsCommentTodo,jsLineComment | |
39 | ||
40 | syntax match jsLabel /\(?\s*\)\@<!\w\+\(\s*:\)\@=/ | |
41 | ||
42 | "" Programm Keywords | |
43 | syntax keyword jsSource import export | |
44 | syntax keyword jsType this var const void | |
45 | syntax keyword jsOperator delete new in instanceof typeof | |
46 | syntax keyword jsBoolean true false | |
47 | syntax keyword jsNull null | |
48 | ||
49 | "" Statement Keywords | |
50 | syntax keyword jsConditional if else | |
51 | syntax keyword jsRepeat while for | |
52 | syntax keyword jsBranch break continue switch case default return | |
53 | syntax keyword jsStatement try catch throw with | |
54 | ||
55 | syntax keyword jsGlobalObjects Array Boolean Date Error Function java JavaArray JavaClass JavaObject JavaPackage Math netscape Number Object Packages RegExp String sun | |
56 | ||
57 | if exists("javaScript_fold") | |
58 | syntax match jsFunction "\<function\>" | |
59 | syntax region jsFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend | |
60 | ||
61 | syntax sync match jsSync grouphere jsFunctionFold "\<function\>" | |
62 | syntax sync match jsSync grouphere NONE "^}" | |
63 | ||
64 | setlocal foldmethod=syntax | |
65 | setlocal foldtext=getline(v:foldstart) | |
66 | else | |
67 | syntax keyword jsFunction function | |
68 | endif | |
69 | ||
70 | syntax sync fromstart | |
71 | syntax sync maxlines=100 | |
72 | ||
73 | " Code blocks | |
74 | syntax cluster jsAll contains=jsComment,jsSpecial,jsStringD,jsStringS,jsNumber,jsRegexpString,jsBoolean,jsFunction,jsFunctionFold,jsConditional,jsRepeat,jsBranch,jsOperator,jsType,jsStatement,jsBoolean,jsGlobalObjects | |
75 | syntax region jsBracket matchgroup=jsBracket transparent start="\[" end="\]" contains=@jsAll,jsBracket,jsParen,jsBlock | |
76 | syntax region jsParen matchgroup=jsParen transparent start="(" end=")" contains=@jsAll,jsParen,jsBracket,jsBlock | |
77 | syntax region jsBlock matchgroup=jsBlcok transparent start="{" end="}" contains=ALL | |
78 | ||
79 | " catch errors caused by wrong parenthesis | |
80 | syntax match jsParenError ")\|}\|\]" | |
81 | ||
82 | if main_syntax == "javascript" | |
83 | syntax sync ccomment jsComment | |
84 | endif | |
85 | ||
86 | " Define the default highlighting. | |
87 | " For version 5.7 and earlier: only when not done already | |
88 | " For version 5.8 and later: only when an item doesn't have highlighting yet | |
89 | if version >= 508 || !exists("did_javascript_syn_inits") | |
90 | if version < 508 | |
91 | let did_javascript_syn_inits = 1 | |
92 | command -nargs=+ HiLink hi link <args> | |
93 | else | |
94 | command -nargs=+ HiLink hi def link <args> | |
95 | endif | |
96 | HiLink jsComment Comment | |
97 | HiLink jsLineComment Comment | |
98 | HiLink jsCommentTodo Todo | |
99 | HiLink jsStringS String | |
100 | HiLink jsStringD String | |
101 | HiLink jsRegexpString String | |
102 | HiLink jsCharacter Character | |
103 | HiLink jsConditional Conditional | |
104 | HiLink jsBranch Conditional | |
105 | HiLink jsRepeat Repeat | |
106 | HiLink jsStatement Statement | |
107 | HiLink jsFunction Function | |
108 | HiLink jsBlock Function | |
109 | HiLink jsError Error | |
110 | HiLink jsParenError Error | |
111 | HiLink jsOperator Operator | |
112 | HiLink jsType Type | |
113 | HiLink jsNull Type | |
114 | HiLink jsNumber Number | |
115 | HiLink jsBoolean Boolean | |
116 | HiLink jsLabel Label | |
117 | HiLink jsSpecial Special | |
118 | HiLink jsSource Special | |
119 | HiLink jsGlobalObjects Special | |
120 | delcommand HiLink | |
121 | endif | |
122 | ||
123 | let b:current_syntax = "javascript" | |
124 | if main_syntax == 'javascript' | |
125 | unlet main_syntax | |
126 | endif | |
127 | ||
128 | " vim: ts=4 |