Mercurial > vim
annotate runtime/syntax/sed.vim @ 32214:a4dafbd8b7d5 v9.0.1438
patch 9.0.1438: .fs files are falsely recognized as forth files
Commit: https://github.com/vim/vim/commit/065088d5549e7711668321cc5a77c9a9b684b142
Author: Johan Kotlinski <kotlinski@gmail.com>
Date: Sun Apr 2 20:29:38 2023 +0100
patch 9.0.1438: .fs files are falsely recognized as forth files
Problem: .fs files are falsely recognized as forth files.
Solution: Check 100 lines for something that looks like forth. (Johan
Kotlinski, closes #12219, closes #11988)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 02 Apr 2023 21:30:05 +0200 |
parents | 3295247d97a5 |
children |
rev | line source |
---|---|
7 | 1 " Vim syntax file |
30875 | 2 " Language: sed |
3 " Maintainer: Doug Kearns <dougkearns@gmail.com> | |
4 " Previous Maintainer: Haakon Riiser <hakonrk@fys.uio.no> | |
5 " Contributor: Jack Haden-Enneking | |
6 " Last Change: 2022 Oct 15 | |
7 | 7 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
2231
diff
changeset
|
8 " quit when a syntax file was already loaded |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
2231
diff
changeset
|
9 if exists("b:current_syntax") |
30875 | 10 finish |
7 | 11 endif |
12 | |
30875 | 13 syn keyword sedTodo contained TODO FIXME XXX |
14 | |
7 | 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\+" | |
30875 | 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 sedFunction "[dDgGhHlnNpPqQx=]\s*\%($\|;\)" contains=sedSemicolon,sedWhitespace | |
24 if exists("g:sed_dialect") && g:sed_dialect ==? "bsd" | |
25 syn match sedComment "^\s*#.*$" contains=sedTodo | |
26 else | |
27 syn match sedFunction "[dDgGhHlnNpPqQx=]\s*\ze#" contains=sedSemicolon,sedWhitespace | |
28 syn match sedComment "#.*$" contains=sedTodo | |
29 endif | |
7 | 30 syn match sedLabel ":[^;]*" |
30875 | 31 syn match sedLineCont "^\%(\\\\\)*\\$" contained |
32 syn match sedLineCont "[^\\]\%(\\\\\)*\\$"ms=e contained | |
7 | 33 syn match sedSpecial "[{},!]" |
30875 | 34 |
35 " continue to silently support the old name | |
36 let s:highlight_tabs = v:false | |
37 if exists("g:highlight_sedtabs") || get(g:, "sed_highlight_tabs", 0) | |
38 let s:highlight_tabs = v:true | |
39 syn match sedTab "\t" contained | |
7 | 40 endif |
41 | |
42 " Append/Change/Insert | |
43 syn region sedACI matchgroup=sedFunction start="[aci]\\$" matchgroup=NONE end="^.*$" contains=sedLineCont,sedTab | |
44 | |
45 syn region sedBranch matchgroup=sedFunction start="[bt]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace | |
46 syn region sedRW matchgroup=sedFunction start="[rw]" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace | |
47 | |
48 " Substitution/transform with various delimiters | |
30875 | 49 syn region sedFlagWrite matchgroup=sedFlag start="w" matchgroup=sedSemicolon end=";\|$" contains=sedWhitespace contained |
50 syn match sedFlag "[[:digit:]gpI]*w\=" contains=sedFlagWrite contained | |
7 | 51 syn match sedRegexpMeta "[.*^$]" contained |
52 syn match sedRegexpMeta "\\." contains=sedTab contained | |
53 syn match sedRegexpMeta "\[.\{-}\]" contains=sedTab contained | |
54 syn match sedRegexpMeta "\\{\d\*,\d*\\}" contained | |
30875 | 55 syn match sedRegexpMeta "\\%(.\{-}\\)" contains=sedTab contained |
56 syn match sedReplaceMeta "&\|\\\%($\|.\)" contains=sedTab contained | |
7 | 57 |
58 " Metacharacters: $ * . \ ^ [ ~ | |
59 " @ is used as delimiter and treated on its own below | |
30875 | 60 let s:at = char2nr("@") |
61 let s:i = char2nr(" ") " ASCII: 32, EBCDIC: 64 | |
7 | 62 if has("ebcdic") |
30875 | 63 let s:last = 255 |
7 | 64 else |
30875 | 65 let s:last = 126 |
7 | 66 endif |
30875 | 67 let s:metacharacters = '$*.\^[~' |
68 while s:i <= s:last | |
69 let s:delimiter = escape(nr2char(s:i), s:metacharacters) | |
70 if s:i != s:at | |
71 exe 'syn region sedAddress matchgroup=Special start=@\\'.s:delimiter.'\%(\\'.s:delimiter.'\)\=@ skip=@[^\\]\%(\\\\\)*\\'.s:delimiter.'@ end=@'.s:delimiter.'[IM]\=@ contains=sedTab' | |
72 exe 'syn region sedRegexp'.s:i 'matchgroup=Special start=@'.s:delimiter.'\%(\\\\\|\\'.s:delimiter.'\)*@ skip=@[^\\'.s:delimiter.']\%(\\\\\)*\\'.s:delimiter.'@ end=@'.s:delimiter.'@me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement'.s:i | |
73 exe 'syn region sedReplacement'.s:i 'matchgroup=Special start=@'.s:delimiter.'\%(\\\\\|\\'.s:delimiter.'\)*@ skip=@[^\\'.s:delimiter.']\%(\\\\\)*\\'.s:delimiter.'@ end=@'.s:delimiter.'@ contains=sedTab,sedReplaceMeta keepend contained nextgroup=@sedFlags' | |
74 endif | |
75 let s:i = s:i + 1 | |
7 | 76 endwhile |
30875 | 77 syn region sedAddress matchgroup=Special start=+\\@\%(\\@\)\=+ skip=+[^\\]\%(\\\\\)*\\@+ end=+@I\=+ contains=sedTab,sedRegexpMeta |
78 syn region sedRegexp64 matchgroup=Special start=+@\%(\\\\\|\\@\)*+ skip=+[^\\@]\%(\\\\\)*\\@+ end=+@+me=e-1 contains=sedTab,sedRegexpMeta keepend contained nextgroup=sedReplacement64 | |
79 syn region sedReplacement64 matchgroup=Special start=+@\%(\\\\\|\\@\)*+ skip=+[^\\@]\%(\\\\\)*\\@+ end=+@+ contains=sedTab,sedReplaceMeta keepend contained nextgroup=sedFlag | |
7 | 80 |
30875 | 81 " Since the syntax for the substitution command is very similar to the |
7 | 82 " syntax for the transform command, I use the same pattern matching |
83 " for both commands. There is one problem -- the transform command | |
84 " (y) does not allow any flags. To save memory, I ignore this problem. | |
85 syn match sedST "[sy]" nextgroup=sedRegexp\d\+ | |
86 | |
87 | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
88 hi def link sedAddress Macro |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
89 hi def link sedACI NONE |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
90 hi def link sedBranch Label |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
91 hi def link sedComment Comment |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
92 hi def link sedDelete Function |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
93 hi def link sedError Error |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
94 hi def link sedFlag Type |
30875 | 95 hi def link sedFlagWrite Constant |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
96 hi def link sedFunction Function |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
97 hi def link sedLabel Label |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
98 hi def link sedLineCont Special |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
99 hi def link sedPutHoldspc Function |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
100 hi def link sedReplaceMeta Special |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
101 hi def link sedRegexpMeta Special |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
102 hi def link sedRW Constant |
30875 | 103 hi def link sedSemicolon Special |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
104 hi def link sedST Function |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
105 hi def link sedSpecial Special |
30875 | 106 hi def link sedTodo Todo |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
107 hi def link sedWhitespace NONE |
30875 | 108 if s:highlight_tabs |
109 hi def link sedTab Todo | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
2231
diff
changeset
|
110 endif |
30875 | 111 let s:i = char2nr(" ") " ASCII: 32, EBCDIC: 64 |
112 while s:i <= s:last | |
113 exe "hi def link sedRegexp".s:i "Macro" | |
114 exe "hi def link sedReplacement".s:i "NONE" | |
115 let s:i = s:i + 1 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
2231
diff
changeset
|
116 endwhile |
7 | 117 |
30875 | 118 unlet s:i s:last s:delimiter s:metacharacters s:at |
119 unlet s:highlight_tabs | |
7 | 120 |
121 let b:current_syntax = "sed" | |
122 | |
30875 | 123 " vim: nowrap sw=2 sts=2 ts=8 noet: |