Mercurial > vim
comparison runtime/syntax/lex.vim @ 20241:56265f711890
Update runtime files
Commit: https://github.com/vim/vim/commit/7ceefb35c8110d87ced884275ddbe63d024a014f
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 1 16:07:38 2020 +0200
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 01 May 2020 16:15:05 +0200 |
parents | 8edf0aeb71b9 |
children | 29c5f168c6fd |
comparison
equal
deleted
inserted
replaced
20240:194676a30660 | 20241:56265f711890 |
---|---|
1 " Vim syntax file | 1 " Vim syntax file |
2 " Language: Lex | 2 " Language: Lex and Flex |
3 " Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> | 3 " Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
4 " Last Change: Aug 31, 2016 | 4 " Contributor: Robert A. van Engelen <engelen@acm.org> |
5 " Version: 17 | 5 " Last Change: Apr 24, 2020 |
6 " URL: http://mysite.verizon.net/astronaut/vim/index.html#SYNTAX_LEX | 6 " Version: 18 |
7 " | |
8 " Option: | |
9 " lex_uses_cpp : if this variable exists, then C++ is loaded rather than C | |
10 | 7 |
11 " quit when a syntax file was already loaded | 8 " quit when a syntax file was already loaded |
12 if exists("b:current_syntax") | 9 if exists("b:current_syntax") |
13 finish | 10 finish |
14 endif | 11 endif |
15 | 12 |
16 " Read the C/C++ syntax to start with | 13 " Read the C++ syntax to start with |
17 let s:Cpath= fnameescape(expand("<sfile>:p:h").(exists("g:lex_uses_cpp")? "/cpp.vim" : "/c.vim")) | 14 let s:Cpath= fnameescape(expand("<sfile>:p:h")."/cpp.vim") |
18 if !filereadable(s:Cpath) | 15 if !filereadable(s:Cpath) |
19 for s:Cpath in split(globpath(&rtp,(exists("g:lex_uses_cpp")? "syntax/cpp.vim" : "syntax/c.vim")),"\n") | 16 for s:Cpath in split(globpath(&rtp,"syntax/cpp.vim"),"\n") |
20 if filereadable(fnameescape(s:Cpath)) | 17 if filereadable(fnameescape(s:Cpath)) |
21 let s:Cpath= fnameescape(s:Cpath) | 18 let s:Cpath= fnameescape(s:Cpath) |
22 break | 19 break |
23 endif | 20 endif |
24 endfor | 21 endfor |
27 | 24 |
28 " --- ========= --- | 25 " --- ========= --- |
29 " --- Lex stuff --- | 26 " --- Lex stuff --- |
30 " --- ========= --- | 27 " --- ========= --- |
31 | 28 |
32 " Options Section | 29 " Definitions |
33 syn match lexOptions '^%\s*option\>.*$' contains=lexPatString | 30 " %% |
31 " Rules | |
32 " %% | |
33 " User Code | |
34 " | |
35 " --- ======= --- | |
36 " --- Example --- | |
37 " --- ======= --- | |
38 " | |
39 " // this is a valid lex file | |
40 " // indented initial code block | |
41 " #include <stdlib.h> | |
42 " %{ | |
43 " // initial code block | |
44 " #include <stdio.h> | |
45 " const char *sep = ""; | |
46 " %} | |
47 " %option outfile="scanner.c" noyywrap nodefault | |
48 " %x COMMENT | |
49 " id [A-Za-z_][A-Za-z0-9_]* | |
50 " %% | |
51 " // indented initial action code block | |
52 " printf("BEGIN"); | |
53 " {id} printf("%s%s", sep, yytext); sep = ""; | |
54 " . | | |
55 " \n { sep = "\n"; } | |
56 " "/*" { BEGIN COMMENT; } | |
57 " "//".* { } | |
58 " <COMMENT>{ | |
59 " "*/" { BEGIN INITIAL; } | |
60 " .|\n | |
61 " } | |
62 " <*><<EOF>> { // end of file | |
63 " printf("\nEND\n"); | |
64 " yyterminate(); | |
65 " } | |
66 " %% | |
67 " void scan() | |
68 " { | |
69 " while (yylex()) | |
70 " continue; | |
71 " } | |
72 " /* main program */ | |
73 " int main() | |
74 " { | |
75 " scan(); | |
76 " } | |
34 | 77 |
35 " Abbreviations Section | 78 " Definitions Section with initial code blocks, abbreviations, options, states |
36 if has("folding") | 79 if has("folding") |
37 syn region lexAbbrvBlock fold start="^\(\h\+\s\|%{\)" end="^\ze%%$" skipnl nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState | 80 syn region lexAbbrvBlock fold start="^\S" end="^\ze%%" skipnl nextgroup=lexPatBlock contains=lexOptions,lexAbbrv,lexInitialCodeBlock,lexInclude,lexAbbrvComment,lexStartState |
38 else | 81 else |
39 syn region lexAbbrvBlock start="^\(\h\+\s\|%{\)" end="^\ze%%$" skipnl nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState | 82 syn region lexAbbrvBlock start="^\S" end="^\ze%%" skipnl nextgroup=lexPatBlock contains=lexOptions,lexAbbrv,lexInitialCodeBlock,lexInclude,lexAbbrvComment,lexStartState |
40 endif | 83 endif |
41 syn match lexAbbrv "^\I\i*\s"me=e-1 skipwhite contained nextgroup=lexAbbrvRegExp | 84 syn match lexOptions "^%\a\+\(\s.*\|[^{]*\)$" contains=lexOptionsEq,lexPatString,lexSlashQuote,lexBrace,lexSlashBrace |
42 syn match lexAbbrv "^%[sx]" contained | 85 syn match lexOptionsEq "=" skipwhite contained |
43 syn match lexAbbrvRegExp "\s\S.*$"lc=1 contained nextgroup=lexAbbrv,lexInclude | 86 syn match lexAbbrv "^\I\i*\s"me=e-1 skipwhite contained nextgroup=lexAbbrvPat |
87 syn match lexAbbrvPat "\s\S.*$"lc=1 contained contains=lexPatAbbrv,lexPatString,lexSlashQuote,lexBrace,lexSlashBrace nextgroup=lexAbbrv,lexInclude | |
88 syn match lexStartState "^%\(xs\?\|s\)\(t\(a\(t\(e\?\)\?\)\?\)\?\)\?\(\s\+\I\i*\)\+\s*$" contained contains=lexStartStateCmd | |
89 syn match lexStartStateCmd '^%\(xs\?\|s\)\(t\(a\(t\(e\?\)\?\)\?\)\?\)\?' contained | |
44 if has("folding") | 90 if has("folding") |
45 syn region lexInclude fold matchgroup=lexSep start="^%{" end="%}" contained contains=@lexCcode | 91 syn region lexInitialCodeBlock fold start="^\s\+" end="^\S"me=e-1 contains=@lexCcode |
46 syn region lexAbbrvComment fold start="^\s\+/\*" end="\*/" contains=@Spell | 92 syn region lexInclude fold matchgroup=lexSep start="^%\a*{" end="^%\?}" contained contains=@lexCcode,lexCFunctions |
47 syn region lexAbbrvComment fold start="\%^/\*" end="\*/" contains=@Spell | 93 syn region lexAbbrvComment fold start="^\s*//" end="$" contains=@Spell |
48 syn region lexStartState fold matchgroup=lexAbbrv start="^%\a\+" end="$" contained | 94 syn region lexAbbrvComment fold start="^\s*/\*" end="\*/" contains=@Spell |
49 else | 95 else |
50 syn region lexInclude matchgroup=lexSep start="^%{" end="%}" contained contains=@lexCcode | 96 syn region lexInitialCodeBlock start="^\s\+" end="^\S"me=e-1 contains=@lexCcode |
51 syn region lexAbbrvComment start="^\s\+/\*" end="\*/" contains=@Spell | 97 syn region lexInclude matchgroup=lexSep start="^%\a*{" end="^%\?}" contained contains=@lexCcode,lexCFunctions |
52 syn region lexAbbrvComment start="\%^/\*" end="\*/" contains=@Spell | 98 syn region lexAbbrvComment start="^\s*//" end="$" contains=@Spell |
53 syn region lexStartState matchgroup=lexAbbrv start="^%\a\+" end="$" contained | 99 syn region lexAbbrvComment start="^\s*/\*" end="\*/" contains=@Spell |
54 endif | 100 endif |
55 | 101 |
56 "%% : Patterns {Actions} | 102 " Rules Section with patterns and actions |
57 if has("folding") | 103 if has("folding") |
58 syn region lexPatBlock fold matchgroup=Todo start="^%%$" matchgroup=Todo end="^%\ze%$" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatInclude | 104 syn region lexPatBlock fold matchgroup=Todo start="^%%" matchgroup=Todo end="^\ze%%" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
59 syn region lexPat fold start=+\S+ skip="\\\\\|\\." end="\s"me=e-1 skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPattern contains=lexPatTag,lexPatString,lexSlashQuote,lexBrace | 105 syn region lexPat fold start="\S" skip="\\\\\|\\\s" end="\ze\(\s*$\|\s\+\(\h\|{\W\|{$\|[-+*]\|//\|/\*\)\)" skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPatEnd contains=lexPatTag,lexPatString,lexSlashQuote,lexPatAbbrv,lexBrace,lexSlashBrace |
60 syn region lexPatInclude fold matchgroup=lexSep start="^%{" end="%}" contained contains=lexPatCode | 106 syn region lexPatInclude fold matchgroup=lexSep start="^%{" end="^%}" contained contains=@lexCcode |
61 syn region lexBrace fold start="\[" skip=+\\\\\|\\+ end="]" contained | 107 syn region lexBrace fold matchgroup=Character start="\[" skip="\\.\|\[:\a\+:\]\|\[\.\a\+\.\]\|\[=.=\]" end="\]" contained |
62 syn region lexPatString fold matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained | 108 syn region lexPatString fold matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained |
63 else | 109 else |
64 syn region lexPatBlock matchgroup=Todo start="^%%$" matchgroup=Todo end="^%%$" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatInclude | 110 syn region lexPatBlock matchgroup=Todo start="^%%" matchgroup=Todo end="^\ze%%" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
65 syn region lexPat start=+\S+ skip="\\\\\|\\." end="\s"me=e-1 skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPattern contains=lexPatTag,lexPatString,lexSlashQuote,lexBrace | 111 syn region lexPat start="\S" skip="\\\\\|\\\s" end="\ze\(\s*$\|\s\+\(\h\|{\W\|{$\|[-+*]\|//\|/\*\)\)" skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPatEnd contains=lexPatTag,lexPatString,lexSlashQuote,lexPatAbbrv,lexBrace,lexSlashBrace |
66 syn region lexPatInclude matchgroup=lexSep start="^%{" end="%}" contained contains=lexPatCode | 112 syn region lexPatInclude matchgroup=lexSep start="^%{" end="^%}" contained contains=@lexCcode |
67 syn region lexBrace start="\[" skip=+\\\\\|\\+ end="]" contained | 113 syn region lexBrace matchgroup=Character start="\[" skip="\\.\|\[:\a\+:\]\|\[\.\a\+\.\]\|\[=.=\]" end="\]" contained |
68 syn region lexPatString matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained | 114 syn region lexPatString matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained |
69 endif | 115 endif |
70 syn match lexPatTag "^<\I\i*\(,\I\i*\)*>" contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep | 116 syn match lexPatAbbrv "{\I\i*}"hs=s+1,he=e-1 contained |
71 syn match lexPatTagZone "^<\I\i*\(,\I\i*\)*>\s\+\ze{" contained nextgroup=lexPatTagZoneStart | 117 syn match lexPatTag "^<\^\?\(\I\i*\|\*\)\(,\^\?\(\I\i*\|\*\)\)*>" contained nextgroup=lexPat,lexMorePat,lexPatSep,lexPatEnd |
72 syn match lexPatTag +^<\I\i*\(,\I\i*\)*>*\(\\\\\)*\\"+ contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep | 118 syn match lexPatTagZone "^<\^\?\(\I\i*\|\*\)\(,\^\?\(\I\i*\|\*\)\)*>\s*{$"me=e-1 contained nextgroup=lexPatTagZoneStart |
73 | |
74 " Lex Patterns | |
75 syn region lexPattern start='[^ \t{}]' end="$" contained contains=lexPatRange | |
76 syn region lexPatRange matchgroup=Delimiter start='\[' skip='\\\\\|\\.' end='\]' contains=lexEscape | |
77 syn match lexEscape '\%(\\\\\)*\\.' contained | |
78 | 119 |
79 if has("folding") | 120 if has("folding") |
80 syn region lexPatTagZoneStart matchgroup=lexPatTag fold start='{' end='}' contained contains=lexPat,lexPatComment | 121 syn region lexPatTagZoneStart fold matchgroup=lexPatTag start='{$' end='^}' skipnl skipwhite contained contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
81 syn region lexPatComment start="\s\+/\*" end="\*/" fold skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | 122 syn region lexPatComment fold start="//" end="$" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell |
123 syn region lexPatComment fold start="/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | |
82 else | 124 else |
83 syn region lexPatTagZoneStart matchgroup=lexPatTag start='{' end='}' contained contains=lexPat,lexPatComment | 125 syn region lexPatTagZoneStart matchgroup=lexPatTag start='{' end='^}' skipnl skipwhitecontained contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatSep,lexPatInclude |
84 syn region lexPatComment start="\s\+/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | 126 syn region lexPatComment start="//" end="$" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell |
127 syn region lexPatComment start="/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell | |
85 endif | 128 endif |
86 syn match lexPatCodeLine "[^{\[].*" contained contains=@lexCcode | 129 syn match lexPatEnd "\s*$" skipnl contained |
87 syn match lexMorePat "\s*|\s*$" skipnl contained nextgroup=lexPat,lexPatTag,lexPatComment | 130 syn match lexPatCodeLine "[^{\[].*" contained contains=@lexCcode,lexCFunctions |
88 syn match lexPatSep "\s\+" contained nextgroup=lexMorePat,lexPatCode,lexPatCodeLine | 131 syn match lexMorePat "\s*|\s*$" skipnl contained nextgroup=lexPat,lexPatTag,lexPatComment |
132 syn match lexPatSep "\s\+" contained nextgroup=lexMorePat,lexPatCode,lexPatCodeLine | |
89 syn match lexSlashQuote +\(\\\\\)*\\"+ contained | 133 syn match lexSlashQuote +\(\\\\\)*\\"+ contained |
134 syn match lexSlashBrace +\(\\\\\)*\\\[+ contained | |
90 if has("folding") | 135 if has("folding") |
91 syn region lexPatCode matchgroup=Delimiter start="{" end="}" fold skipnl contained contains=@lexCcode,lexCFunctions | 136 syn region lexPatCode fold matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions |
92 else | 137 else |
93 syn region lexPatCode matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions | 138 syn region lexPatCode matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions |
94 endif | 139 endif |
95 | 140 |
96 " Lex "functions" which may appear in C/C++ code blocks | 141 " User Code Section with final code block |
97 syn keyword lexCFunctions BEGIN input unput woutput yyleng yylook yytext | 142 syn region lexFinalCodeBlock matchgroup=Todo start="^%%" end="\%$" contained contains=@lexCcode |
98 syn keyword lexCFunctions ECHO output winput wunput yyless yymore yywrap | |
99 | 143 |
100 " %% | 144 " Lex macros which may appear in C/C++ code blocks |
101 " lexAbbrevBlock | 145 syn keyword lexCFunctions BEGIN ECHO REJECT yytext YYText yyleng YYLeng yymore yyless yywrap yylook |
102 " %% | 146 syn keyword lexCFunctions yyrestart yyterminate yylineno yycolumno yyin yyout |
103 " lexPatBlock | 147 syn keyword lexCFunctions input unput output winput wunput woutput |
104 " %% | 148 syn keyword lexCFunctions yyinput yyunput yyoutput yywinput yywunput yywoutput |
105 " lexFinalCodeBlock | |
106 syn region lexFinalCodeBlock matchgroup=Todo start="%$"me=e-1 end="\%$" contained contains=@lexCcode | |
107 | 149 |
108 " <c.vim> includes several ALLBUTs; these have to be treated so as to exclude lex* groups | 150 " <c.vim> includes several ALLBUTs; these have to be treated so as to exclude lex* groups |
109 syn cluster cParenGroup add=lex.* | 151 syn cluster cParenGroup add=lex.* |
110 syn cluster cDefineGroup add=lex.* | 152 syn cluster cDefineGroup add=lex.* |
111 syn cluster cPreProcGroup add=lex.* | 153 syn cluster cPreProcGroup add=lex.* |
112 syn cluster cMultiGroup add=lex.* | 154 syn cluster cMultiGroup add=lex.* |
113 | 155 |
114 " Synchronization | 156 " Synchronization |
115 syn sync clear | 157 syn sync clear |
116 syn sync minlines=500 | 158 syn sync minlines=500 |
117 syn sync match lexSyncPat grouphere lexPatBlock "^%[a-zA-Z]" | 159 syn sync match lexSyncPat grouphere lexPatBlock "^%[a-zA-Z]" |
118 syn sync match lexSyncPat groupthere lexPatBlock "^<$" | 160 syn sync match lexSyncPat groupthere lexPatBlock "^<$" |
119 syn sync match lexSyncPat groupthere lexPatBlock "^%%$" | 161 syn sync match lexSyncPat groupthere lexPatBlock "^%%" |
120 | 162 |
121 " The default highlighting. | 163 " The default highlighting. |
122 if !exists("skip_lex_syntax_inits") | 164 if !exists("skip_lex_syntax_inits") |
123 hi def link lexAbbrvComment lexPatComment | 165 hi def link lexAbbrvComment lexPatComment |
124 hi def link lexAbbrvRegExp Macro | 166 hi def link lexAbbrvPat lexPat |
125 hi def link lexAbbrv SpecialChar | 167 hi def link lexAbbrv Special |
126 hi def link lexBrace lexPat | 168 hi def link lexBrace lexPat |
127 hi def link lexCFunctions Function | 169 hi def link lexCFunctions PreProc |
128 hi def link lexCstruct cStructure | 170 hi def link lexMorePat Special |
129 hi def link lexMorePat SpecialChar | 171 hi def link lexOptions PreProc |
130 hi def link lexOptions PreProc | 172 hi def link lexOptionsEq Operator |
131 hi def link lexPatComment Comment | 173 hi def link lexPatComment Comment |
132 hi def link lexPat Function | 174 hi def link lexPat Function |
133 hi def link lexPatString Function | 175 hi def link lexPatString lexPat |
134 hi def link lexPatTag Special | 176 hi def link lexPatAbbrv Special |
177 hi def link lexPatTag Statement | |
135 hi def link lexPatTagZone lexPatTag | 178 hi def link lexPatTagZone lexPatTag |
136 hi def link lexSep Delimiter | 179 hi def link lexSep Delimiter |
137 hi def link lexSlashQuote lexPat | 180 hi def link lexSlashQuote lexPat |
138 hi def link lexStartState Statement | 181 hi def link lexSlashBrace lexPat |
182 hi def link lexStartState lexPatTag | |
183 hi def link lexStartStateCmd Special | |
139 endif | 184 endif |
140 | 185 |
141 let b:current_syntax = "lex" | 186 let b:current_syntax = "lex" |
142 | 187 |
143 " vim:ts=10 | 188 " vim:ts=8 |