home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / dos / syntax / rst.vim < prev    next >
Encoding:
Text File  |  2010-08-15  |  7.5 KB  |  176 lines

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