3 " Maintainer: Haakon Riiser <haakon@riiser.net>
4 " Last Change: 2001 May 10
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.
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
13 elseif exists("b:current_syntax")
17 syn match sedError "\S"
19 syn match sedWhitespace "\s\+" contained
20 syn match sedSemicolon ";"
21 syn match sedAddress "[[:digit:]$]"
22 syn match sedAddress "\d\+\~\d\+"
23 syn region sedAddress matchgroup=Special start="[{,;]\s*/\(\\/\)\="lc=1 skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
24 syn region sedAddress matchgroup=Special start="^\s*/\(\\/\)\=" skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta
25 syn match sedComment "^\s*#.*$"
26 syn match sedFunction "[dDgGhHlnNpPqx=]\s*\($\|;\)" contains=sedSemicolon,sedWhitespace
27 syn match sedLabel ":[^;]*"
28 syn match sedLineCont "^\(\\\\\)*\\$" contained
29 syn match sedLineCont "[^\\]\(\\\\\)*\\$"ms=e contained
30 syn match sedSpecial "[{},!]"
31 if exists("highlight_sedtabs")
32 syn match sedTab "\t" contained
35 " Append/Change/Insert
36 syn region sedACI matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab
38 syn region sedBranch matchgroup=sedFunction start="[bt]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
39 syn region sedRW matchgroup=sedFunction start="[rw]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace
41 " Substitution/transform with various delimiters
42 syn region sedFlagwrite matchgroup=sedFlag start="w" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace contained
43 syn match sedFlag "[[:digit:]gpI]*w\=" contains=sedFlagwrite contained
44 syn match sedRegexpMeta "[.*^$]" contained
45 syn match sedRegexpMeta "\\." contains=sedTab contained
46 syn match sedRegexpMeta "\[.\{-}\]" contains=sedTab contained
47 syn match sedRegexpMeta "\\{\d\*,\d*\\}" contained
48 syn match sedRegexpMeta "\\(.\{-}\\)" contains=sedTab contained
49 syn match sedReplaceMeta "&\|\\\($\|.\)" contains=sedTab contained
51 " Metacharacters: $ * . \ ^ [ ~
52 " @ is used as delimiter and treated on its own below
53 let __at = char2nr("@")
54 let __sed_i = char2nr(" ")
60 let __sed_metacharacters = '$*.\^[~'
61 while __sed_i <= __sed_last
62 let __sed_delimiter = escape(nr2char(__sed_i), __sed_metacharacters)
64 exe 'syn region sedAddress matchgroup=Special start=@\\'.__sed_delimiter.'\(\\'.__sed_delimiter.'\)\=@ skip=@[^\\]\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'I\=@ contains=sedTab'
65 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
66 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'
68 let __sed_i = __sed_i + 1
70 syn region sedAddress matchgroup=Special start=+\\@\(\\@\)\=+ skip=+[^\\]\(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta
71 syn region sedRegexp64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64
72 syn region sedReplacement64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag
74 " Since the syntax for the substituion command is very similar to the
75 " syntax for the transform command, I use the same pattern matching
76 " for both commands. There is one problem -- the transform command
77 " (y) does not allow any flags. To save memory, I ignore this problem.
78 syn match sedST "[sy]" nextgroup=sedRegexp\d\+
80 if version >= 508 || !exists("did_sed_syntax_inits")
82 let did_sed_syntax_inits = 1
83 command -nargs=+ HiLink hi link <args>
85 command -nargs=+ HiLink hi def link <args>
88 HiLink sedAddress Macro
90 HiLink sedBranch Label
91 HiLink sedComment Comment
92 HiLink sedDelete Function
95 HiLink sedFlagwrite Constant
96 HiLink sedFunction Function
98 HiLink sedLineCont Special
99 HiLink sedPutHoldspc Function
100 HiLink sedReplaceMeta Special
101 HiLink sedRegexpMeta Special
102 HiLink sedRW Constant
103 HiLink sedSemicolon Special
104 HiLink sedST Function
105 HiLink sedSpecial Special
106 HiLink sedWhitespace NONE
107 if exists("highlight_sedtabs")
112 exe "HiLink sedRegexp".__sed_i "Macro"
113 exe "HiLink sedReplacement".__sed_i "NONE"
114 let __sed_i = __sed_i + 1
120 unlet __sed_i __sed_delimiter __sed_metacharacters
122 let b:current_syntax = "sed"
124 " vim: sts=4 sw=4 ts=8