Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: sed |
| 3 | " Maintainer: Haakon Riiser <hakonrk@fys.uio.no> |
| 4 | " URL: http://folk.uio.no/hakonrk/vim/syntax/sed.vim |
Bram Moolenaar | 9db5806 | 2010-05-29 20:33:07 +0200 | [diff] [blame] | 5 | " Last Change: 2010 May 29 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 7 | " quit when a syntax file was already loaded |
| 8 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | finish |
| 10 | endif |
| 11 | |
| 12 | syn match sedError "\S" |
| 13 | |
| 14 | syn match sedWhitespace "\s\+" contained |
| 15 | syn match sedSemicolon ";" |
| 16 | syn match sedAddress "[[:digit:]$]" |
| 17 | syn match sedAddress "\d\+\~\d\+" |
| 18 | syn region sedAddress matchgroup=Special start="[{,;]\s*/\(\\/\)\="lc=1 skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta |
| 19 | syn region sedAddress matchgroup=Special start="^\s*/\(\\/\)\=" skip="[^\\]\(\\\\\)*\\/" end="/I\=" contains=sedTab,sedRegexpMeta |
| 20 | syn match sedComment "^\s*#.*$" |
Bram Moolenaar | 12033fb | 2005-12-16 21:49:31 +0000 | [diff] [blame] | 21 | syn match sedFunction "[dDgGhHlnNpPqQx=]\s*\($\|;\)" contains=sedSemicolon,sedWhitespace |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 22 | syn match sedLabel ":[^;]*" |
| 23 | syn match sedLineCont "^\(\\\\\)*\\$" contained |
| 24 | syn match sedLineCont "[^\\]\(\\\\\)*\\$"ms=e contained |
| 25 | syn match sedSpecial "[{},!]" |
| 26 | if exists("highlight_sedtabs") |
| 27 | syn match sedTab "\t" contained |
| 28 | endif |
| 29 | |
| 30 | " Append/Change/Insert |
| 31 | syn region sedACI matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab |
| 32 | |
| 33 | syn region sedBranch matchgroup=sedFunction start="[bt]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace |
| 34 | syn region sedRW matchgroup=sedFunction start="[rw]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace |
| 35 | |
| 36 | " Substitution/transform with various delimiters |
| 37 | syn region sedFlagwrite matchgroup=sedFlag start="w" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace contained |
| 38 | syn match sedFlag "[[:digit:]gpI]*w\=" contains=sedFlagwrite contained |
| 39 | syn match sedRegexpMeta "[.*^$]" contained |
| 40 | syn match sedRegexpMeta "\\." contains=sedTab contained |
| 41 | syn match sedRegexpMeta "\[.\{-}\]" contains=sedTab contained |
| 42 | syn match sedRegexpMeta "\\{\d\*,\d*\\}" contained |
| 43 | syn match sedRegexpMeta "\\(.\{-}\\)" contains=sedTab contained |
| 44 | syn match sedReplaceMeta "&\|\\\($\|.\)" contains=sedTab contained |
| 45 | |
| 46 | " Metacharacters: $ * . \ ^ [ ~ |
| 47 | " @ is used as delimiter and treated on its own below |
| 48 | let __at = char2nr("@") |
Bram Moolenaar | 9db5806 | 2010-05-29 20:33:07 +0200 | [diff] [blame] | 49 | let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 50 | if has("ebcdic") |
| 51 | let __sed_last = 255 |
| 52 | else |
| 53 | let __sed_last = 126 |
| 54 | endif |
| 55 | let __sed_metacharacters = '$*.\^[~' |
| 56 | while __sed_i <= __sed_last |
| 57 | let __sed_delimiter = escape(nr2char(__sed_i), __sed_metacharacters) |
| 58 | if __sed_i != __at |
| 59 | exe 'syn region sedAddress matchgroup=Special start=@\\'.__sed_delimiter.'\(\\'.__sed_delimiter.'\)\=@ skip=@[^\\]\(\\\\\)*\\'.__sed_delimiter.'@ end=@'.__sed_delimiter.'I\=@ contains=sedTab' |
| 60 | 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 |
| 61 | 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' |
| 62 | endif |
| 63 | let __sed_i = __sed_i + 1 |
| 64 | endwhile |
| 65 | syn region sedAddress matchgroup=Special start=+\\@\(\\@\)\=+ skip=+[^\\]\(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta |
| 66 | syn region sedRegexp64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64 |
| 67 | syn region sedReplacement64 matchgroup=Special start=+@\(\\\\\|\\@\)*+ skip=+[^\\@]\(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag |
| 68 | |
| 69 | " Since the syntax for the substituion command is very similar to the |
| 70 | " syntax for the transform command, I use the same pattern matching |
| 71 | " for both commands. There is one problem -- the transform command |
| 72 | " (y) does not allow any flags. To save memory, I ignore this problem. |
| 73 | syn match sedST "[sy]" nextgroup=sedRegexp\d\+ |
| 74 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 75 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 76 | hi def link sedAddress Macro |
| 77 | hi def link sedACI NONE |
| 78 | hi def link sedBranch Label |
| 79 | hi def link sedComment Comment |
| 80 | hi def link sedDelete Function |
| 81 | hi def link sedError Error |
| 82 | hi def link sedFlag Type |
| 83 | hi def link sedFlagwrite Constant |
| 84 | hi def link sedFunction Function |
| 85 | hi def link sedLabel Label |
| 86 | hi def link sedLineCont Special |
| 87 | hi def link sedPutHoldspc Function |
| 88 | hi def link sedReplaceMeta Special |
| 89 | hi def link sedRegexpMeta Special |
| 90 | hi def link sedRW Constant |
| 91 | hi def link sedSemicolon Special |
| 92 | hi def link sedST Function |
| 93 | hi def link sedSpecial Special |
| 94 | hi def link sedWhitespace NONE |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 95 | if exists("highlight_sedtabs") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 96 | hi def link sedTab Todo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 97 | endif |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 98 | let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64 |
| 99 | while __sed_i <= __sed_last |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 100 | exe "hi def link sedRegexp".__sed_i "Macro" |
| 101 | exe "hi def link sedReplacement".__sed_i "NONE" |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 102 | let __sed_i = __sed_i + 1 |
| 103 | endwhile |
| 104 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 105 | |
Bram Moolenaar | 9db5806 | 2010-05-29 20:33:07 +0200 | [diff] [blame] | 106 | unlet __sed_i __sed_last __sed_delimiter __sed_metacharacters |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | |
| 108 | let b:current_syntax = "sed" |
| 109 | |
| 110 | " vim: sts=4 sw=4 ts=8 |