Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Lex |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 3 | " Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 4 | " Last Change: Aug 31, 2016 |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 5 | " Version: 17 |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 6 | " URL: http://mysite.verizon.net/astronaut/vim/index.html#SYNTAX_LEX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | " |
| 8 | " Option: |
| 9 | " lex_uses_cpp : if this variable exists, then C++ is loaded rather than C |
| 10 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 11 | " quit when a syntax file was already loaded |
| 12 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 13 | finish |
| 14 | endif |
| 15 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 16 | " Read the C/C++ syntax to start with |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 17 | let s:Cpath= fnameescape(expand("<sfile>:p:h").(exists("g:lex_uses_cpp")? "/cpp.vim" : "/c.vim")) |
| 18 | if !filereadable(s:Cpath) |
| 19 | for s:Cpath in split(globpath(&rtp,(exists("g:lex_uses_cpp")? "syntax/cpp.vim" : "syntax/c.vim")),"\n") |
| 20 | if filereadable(fnameescape(s:Cpath)) |
| 21 | let s:Cpath= fnameescape(s:Cpath) |
| 22 | break |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | endif |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 24 | endfor |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 25 | endif |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 26 | exe "syn include @lexCcode ".s:Cpath |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 27 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 28 | " --- ========= --- |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 29 | " --- Lex stuff --- |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 30 | " --- ========= --- |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 31 | |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 32 | " Options Section |
| 33 | syn match lexOptions '^%\s*option\>.*$' contains=lexPatString |
| 34 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 35 | " Abbreviations Section |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 36 | if has("folding") |
| 37 | syn region lexAbbrvBlock fold start="^\(\h\+\s\|%{\)" end="^\ze%%$" skipnl nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState |
| 38 | else |
| 39 | syn region lexAbbrvBlock start="^\(\h\+\s\|%{\)" end="^\ze%%$" skipnl nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState |
| 40 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | syn match lexAbbrv "^\I\i*\s"me=e-1 skipwhite contained nextgroup=lexAbbrvRegExp |
| 42 | syn match lexAbbrv "^%[sx]" contained |
| 43 | syn match lexAbbrvRegExp "\s\S.*$"lc=1 contained nextgroup=lexAbbrv,lexInclude |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 44 | if has("folding") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 45 | syn region lexInclude fold matchgroup=lexSep start="^%{" end="%}" contained contains=@lexCcode |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 46 | syn region lexAbbrvComment fold start="^\s\+/\*" end="\*/" contains=@Spell |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 47 | syn region lexAbbrvComment fold start="\%^/\*" end="\*/" contains=@Spell |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 48 | syn region lexStartState fold matchgroup=lexAbbrv start="^%\a\+" end="$" contained |
| 49 | else |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 50 | syn region lexInclude matchgroup=lexSep start="^%{" end="%}" contained contains=@lexCcode |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 51 | syn region lexAbbrvComment start="^\s\+/\*" end="\*/" contains=@Spell |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 52 | syn region lexAbbrvComment start="\%^/\*" end="\*/" contains=@Spell |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 53 | syn region lexStartState matchgroup=lexAbbrv start="^%\a\+" end="$" contained |
| 54 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | |
| 56 | "%% : Patterns {Actions} |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 57 | if has("folding") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 58 | syn region lexPatBlock fold matchgroup=Todo start="^%%$" matchgroup=Todo end="^%\ze%$" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,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 |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 60 | syn region lexPatInclude fold matchgroup=lexSep start="^%{" end="%}" contained contains=lexPatCode |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 61 | syn region lexBrace fold start="\[" skip=+\\\\\|\\+ end="]" contained |
| 62 | syn region lexPatString fold matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained |
| 63 | else |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 64 | syn region lexPatBlock matchgroup=Todo start="^%%$" matchgroup=Todo end="^%%$" skipnl skipwhite nextgroup=lexFinalCodeBlock contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatInclude |
| 65 | syn region lexPat start=+\S+ skip="\\\\\|\\." end="\s"me=e-1 skipwhite contained nextgroup=lexMorePat,lexPatSep,lexPattern contains=lexPatTag,lexPatString,lexSlashQuote,lexBrace |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 66 | syn region lexPatInclude matchgroup=lexSep start="^%{" end="%}" contained contains=lexPatCode |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 67 | syn region lexBrace start="\[" skip=+\\\\\|\\+ end="]" contained |
| 68 | syn region lexPatString matchgroup=String start=+"+ skip=+\\\\\|\\"+ matchgroup=String end=+"+ contained |
| 69 | endif |
| 70 | syn match lexPatTag "^<\I\i*\(,\I\i*\)*>" contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 71 | syn match lexPatTagZone "^<\I\i*\(,\I\i*\)*>\s\+\ze{" contained nextgroup=lexPatTagZoneStart |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | syn match lexPatTag +^<\I\i*\(,\I\i*\)*>*\(\\\\\)*\\"+ contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 79 | if has("folding") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 80 | syn region lexPatTagZoneStart matchgroup=lexPatTag fold start='{' end='}' contained contains=lexPat,lexPatComment |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 81 | syn region lexPatComment start="\s\+/\*" end="\*/" fold skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell |
| 82 | else |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 83 | syn region lexPatTagZoneStart matchgroup=lexPatTag start='{' end='}' contained contains=lexPat,lexPatComment |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 84 | syn region lexPatComment start="\s\+/\*" end="\*/" skipnl contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell |
| 85 | endif |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 86 | syn match lexPatCodeLine "[^{\[].*" contained contains=@lexCcode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 87 | syn match lexMorePat "\s*|\s*$" skipnl contained nextgroup=lexPat,lexPatTag,lexPatComment |
| 88 | syn match lexPatSep "\s\+" contained nextgroup=lexMorePat,lexPatCode,lexPatCodeLine |
| 89 | syn match lexSlashQuote +\(\\\\\)*\\"+ contained |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 90 | if has("folding") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 91 | syn region lexPatCode matchgroup=Delimiter start="{" end="}" fold skipnl contained contains=@lexCcode,lexCFunctions |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 92 | else |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 93 | syn region lexPatCode matchgroup=Delimiter start="{" end="}" skipnl contained contains=@lexCcode,lexCFunctions |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 94 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 96 | " Lex "functions" which may appear in C/C++ code blocks |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 97 | syn keyword lexCFunctions BEGIN input unput woutput yyleng yylook yytext |
| 98 | syn keyword lexCFunctions ECHO output winput wunput yyless yymore yywrap |
| 99 | |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 100 | " %% |
| 101 | " lexAbbrevBlock |
| 102 | " %% |
| 103 | " lexPatBlock |
| 104 | " %% |
| 105 | " lexFinalCodeBlock |
| 106 | syn region lexFinalCodeBlock matchgroup=Todo start="%$"me=e-1 end="\%$" contained contains=@lexCcode |
| 107 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | " <c.vim> includes several ALLBUTs; these have to be treated so as to exclude lex* groups |
| 109 | syn cluster cParenGroup add=lex.* |
| 110 | syn cluster cDefineGroup add=lex.* |
| 111 | syn cluster cPreProcGroup add=lex.* |
| 112 | syn cluster cMultiGroup add=lex.* |
| 113 | |
| 114 | " Synchronization |
| 115 | syn sync clear |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 116 | syn sync minlines=500 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 117 | syn sync match lexSyncPat grouphere lexPatBlock "^%[a-zA-Z]" |
| 118 | syn sync match lexSyncPat groupthere lexPatBlock "^<$" |
| 119 | syn sync match lexSyncPat groupthere lexPatBlock "^%%$" |
| 120 | |
| 121 | " The default highlighting. |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 122 | if !exists("skip_lex_syntax_inits") |
| 123 | hi def link lexAbbrvComment lexPatComment |
| 124 | hi def link lexAbbrvRegExp Macro |
| 125 | hi def link lexAbbrv SpecialChar |
| 126 | hi def link lexBrace lexPat |
| 127 | hi def link lexCFunctions Function |
| 128 | hi def link lexCstruct cStructure |
| 129 | hi def link lexMorePat SpecialChar |
| 130 | hi def link lexOptions PreProc |
| 131 | hi def link lexPatComment Comment |
| 132 | hi def link lexPat Function |
| 133 | hi def link lexPatString Function |
| 134 | hi def link lexPatTag Special |
| 135 | hi def link lexPatTagZone lexPatTag |
| 136 | hi def link lexSep Delimiter |
| 137 | hi def link lexSlashQuote lexPat |
| 138 | hi def link lexStartState Statement |
| 139 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 140 | |
| 141 | let b:current_syntax = "lex" |
| 142 | |
| 143 | " vim:ts=10 |