cweb.vim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. " Vim syntax file
  2. " Language: CWEB
  3. " Maintainer: Andreas Scherer <andreas.scherer@pobox.com>
  4. " Last Change: 2011 Dec 25 by Thilo Six
  5. " Details of the CWEB language can be found in the article by Donald E. Knuth
  6. " and Silvio Levy, "The CWEB System of Structured Documentation", included as
  7. " file "cwebman.tex" in the standard CWEB distribution, available for
  8. " anonymous ftp at ftp://labrea.stanford.edu/pub/cweb/.
  9. " TODO: Section names and C/C++ comments should be treated as TeX material.
  10. " TODO: The current version switches syntax highlighting off for section
  11. " TODO: names, and leaves C/C++ comments as such. (On the other hand,
  12. " TODO: switching to TeX mode in C/C++ comments might be colour overkill.)
  13. " quit when a syntax file was already loaded
  14. if exists("b:current_syntax")
  15. finish
  16. endif
  17. " For starters, read the TeX syntax; TeX syntax items are allowed at the top
  18. " level in the CWEB syntax, e.g., in the preamble. In general, a CWEB source
  19. " code can be seen as a normal TeX document with some C/C++ material
  20. " interspersed in certain defined regions.
  21. runtime! syntax/tex.vim
  22. unlet b:current_syntax
  23. " Read the C/C++ syntax too; C/C++ syntax items are treated as such in the
  24. " C/C++ section of a CWEB chunk or in inner C/C++ context in "|...|" groups.
  25. syntax include @webIncludedC <sfile>:p:h/cpp.vim
  26. let s:cpo_save = &cpo
  27. set cpo&vim
  28. " Inner C/C++ context (ICC) should be quite simple as it's comprised of
  29. " material in "|...|"; however the naive definition for this region would
  30. " hickup at the innocious "\|" TeX macro. Note: For the time being we expect
  31. " that an ICC begins either at the start of a line or after some white space.
  32. syntax region webInnerCcontext start="\(^\|[ \t\~`(]\)|" end="|" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
  33. " Genuine C/C++ material. This syntactic region covers both the definition
  34. " part and the C/C++ part of a CWEB section; it is ended by the TeX part of
  35. " the next section.
  36. syntax region webCpart start="@[dfscp<(]" end="@[ \*]" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
  37. " Section names contain C/C++ material only in inner context.
  38. syntax region webSectionName start="@[<(]" end="@>" contains=webInnerCcontext contained
  39. " The contents of "control texts" is not treated as TeX material, because in
  40. " non-trivial cases this completely clobbers the syntax recognition. Instead,
  41. " we highlight these elements as "strings".
  42. syntax region webRestrictedTeX start="@[\^\.:t=q]" end="@>" oneline
  43. " Double-@ means single-@, anywhere in the CWEB source. (This allows e-mail
  44. " address <someone@@fsf.org> without going into C/C++ mode.)
  45. syntax match webIgnoredStuff "@@"
  46. " Define the default highlighting.
  47. " Only when an item doesn't have highlighting yet
  48. hi def link webRestrictedTeX String
  49. let b:current_syntax = "cweb"
  50. let &cpo = s:cpo_save
  51. unlet s:cpo_save
  52. " vim: ts=8