Mercurial > hg > RemoteEditor > vim7
comparison runtime/syntax/rst.vim @ 0:76efa0be13f1
Initial revision
author | atsuki |
---|---|
date | Sat, 10 Nov 2007 15:07:22 +0900 |
parents | |
children | c16898406ff2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76efa0be13f1 |
---|---|
1 " Vim syntax file | |
2 " Language: reStructuredText documentation format | |
3 " Maintainer: Nikolai Weibull <now@bitwi.se> | |
4 " Latest Revision: 2006-07-04 | |
5 | |
6 if exists("b:current_syntax") | |
7 finish | |
8 endif | |
9 | |
10 let s:cpo_save = &cpo | |
11 set cpo&vim | |
12 | |
13 syn case ignore | |
14 | |
15 " FIXME: The problem with these two is that Vim doesn’t seem to like | |
16 " matching across line boundaries. | |
17 " | |
18 " syn match rstSections /^.*\n[=`:.'"~^_*+#-]\+$/ | |
19 | |
20 " syn match rstTransition /^\s*[=`:.'"~^_*+#-]\{4,}\s*$/ | |
21 | |
22 syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis, | |
23 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference, | |
24 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference | |
25 | |
26 syn region rstLiteralBlock matchgroup=rstDelimiter | |
27 \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!' | |
28 \ contains=@NoSpell | |
29 | |
30 syn region rstQuotedLiteralBlock matchgroup=rstDelimiter | |
31 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)" | |
32 \ end='^\z1\@!' contains=@NoSpell | |
33 | |
34 syn region rstDoctestBlock oneline display matchgroup=rstDelimiter | |
35 \ start='^>>>\s' end='^$' | |
36 | |
37 syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$' | |
38 \ contains=rstTableLines,@rstCruft | |
39 syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\=' | |
40 | |
41 syn region rstSimpleTable transparent | |
42 \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
43 \ end='^$' | |
44 \ contains=rstSimpleTableLines,@rstCruft | |
45 syn match rstSimpleTableLines contained display | |
46 \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
47 syn match rstSimpleTableLines contained display | |
48 \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
49 | |
50 syn cluster rstDirectives contains=rstFootnote,rstCitation, | |
51 \ rstHyperlinkTarget,rstExDirective | |
52 | |
53 syn match rstExplicitMarkup '^\.\.\_s' | |
54 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition | |
55 | |
56 let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*' | |
57 | |
58 syn keyword rstTodo contained FIXME TODO XXX NOTE | |
59 | |
60 execute 'syn region rstComment contained' . | |
61 \ ' start=/.*/' | |
62 \ ' end=/^\s\@!/ contains=rstTodo' | |
63 | |
64 execute 'syn region rstFootnote contained matchgroup=rstDirective' . | |
65 \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' . | |
66 \ ' skip=+^$+' . | |
67 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
68 | |
69 execute 'syn region rstCitation contained matchgroup=rstDirective' . | |
70 \ ' start=+\[' . s:ReferenceName . '\]\_s+' . | |
71 \ ' skip=+^$+' . | |
72 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
73 | |
74 syn region rstHyperlinkTarget contained matchgroup=rstDirective | |
75 \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+ | |
76 | |
77 syn region rstHyperlinkTarget contained matchgroup=rstDirective | |
78 \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+ | |
79 | |
80 syn region rstHyperlinkTarget matchgroup=rstDirective | |
81 \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+ | |
82 | |
83 execute 'syn region rstExDirective contained matchgroup=rstDirective' . | |
84 \ ' start=+' . s:ReferenceName . '::\_s+' . | |
85 \ ' skip=+^$+' . | |
86 \ ' end=+^\s\@!+ contains=@rstCruft' | |
87 | |
88 execute 'syn match rstSubstitutionDefinition contained' . | |
89 \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives' | |
90 | |
91 function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right) | |
92 execute 'syn region rst' . a:name . | |
93 \ ' start=+' . a:char_left . '\zs' . a:start . | |
94 \ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' . | |
95 \ a:middle . | |
96 \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
97 endfunction | |
98 | |
99 function! s:DefineInlineMarkup(name, start, middle, end) | |
100 let middle = a:middle != "" ? | |
101 \ (' skip=+\\\\\|\\' . a:middle . '+') : | |
102 \ "" | |
103 | |
104 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'") | |
105 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"') | |
106 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '(', ')') | |
107 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\[', '\]') | |
108 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '{', '}') | |
109 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '<', '>') | |
110 | |
111 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '') | |
112 | |
113 execute 'syn match rst' . a:name . | |
114 \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start . | |
115 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' | |
116 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
117 | |
118 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name | |
119 endfunction | |
120 | |
121 call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') | |
122 call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') | |
123 call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') | |
124 call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') | |
125 call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') | |
126 call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') | |
127 | |
128 " TODO: Can’t remember why these two can’t be defined like the ones above. | |
129 execute 'syn match rstFootnoteReference contains=@NoSpell' . | |
130 \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+' | |
131 | |
132 execute 'syn match rstCitationReference contains=@NoSpell' . | |
133 \ ' +\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
134 | |
135 execute 'syn match rstHyperlinkReference' . | |
136 \ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/' | |
137 | |
138 syn match rstStandaloneHyperlink contains=@NoSpell | |
139 \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]" | |
140 | |
141 " TODO: Use better syncing. I don’t know the specifics of syncing well enough, | |
142 " though. | |
143 syn sync minlines=50 | |
144 | |
145 hi def link rstTodo Todo | |
146 hi def link rstComment Comment | |
147 "hi def link rstSections Type | |
148 "hi def link rstTransition Type | |
149 hi def link rstLiteralBlock String | |
150 hi def link rstQuotedLiteralBlock String | |
151 hi def link rstDoctestBlock PreProc | |
152 hi def link rstTableLines rstDelimiter | |
153 hi def link rstSimpleTableLines rstTableLines | |
154 hi def link rstExplicitMarkup rstDirective | |
155 hi def link rstDirective Keyword | |
156 hi def link rstFootnote String | |
157 hi def link rstCitation String | |
158 hi def link rstHyperlinkTarget String | |
159 hi def link rstExDirective String | |
160 hi def link rstSubstitutionDefinition rstDirective | |
161 hi def link rstDelimiter Delimiter | |
162 " TODO: I dunno... | |
163 hi def rstEmphasis term=italic cterm=italic gui=italic | |
164 hi def link rstStrongEmphasis Special | |
165 "term=bold cterm=bold gui=bold | |
166 hi def link rstInterpretedTextOrHyperlinkReference Identifier | |
167 hi def link rstInlineLiteral String | |
168 hi def link rstSubstitutionReference PreProc | |
169 hi def link rstInlineInternalTargets Identifier | |
170 hi def link rstFootnoteReference Identifier | |
171 hi def link rstCitationReference Identifier | |
172 hi def link rstHyperLinkReference Identifier | |
173 hi def link rstStandaloneHyperlink Identifier | |
174 | |
175 let b:current_syntax = "rst" | |
176 | |
177 let &cpo = s:cpo_save | |
178 unlet s:cpo_save |