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