Mercurial > vim
annotate runtime/syntax/sed.vim @ 8306:7fcf3f6020c1 v7.4.1445
commit https://github.com/vim/vim/commit/b36287283781e09d8874157b9d9bdc5243a2f319
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 28 14:56:39 2016 +0100
patch 7.4.1445
Problem: Memory corruption when 'encoding' is not utf-8.
Solution: Convert decoded string later.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 28 Feb 2016 15:00:04 +0100 |
parents | aa6412cab544 |
children | 43efa4f5a8ea |
rev | line source |
---|---|
7 | 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 | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
602
diff
changeset
|
5 " Last Change: 2010 May 29 |
7 | 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*#.*$" | |
602 | 24 syn match sedFunction "[dDgGhHlnNpPqQx=]\s*\($\|;\)" contains=sedSemicolon,sedWhitespace |
7 | 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("@") | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
602
diff
changeset
|
52 let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64 |
7 | 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 | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
602
diff
changeset
|
108 let __sed_i = char2nr(" ") " ASCII: 32, EBCDIC: 64 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
602
diff
changeset
|
109 while __sed_i <= __sed_last |
7 | 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 | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
602
diff
changeset
|
118 unlet __sed_i __sed_last __sed_delimiter __sed_metacharacters |
7 | 119 |
120 let b:current_syntax = "sed" | |
121 | |
122 " vim: sts=4 sw=4 ts=8 |