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