1" Vim syntax file
2" Language:	printcap/termcap database
3" Maintainer:	Haakon Riiser <hakonrk@fys.uio.no>
4" URL:		http://folk.uio.no/hakonrk/vim/syntax/ptcap.vim
5" Last Change:	2001 May 15
6
7" For version 5.x: Clear all syntax items
8" For version 6.x: Quit when a syntax file was already loaded
9if version < 600
10    syn clear
11elseif exists("b:current_syntax")
12    finish
13endif
14
15" Since I only highlight based on the structure of the databases, not
16" specific keywords, case sensitivity isn't required
17syn case ignore
18
19" Since everything that is not caught by the syntax patterns is assumed
20" to be an error, we start parsing 20 lines up, unless something else
21" is specified
22if exists("ptcap_minlines")
23    exe "syn sync lines=".ptcap_minlines
24else
25    syn sync lines=20
26endif
27
28" Highlight everything that isn't caught by the rules as errors,
29" except blank lines
30syn match ptcapError	    "^.*\S.*$"
31
32syn match ptcapLeadBlank    "^\s\+" contained
33
34" `:' and `|' are delimiters for fields and names, and should not be
35" highlighted.	Hence, they are linked to `NONE'
36syn match ptcapDelimiter    "[:|]" contained
37
38" Escaped characters receive special highlighting
39syn match ptcapEscapedChar  "\\." contained
40syn match ptcapEscapedChar  "\^." contained
41syn match ptcapEscapedChar  "\\\o\{3}" contained
42
43" A backslash at the end of a line will suppress the newline
44syn match ptcapLineCont	    "\\$" contained
45
46" A number follows the same rules as an integer in C
47syn match ptcapNumber	    "#\(+\|-\)\=\d\+"lc=1 contained
48syn match ptcapNumberError  "#\d*[^[:digit:]:\\]"lc=1 contained
49syn match ptcapNumber	    "#0x\x\{1,8}"lc=1 contained
50syn match ptcapNumberError  "#0x\X"me=e-1,lc=1 contained
51syn match ptcapNumberError  "#0x\x\{9}"lc=1 contained
52syn match ptcapNumberError  "#0x\x*[^[:xdigit:]:\\]"lc=1 contained
53
54" The `@' operator clears a flag (i.e., sets it to zero)
55" The `#' operator assigns a following number to the flag
56" The `=' operator assigns a string to the preceding flag
57syn match ptcapOperator	    "[@#=]" contained
58
59" Some terminal capabilites have special names like `#5' and `@1', and we
60" need special rules to match these properly
61syn match ptcapSpecialCap   "\W[#@]\d" contains=ptcapDelimiter contained
62
63" If editing a termcap file, an entry in the database is terminated by
64" a (non-escaped) newline.  Otherwise, it is terminated by a line which
65" does not start with a colon (:)
66if exists("b:ptcap_type") && b:ptcap_type[0] == 't'
67    syn region ptcapEntry   start="^\s*[^[:space:]:]" end="[^\\]\(\\\\\)*$" end="^$" contains=ptcapNames,ptcapField,ptcapLeadBlank keepend
68else
69    syn region ptcapEntry   start="^\s*[^[:space:]:]"me=e-1 end="^\s*[^[:space:]:#]"me=e-1 contains=ptcapNames,ptcapField,ptcapLeadBlank,ptcapComment
70endif
71syn region ptcapNames	    start="^\s*[^[:space:]:]" skip="[^\\]\(\\\\\)*\\:" end=":"me=e-1 contains=ptcapDelimiter,ptcapEscapedChar,ptcapLineCont,ptcapLeadBlank,ptcapComment keepend contained
72syn region ptcapField	    start=":" skip="[^\\]\(\\\\\)*\\$" end="[^\\]\(\\\\\)*:"me=e-1 end="$" contains=ptcapDelimiter,ptcapString,ptcapNumber,ptcapNumberError,ptcapOperator,ptcapLineCont,ptcapSpecialCap,ptcapLeadBlank,ptcapComment keepend contained
73syn region ptcapString	    matchgroup=ptcapOperator start="=" skip="[^\\]\(\\\\\)*\\:" matchgroup=ptcapDelimiter end=":"me=e-1 matchgroup=NONE end="[^\\]\(\\\\\)*[^\\]$" end="^$" contains=ptcapEscapedChar,ptcapLineCont keepend contained
74syn region ptcapComment	    start="^\s*#" end="$" contains=ptcapLeadBlank
75
76if version >= 508 || !exists("did_ptcap_syntax_inits")
77    if version < 508
78	let did_ptcap_syntax_inits = 1
79	command -nargs=+ HiLink hi link <args>
80    else
81	command -nargs=+ HiLink hi def link <args>
82    endif
83
84    HiLink ptcapComment		Comment
85    HiLink ptcapDelimiter	Delimiter
86    " The highlighting of "ptcapEntry" should always be overridden by
87    " its contents, so I use Todo highlighting to indicate that there
88    " is work to be done with the syntax file if you can see it :-)
89    HiLink ptcapEntry		Todo
90    HiLink ptcapError		Error
91    HiLink ptcapEscapedChar	SpecialChar
92    HiLink ptcapField		Type
93    HiLink ptcapLeadBlank	NONE
94    HiLink ptcapLineCont	Special
95    HiLink ptcapNames		Label
96    HiLink ptcapNumber		NONE
97    HiLink ptcapNumberError	Error
98    HiLink ptcapOperator	Operator
99    HiLink ptcapSpecialCap	Type
100    HiLink ptcapString		NONE
101
102    delcommand HiLink
103endif
104
105let b:current_syntax = "ptcap"
106
107" vim: sts=4 sw=4 ts=8
108