blob: 6d3c460d39d12cf563f2e469e6b3eba515939618 [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
56" Some terminal capabilites have special names like `#5' and `@1', and we
57" 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 Moolenaar89bcfda2016-08-30 23:26:57 +020073command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020075HiLink ptcapComment Comment
76HiLink ptcapDelimiter Delimiter
77" The highlighting of "ptcapEntry" should always be overridden by
78" its contents, so I use Todo highlighting to indicate that there
79" is work to be done with the syntax file if you can see it :-)
80HiLink ptcapEntry Todo
81HiLink ptcapError Error
82HiLink ptcapEscapedChar SpecialChar
83HiLink ptcapField Type
84HiLink ptcapLeadBlank NONE
85HiLink ptcapLineCont Special
86HiLink ptcapNames Label
87HiLink ptcapNumber NONE
88HiLink ptcapNumberError Error
89HiLink ptcapOperator Operator
90HiLink ptcapSpecialCap Type
91HiLink ptcapString NONE
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020093delcommand HiLink
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
95let b:current_syntax = "ptcap"
96
97" vim: sts=4 sw=4 ts=8