xref: /vim-8.2.3635/runtime/syntax/cweb.vim (revision f37506f6)
1071d4279SBram Moolenaar" Vim syntax file
2071d4279SBram Moolenaar" Language:	CWEB
3071d4279SBram Moolenaar" Maintainer:	Andreas Scherer <[email protected]>
4b6b046b2SBram Moolenaar" Last Change:	2011 Dec 25 by Thilo Six
5071d4279SBram Moolenaar
6071d4279SBram Moolenaar" Details of the CWEB language can be found in the article by Donald E. Knuth
7071d4279SBram Moolenaar" and Silvio Levy, "The CWEB System of Structured Documentation", included as
8071d4279SBram Moolenaar" file "cwebman.tex" in the standard CWEB distribution, available for
9071d4279SBram Moolenaar" anonymous ftp at ftp://labrea.stanford.edu/pub/cweb/.
10071d4279SBram Moolenaar
11071d4279SBram Moolenaar" TODO: Section names and C/C++ comments should be treated as TeX material.
12071d4279SBram Moolenaar" TODO: The current version switches syntax highlighting off for section
13071d4279SBram Moolenaar" TODO: names, and leaves C/C++ comments as such. (On the other hand,
14071d4279SBram Moolenaar" TODO: switching to TeX mode in C/C++ comments might be colour overkill.)
15071d4279SBram Moolenaar
1689bcfda6SBram Moolenaar" quit when a syntax file was already loaded
1789bcfda6SBram Moolenaarif exists("b:current_syntax")
18071d4279SBram Moolenaar  finish
19071d4279SBram Moolenaarendif
20071d4279SBram Moolenaar
21071d4279SBram Moolenaar" For starters, read the TeX syntax; TeX syntax items are allowed at the top
22071d4279SBram Moolenaar" level in the CWEB syntax, e.g., in the preamble.  In general, a CWEB source
23071d4279SBram Moolenaar" code can be seen as a normal TeX document with some C/C++ material
24071d4279SBram Moolenaar" interspersed in certain defined regions.
25071d4279SBram Moolenaarruntime! syntax/tex.vim
26071d4279SBram Moolenaarunlet b:current_syntax
27071d4279SBram Moolenaar
28071d4279SBram Moolenaar" Read the C/C++ syntax too; C/C++ syntax items are treated as such in the
29071d4279SBram Moolenaar" C/C++ section of a CWEB chunk or in inner C/C++ context in "|...|" groups.
30071d4279SBram Moolenaarsyntax include @webIncludedC <sfile>:p:h/cpp.vim
31071d4279SBram Moolenaar
32b6b046b2SBram Moolenaarlet s:cpo_save = &cpo
33b6b046b2SBram Moolenaarset cpo&vim
34b6b046b2SBram Moolenaar
35071d4279SBram Moolenaar" Inner C/C++ context (ICC) should be quite simple as it's comprised of
36071d4279SBram Moolenaar" material in "|...|"; however the naive definition for this region would
37071d4279SBram Moolenaar" hickup at the innocious "\|" TeX macro.  Note: For the time being we expect
38071d4279SBram Moolenaar" that an ICC begins either at the start of a line or after some white space.
39071d4279SBram Moolenaarsyntax region webInnerCcontext start="\(^\|[ \t\~`(]\)|" end="|" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
40071d4279SBram Moolenaar
41071d4279SBram Moolenaar" Genuine C/C++ material.  This syntactic region covers both the definition
42071d4279SBram Moolenaar" part and the C/C++ part of a CWEB section; it is ended by the TeX part of
43071d4279SBram Moolenaar" the next section.
44071d4279SBram Moolenaarsyntax region webCpart start="@[dfscp<(]" end="@[ \*]" contains=@webIncludedC,webSectionName,webRestrictedTeX,webIgnoredStuff
45071d4279SBram Moolenaar
46071d4279SBram Moolenaar" Section names contain C/C++ material only in inner context.
47071d4279SBram Moolenaarsyntax region webSectionName start="@[<(]" end="@>" contains=webInnerCcontext contained
48071d4279SBram Moolenaar
49071d4279SBram Moolenaar" The contents of "control texts" is not treated as TeX material, because in
50071d4279SBram Moolenaar" non-trivial cases this completely clobbers the syntax recognition.  Instead,
51071d4279SBram Moolenaar" we highlight these elements as "strings".
52071d4279SBram Moolenaarsyntax region webRestrictedTeX start="@[\^\.:t=q]" end="@>" oneline
53071d4279SBram Moolenaar
54071d4279SBram Moolenaar" Double-@ means single-@, anywhere in the CWEB source.  (This allows e-mail
55071d4279SBram Moolenaar" address <someone@@fsf.org> without going into C/C++ mode.)
56071d4279SBram Moolenaarsyntax match webIgnoredStuff "@@"
57071d4279SBram Moolenaar
58071d4279SBram Moolenaar" Define the default highlighting.
5989bcfda6SBram Moolenaar" Only when an item doesn't have highlighting yet
60071d4279SBram Moolenaar
61*f37506f6SBram Moolenaarhi def link webRestrictedTeX String
62071d4279SBram Moolenaar
63071d4279SBram Moolenaar
64071d4279SBram Moolenaarlet b:current_syntax = "cweb"
65071d4279SBram Moolenaar
66b6b046b2SBram Moolenaarlet &cpo = s:cpo_save
67b6b046b2SBram Moolenaarunlet s:cpo_save
68071d4279SBram Moolenaar" vim: ts=8
69