home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / syntax / sed.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  4.5 KB  |  103 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:    sed
  3. " Maintainer:    Haakon Riiser <hakonrk@fys.uio.no>
  4. " Last change:    1999 Jul 02
  5. "
  6. " Special thanks go to Preben "Peppe" Guldberg for a lot of help, and, in
  7. " particular, his clever way of matching the substitute command.
  8.  
  9. " Clear old syntax defs
  10. syn clear
  11.  
  12. syn match sedError    "\S"
  13.  
  14. syn match sedSemicolon    ";"
  15. syn match sedAddress    "[[:digit:]$]"
  16. syn match sedAddress    "\d\+\~\d\+"
  17. syn region sedAddress    matchgroup=Special start="/\(\\/\)\=" skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
  18. syn match sedComment    "^\s*#.*$"
  19. syn match sedFunction    "[dDgGhHlnNpPqx=]\($\|;\)" contains=sedSemicolon
  20. syn match sedLabel    "^\s*:.*$"
  21. syn match sedLineCont    "^\(\\\\\)*\\$" contained
  22. syn match sedLineCont    "[^\\]\(\\\\\)*\\$"ms=e contained
  23. syn match sedSpecial    "[{},!]"
  24. if exists("highlight_sedtabs")
  25.     syn match sedTab    "\t" contained
  26. endif
  27.  
  28. " Append/Change/Insert
  29. syn region sedACI    matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab
  30.  
  31. syn region sedBranch    matchgroup=sedFunction start="[bt]" end="$"
  32. syn region sedRW    matchgroup=sedFunction start="[rw]" end="$"
  33.  
  34. " Substitution/transform with various delimiters
  35. syn region sedFlagwrite        matchgroup=sedFlag start="w" end="$" contained
  36. syn match sedFlag        "[[:digit:]gpI]*\(;\|$\|w\)" contains=sedFlagwrite,sedSemicolon contained
  37. syn match sedRegexpMeta        "[.*^$]" contained
  38. syn match sedRegexpMeta        "\\." contains=sedTab contained
  39. syn match sedRegexpMeta        "\[.\{-}\]" contains=sedTab contained
  40. syn match sedRegexpMeta        "\\{\d\*,\d*\\}" contained
  41. syn match sedRegexpMeta        "\\(.\{-}\\)" contains=sedTab contained
  42. syn match sedReplaceMeta    "&\|\\\($\|.\)" contains=sedTab contained
  43.  
  44. " Metacharacters: $ * . \ ^ [ ~
  45. " @ (ascii 64) is used as delimiter and treated on its own below
  46. let __sed_metacharacters = '$*.\^[~'
  47. let __sed_i = 32
  48. while __sed_i <= 126
  49.     let __sed_delimiter = escape(nr2char(__sed_i), __sed_metacharacters)
  50.     if __sed_i != 64
  51.         exe 'syn region sedAddress matchgroup=Special start=@\\'.__sed_delimiter.'\(\\'.__sed_delimiter.'\)\=@ skip=@[^\\]\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'I\=@ contains=sedTab'
  52.         exe 'syn region sedRegexp'.__sed_i  'matchgroup=Special start=@'.__sed_delimiter.'\(\\\\\|\\'.__sed_delimiter.'\)*@ skip=@[^\\'.__sed_delimiter.']\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'@me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement'.__sed_i
  53.         exe 'syn region sedReplacement'.__sed_i 'matchgroup=Special start=@'.__sed_delimiter.'\(\\\\\|\\'.__sed_delimiter.'\)*@ skip=@[^\\'.__sed_delimiter.']\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'@ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag'
  54.     endif
  55.     let __sed_i = __sed_i + 1
  56. endwhile
  57. syn region sedAddress matchgroup=Special start=+\\@\(\\@\)\=+ skip=+[^\\]\(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta
  58. syn region sedRegexp64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64
  59. syn region sedReplacement64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag
  60.  
  61. " Since the syntax for the substituion command is very similar to the
  62. " syntax for the transform command, I use the same pattern matching
  63. " for both commands.  There is one problem -- the transform command
  64. " (y) does not allow any flags.  To save memory, I ignore this problem.
  65. syn match sedST    "[sy]" nextgroup=sedRegexp\d\+
  66.  
  67. if !exists("did_sed_syntax_inits")
  68.     let did_sed_syntax_inits = 1
  69.     hi link sedAddress        Macro
  70.     hi link sedACI        NONE
  71.     hi link sedBranch        Label
  72.     hi link sedComment        Comment
  73.     hi link sedDelete        Function
  74.     hi link sedError        Error
  75.     hi link sedFlag        Type
  76.     hi link sedFlagwrite    Constant
  77.     hi link sedFunction        Function
  78.     hi link sedLabel        Label
  79.     hi link sedLineCont        Special
  80.     hi link sedPutHoldspc    Function
  81.     hi link sedReplaceMeta    Special
  82.     hi link sedRegexpMeta    Special
  83.     hi link sedRW        Constant
  84.     hi link sedSemicolon    Special
  85.     hi link sedST        Function
  86.     hi link sedSpecial        Special
  87.     if exists("highlight_sedtabs")
  88.         hi link sedTab        Todo
  89.     endif
  90.     let __sed_i = 32
  91.     while __sed_i <= 126
  92.     exe "hi link sedRegexp".__sed_i        "Macro"
  93.     exe "hi link sedReplacement".__sed_i    "NONE"
  94.     let __sed_i = __sed_i + 1
  95.     endwhile
  96. endif
  97.  
  98. unlet __sed_i __sed_delimiter __sed_metacharacters
  99.  
  100. let b:current_syntax = "sed"
  101.  
  102. " vim: sts=4 sw=4 ts=8
  103.