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