blob: 39b593d2beb51fa5b4f6ffd8e2a2a4eeae727775 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: CWEB
3" Maintainer: Andreas Scherer <andreas.scherer@pobox.com>
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01004" Last Change: 2011 Dec 25 by Thilo Six
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
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
16" For version 5.x: Clear all syntax items
17" For version 6.x: Quit when a syntax file was already loaded
18if version < 600
19 syntax clear
20elseif exists("b:current_syntax")
21 finish
22endif
23
24" For starters, read the TeX syntax; TeX syntax items are allowed at the top
25" level in the CWEB syntax, e.g., in the preamble. In general, a CWEB source
26" code can be seen as a normal TeX document with some C/C++ material
27" interspersed in certain defined regions.
28if version < 600
29 source <sfile>:p:h/tex.vim
30else
31 runtime! syntax/tex.vim
32 unlet b:current_syntax
33endif
34
35" Read the C/C++ syntax too; C/C++ syntax items are treated as such in the
36" C/C++ section of a CWEB chunk or in inner C/C++ context in "|...|" groups.
37syntax include @webIncludedC <sfile>:p:h/cpp.vim
38
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010039let s:cpo_save = &cpo
40set cpo&vim
41
Bram Moolenaar071d4272004-06-13 20:20:40 +000042" Inner C/C++ context (ICC) should be quite simple as it's comprised of
43" material in "|...|"; however the naive definition for this region would
44" hickup at the innocious "\|" TeX macro. Note: For the time being we expect
45" that an ICC begins either at the start of a line or after some white space.
46syntax region webInnerCcontext start="\(^\|[ \t\~`(]\)|" end="|" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
47
48" Genuine C/C++ material. This syntactic region covers both the definition
49" part and the C/C++ part of a CWEB section; it is ended by the TeX part of
50" the next section.
51syntax region webCpart start="@[dfscp<(]" end="@[ \*]" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
52
53" Section names contain C/C++ material only in inner context.
54syntax region webSectionName start="@[<(]" end="@>" contains=webInnerCcontext contained
55
56" The contents of "control texts" is not treated as TeX material, because in
57" non-trivial cases this completely clobbers the syntax recognition. Instead,
58" we highlight these elements as "strings".
59syntax region webRestrictedTeX start="@[\^\.:t=q]" end="@>" oneline
60
61" Double-@ means single-@, anywhere in the CWEB source. (This allows e-mail
62" address <someone@@fsf.org> without going into C/C++ mode.)
63syntax match webIgnoredStuff "@@"
64
65" Define the default highlighting.
66" For version 5.7 and earlier: only when not done already
67" For version 5.8 and later: only when an item doesn't have highlighting yet
68if version >= 508 || !exists("did_cweb_syntax_inits")
69 if version < 508
70 let did_cweb_syntax_inits = 1
71 command -nargs=+ HiLink hi link <args>
72 else
73 command -nargs=+ HiLink hi def link <args>
74 endif
75
76 HiLink webRestrictedTeX String
77
78 delcommand HiLink
79endif
80
81let b:current_syntax = "cweb"
82
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010083let &cpo = s:cpo_save
84unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +000085" vim: ts=8