ptcap.vim 4.0 KB

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