robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:70d55cd: runtime(m4): Prevent the m4Disabled region from nesting within itself. (#41037)a8626466e8

master
4.4 KiB105 linesraw
1" Vim syntax file
2" Language:	M4
3" Maintainer:	Claudio Fleiner (claudio@fleiner.com)
4" Last Change:	2022 Jun 12
5" 2025 Sep 2 by Vim project: fix a few syntax issues #18192
6" 2025 Sep 5 by Vim project: introduce m4Disabled region #18200
7" 2025 Sep 6 by Vim project: remove m4Function heuristics #18211
8" 2025 Sep 6 by Vim project: remove m4Type and m4Function #18223
9" 2025 Sep 15 by Vim project: highlight m4Parameters #18306
10
11" quit when a syntax file was already loaded
12if !exists("main_syntax")
13  if exists("b:current_syntax")
14	finish
15  endif
16  " we define it here so that included files can test for it
17  let main_syntax='m4'
18endif
19
20" Reference: The Open Group Base Specifications, M4
21" https://pubs.opengroup.org/onlinepubs/9799919799/
22
23" Early definition of a cluster
24syn cluster m4Top contains=NONE
25
26" Quoting in M4:
27" – Quotes are nestable;
28" – The delimiters can be redefined with changequote(); here we only handle
29"   the default pair: ` ... ';
30" – Quoted text in M4 is rescanned, not treated as a literal string.
31"   Therefore the region is marked transparent so contained items retain
32"   their normal highlighting.
33syn region m4Quoted
34  \ matchgroup=m4QuoteDelim
35  \ start=+`+
36  \ end=+'+
37  \ contains=@m4Top
38  \ transparent
39syn cluster m4Top add=m4Quoted
40
41" Comments in M4:
42" – According to the Open Group Base Specification, comments start with
43"   a <number-sign> (#) and end at <newline>, unless redefined with changecom().
44"   We only handle the default here.
45" – Comments in M4 are not like in most languages: they do not remove the text,
46"   they simply prevent any macros from being expanded, while the text remains
47"   in the output. This region therefore disables any other matches.
48" – Comments themselves are disabled when quoted.
49syn region m4Disabled start=+#+ end=+$+ containedin=ALLBUT,m4Quoted,m4ParamCount,m4Disabled
50
51" Macros in M4:
52" – Name tokens consist of the longest possible sequence of letters, digits,
53"   and underscores, where the first character is not a digit.
54" – In GNU M4, this can be altered with changeword().
55" – Any name token may be defined as a macro and quoting prevents expansion.
56"   Thus correct highlighting requires running M4.
57
58" Parameters in M4:
59" $0 = macro name; $1..$9 = positional (single digit only); $# = count;
60" $* = args comma-joined; $@ = args quoted+comma; "${" = unspecified.
61syn match  m4ParamZero  contained "\$0"
62syn match  m4ParamPos   contained "\$[1-9]"
63syn match  m4ParamCount contained "\$#"
64syn match  m4ParamAll   contained "\$[@*]"
65syn match  m4ParamBad   contained '\${'
66syn cluster m4Top add=m4ParamZero,m4ParamPos,m4ParamCount,m4ParamAll,m4ParamBad
67
68" define the rest of M4 syntax
69syn match  m4Comment  "\<\(m4_\)\=dnl\>.*" contains=SpellErrors
70syn match  m4Constants "\<\(m4_\)\=__file__"
71syn match  m4Constants "\<\(m4_\)\=__line__"
72syn keyword m4Constants divnum sysval m4_divnum m4_sysval
73syn region m4Paren    matchgroup=m4Delimiter start="(" end=")" contained contains=@m4Top
74syn region m4Command  matchgroup=m4Define  start="\<\(m4_\)\=\(define\|defn\|pushdef\)(" end=")" contains=@m4Top
75syn region m4Command  matchgroup=m4Preproc   start="\<\(m4_\)\=\(include\|sinclude\)("he=e-1 end=")" contains=@m4Top
76syn region m4Command  matchgroup=m4Statement start="\<\(m4_\)\=\(syscmd\|esyscmd\|ifdef\|ifelse\|indir\|builtin\|shift\|errprint\|m4exit\|changecom\|changequote\|changeword\|m4wrap\|debugfile\|divert\|undivert\)("he=e-1 end=")" contains=@m4Top
77syn region m4Command  matchgroup=m4Builtin start="\<\(m4_\)\=\(len\|index\|regexp\|substr\|translit\|patsubst\|format\|incr\|decr\|eval\|maketemp\)("he=e-1 end=")" contains=@m4Top
78syn keyword m4Statement divert undivert
79syn region m4Command  matchgroup=m4Define      start="\<\(m4_\)\=\(undefine\|popdef\)("he=e-1 end=")" contains=@m4Top
80syn cluster m4Top     add=m4Comment,m4Constants,m4Paren,m4Command,m4Statement
81
82" Define the default highlighting.
83" Only when an item doesn't have highlighting yet
84hi def link m4QuoteDelim  Delimiter
85hi def link m4Delimiter   Delimiter
86hi def link m4Comment     Comment
87hi def link m4ParamZero   Macro
88hi def link m4ParamPos    Special
89hi def link m4ParamCount  Keyword
90hi def link m4ParamAll    Keyword
91hi def link m4ParamBad    Error
92hi def link m4Keyword     Keyword
93hi def link m4Define      Define
94hi def link m4Statement   Statement
95hi def link m4Preproc     PreProc
96hi def link m4Constants   Constant
97hi def link m4Builtin     Statement
98
99let b:current_syntax = "m4"
100
101if main_syntax == 'm4'
102  unlet main_syntax
103endif
104
105" vim: ts=4