blob: 5db7bda89659a99af007dc214549a7586b7aaffb [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02007" quit when a syntax file was already loaded
8if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00009 finish
10endif
11
12" Since I only highlight based on the structure of the databases, not
13" specific keywords, case sensitivity isn't required
14syn case ignore
15
16" Since everything that is not caught by the syntax patterns is assumed
17" to be an error, we start parsing 20 lines up, unless something else
18" is specified
19if exists("ptcap_minlines")
20 exe "syn sync lines=".ptcap_minlines
21else
22 syn sync lines=20
23endif
24
25" Highlight everything that isn't caught by the rules as errors,
26" except blank lines
27syn match ptcapError "^.*\S.*$"
28
29syn match ptcapLeadBlank "^\s\+" contained
30
31" `:' and `|' are delimiters for fields and names, and should not be
32" highlighted. Hence, they are linked to `NONE'
33syn match ptcapDelimiter "[:|]" contained
34
35" Escaped characters receive special highlighting
36syn match ptcapEscapedChar "\\." contained
37syn match ptcapEscapedChar "\^." contained
38syn match ptcapEscapedChar "\\\o\{3}" contained
39
40" A backslash at the end of a line will suppress the newline
41syn match ptcapLineCont "\\$" contained
42
43" A number follows the same rules as an integer in C
44syn match ptcapNumber "#\(+\|-\)\=\d\+"lc=1 contained
45syn match ptcapNumberError "#\d*[^[:digit:]:\\]"lc=1 contained
46syn match ptcapNumber "#0x\x\{1,8}"lc=1 contained
47syn match ptcapNumberError "#0x\X"me=e-1,lc=1 contained
48syn match ptcapNumberError "#0x\x\{9}"lc=1 contained
49syn match ptcapNumberError "#0x\x*[^[:xdigit:]:\\]"lc=1 contained
50
51" The `@' operator clears a flag (i.e., sets it to zero)
52" The `#' operator assigns a following number to the flag
53" The `=' operator assigns a string to the preceding flag
54syn match ptcapOperator "[@#=]" contained
55
Bram Moolenaard13166e2022-11-18 21:49:57 +000056" Some terminal capabilities have special names like `#5' and `@1', and we
Bram Moolenaar071d4272004-06-13 20:20:40 +000057" need special rules to match these properly
58syn match ptcapSpecialCap "\W[#@]\d" contains=ptcapDelimiter contained
59
60" If editing a termcap file, an entry in the database is terminated by
61" a (non-escaped) newline. Otherwise, it is terminated by a line which
62" does not start with a colon (:)
63if exists("b:ptcap_type") && b:ptcap_type[0] == 't'
64 syn region ptcapEntry start="^\s*[^[:space:]:]" end="[^\\]\(\\\\\)*$" end="^$" contains=ptcapNames,ptcapField,ptcapLeadBlank keepend
65else
66 syn region ptcapEntry start="^\s*[^[:space:]:]"me=e-1 end="^\s*[^[:space:]:#]"me=e-1 contains=ptcapNames,ptcapField,ptcapLeadBlank,ptcapComment
67endif
68syn region ptcapNames start="^\s*[^[:space:]:]" skip="[^\\]\(\\\\\)*\\:" end=":"me=e-1 contains=ptcapDelimiter,ptcapEscapedChar,ptcapLineCont,ptcapLeadBlank,ptcapComment keepend contained
69syn region ptcapField start=":" skip="[^\\]\(\\\\\)*\\$" end="[^\\]\(\\\\\)*:"me=e-1 end="$" contains=ptcapDelimiter,ptcapString,ptcapNumber,ptcapNumberError,ptcapOperator,ptcapLineCont,ptcapSpecialCap,ptcapLeadBlank,ptcapComment keepend contained
70syn region ptcapString matchgroup=ptcapOperator start="=" skip="[^\\]\(\\\\\)*\\:" matchgroup=ptcapDelimiter end=":"me=e-1 matchgroup=NONE end="[^\\]\(\\\\\)*[^\\]$" end="^$" contains=ptcapEscapedChar,ptcapLineCont keepend contained
71syn region ptcapComment start="^\s*#" end="$" contains=ptcapLeadBlank
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
Bram Moolenaarf37506f2016-08-31 22:22:10 +020074hi def link ptcapComment Comment
75hi def link ptcapDelimiter Delimiter
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020076" The highlighting of "ptcapEntry" should always be overridden by
77" its contents, so I use Todo highlighting to indicate that there
78" is work to be done with the syntax file if you can see it :-)
Bram Moolenaarf37506f2016-08-31 22:22:10 +020079hi def link ptcapEntry Todo
80hi def link ptcapError Error
81hi def link ptcapEscapedChar SpecialChar
82hi def link ptcapField Type
83hi def link ptcapLeadBlank NONE
84hi def link ptcapLineCont Special
85hi def link ptcapNames Label
86hi def link ptcapNumber NONE
87hi def link ptcapNumberError Error
88hi def link ptcapOperator Operator
89hi def link ptcapSpecialCap Type
90hi def link ptcapString NONE
Bram Moolenaar071d4272004-06-13 20:20:40 +000091
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93let b:current_syntax = "ptcap"
94
95" vim: sts=4 sw=4 ts=8