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