xref: /vim-8.2.3635/runtime/syntax/lex.vim (revision 17fb0e89)
1" Vim syntax file
2" Language:	Lex
3" Maintainer:	Charles E. Campbell, Jr. <[email protected]>
4" Last Change:	Nov 01, 2010
5" Version:	12
6" URL:	http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
7"
8" Option:
9"   lex_uses_cpp : if this variable exists, then C++ is loaded rather than C
10
11" For version 5.x: Clear all syntax items
12" For version 6.x: Quit when a syntax file was already loaded
13if version < 600
14  syntax clear
15elseif exists("b:current_syntax")
16  finish
17endif
18
19" Read the C/C++ syntax to start with
20if version >= 600
21  if exists("lex_uses_cpp")
22    runtime! syntax/cpp.vim
23  else
24    runtime! syntax/c.vim
25  endif
26  unlet b:current_syntax
27else
28  if exists("lex_uses_cpp")
29    so <sfile>:p:h/cpp.vim
30  else
31    so <sfile>:p:h/c.vim
32  endif
33endif
34
35" --- ========= ---
36" --- Lex stuff ---
37" --- ========= ---
38
39" Options Section
40syn match lexOptions '^%\s*option\>.*$' contains=lexPatString
41
42"I'd prefer to use lex.* , but vim doesn't handle forward definitions yet
43syn cluster lexListGroup		contains=lexAbbrvBlock,lexAbbrv,lexAbbrv,lexAbbrvRegExp,lexInclude,lexPatBlock,lexPat,lexBrace,lexPatString,lexPatTag,lexPatTag,lexPatComment,lexPatCodeLine,lexMorePat,lexPatSep,lexSlashQuote,lexPatCode,cInParen,cUserLabel,cOctalZero,cCppSkip,cErrInBracket,cErrInParen,cOctalError,cCppOut2,cCommentStartError,cParenError
44syn cluster lexListPatCodeGroup	contains=lexAbbrvBlock,lexAbbrv,lexAbbrv,lexAbbrvRegExp,lexInclude,lexPatBlock,lexPat,lexBrace,lexPatTag,lexPatTag,lexPatTagZoneStart,lexPatComment,lexPatCodeLine,lexMorePat,lexPatSep,lexSlashQuote,cInParen,cUserLabel,cOctalZero,cCppSkip,cErrInBracket,cErrInParen,cOctalError,cCppOut2,cCommentStartError,cParenError
45
46" Abbreviations Section
47if has("folding")
48 syn region lexAbbrvBlock	fold start="^\(\h\+\s\|%{\)"	end="^\ze%%$"	skipnl	nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState
49else
50 syn region lexAbbrvBlock	start="^\(\h\+\s\|%{\)"	end="^\ze%%$"	skipnl	nextgroup=lexPatBlock contains=lexAbbrv,lexInclude,lexAbbrvComment,lexStartState
51endif
52syn match  lexAbbrv		"^\I\i*\s"me=e-1			skipwhite	contained nextgroup=lexAbbrvRegExp
53syn match  lexAbbrv		"^%[sx]"					contained
54syn match  lexAbbrvRegExp	"\s\S.*$"lc=1				contained nextgroup=lexAbbrv,lexInclude
55if has("folding")
56 syn region lexInclude	fold matchgroup=lexSep	start="^%{"	end="%}"	contained	contains=ALLBUT,@lexListGroup
57 syn region lexAbbrvComment	fold			start="^\s\+/\*"	end="\*/"	contains=@Spell
58 syn region lexStartState	fold matchgroup=lexAbbrv	start="^%\a\+"	end="$"	contained
59else
60 syn region lexInclude	matchgroup=lexSep		start="^%{"	end="%}"	contained	contains=ALLBUT,@lexListGroup
61 syn region lexAbbrvComment				start="^\s\+/\*"	end="\*/"	contains=@Spell
62 syn region lexStartState	matchgroup=lexAbbrv		start="^%\a\+"	end="$"	contained
63endif
64
65"%% : Patterns {Actions}
66if has("folding")
67 syn region lexPatBlock	fold matchgroup=Todo	start="^%%$" matchgroup=Todo	end="^%%$"	skipnl	skipwhite	contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatInclude
68 syn region lexPat		fold			start=+\S+ skip="\\\\\|\\."	end="\s"me=e-1		contained nextgroup=lexMorePat,lexPatSep contains=lexPatTag,lexPatString,lexSlashQuote,lexBrace
69 syn region lexPatInclude	fold matchgroup=lexSep	start="^%{"	end="%}"	contained	contains=lexPatCode
70 syn region lexBrace	fold			start="\[" skip=+\\\\\|\\+	end="]"			contained
71 syn region lexPatString	fold matchgroup=String	start=+"+	skip=+\\\\\|\\"+	matchgroup=String end=+"+	contained
72else
73 syn region lexPatBlock	matchgroup=Todo		start="^%%$" matchgroup=Todo	end="^%%$"	skipnl	skipwhite	contains=lexPatTag,lexPatTagZone,lexPatComment,lexPat,lexPatInclude
74 syn region lexPat					start=+\S+ skip="\\\\\|\\."	end="\s"me=e-1		contained nextgroup=lexMorePat,lexPatSep contains=lexPatTag,lexPatString,lexSlashQuote,lexBrace
75 syn region lexPatInclude	matchgroup=lexSep		start="^%{"	end="%}"	contained	contains=lexPatCode
76 syn region lexBrace				start="\[" skip=+\\\\\|\\+	end="]"			contained
77 syn region lexPatString	matchgroup=String		start=+"+	skip=+\\\\\|\\"+	matchgroup=String end=+"+	contained
78endif
79syn match  lexPatTag	"^<\I\i*\(,\I\i*\)*>"			contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep
80syn match  lexPatTagZone	"^<\I\i*\(,\I\i*\)*>\s*\ze{"		contained nextgroup=lexPatTagZoneStart
81syn match  lexPatTag	+^<\I\i*\(,\I\i*\)*>*\(\\\\\)*\\"+		contained nextgroup=lexPat,lexPatTag,lexMorePat,lexPatSep
82if has("folding")
83 syn region  lexPatTagZoneStart matchgroup=lexPatTag	fold	start='{' end='}'	contained contains=lexPat,lexPatComment
84 syn region lexPatComment	start="\s\+/\*" end="\*/"	fold	skipnl	contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell
85else
86 syn region  lexPatTagZoneStart matchgroup=lexPatTag		start='{' end='}'	contained contains=lexPat,lexPatComment
87 syn region lexPatComment	start="\s\+/\*" end="\*/"		skipnl	contained contains=cTodo skipwhite nextgroup=lexPatComment,lexPat,@Spell
88endif
89syn match  lexPatCodeLine	".*$"					contained contains=ALLBUT,@lexListGroup
90syn match  lexMorePat	"\s*|\s*$"			skipnl	contained nextgroup=lexPat,lexPatTag,lexPatComment
91syn match  lexPatSep	"\s\+"					contained nextgroup=lexMorePat,lexPatCode,lexPatCodeLine
92syn match  lexSlashQuote	+\(\\\\\)*\\"+				contained
93if has("folding")
94 syn region lexPatCode matchgroup=Delimiter start="{" end="}"	fold	skipnl contained contains=ALLBUT,@lexListPatCodeGroup
95else
96 syn region lexPatCode matchgroup=Delimiter start="{" end="}"		skipnl contained contains=ALLBUT,@lexListPatCodeGroup
97endif
98
99syn keyword lexCFunctions	BEGIN	input	unput	woutput	yyleng	yylook	yytext
100syn keyword lexCFunctions	ECHO	output	winput	wunput	yyless	yymore	yywrap
101
102" <c.vim> includes several ALLBUTs; these have to be treated so as to exclude lex* groups
103syn cluster cParenGroup	add=lex.*
104syn cluster cDefineGroup	add=lex.*
105syn cluster cPreProcGroup	add=lex.*
106syn cluster cMultiGroup	add=lex.*
107
108" Synchronization
109syn sync clear
110syn sync minlines=300
111syn sync match lexSyncPat	grouphere  lexPatBlock	"^%[a-zA-Z]"
112syn sync match lexSyncPat	groupthere lexPatBlock	"^<$"
113syn sync match lexSyncPat	groupthere lexPatBlock	"^%%$"
114
115" The default highlighting.
116hi def link lexAbbrvComment	lexPatComment
117hi def link lexBrace	lexPat
118hi def link lexPatTagZone	lexPatTag
119hi def link lexSlashQuote	lexPat
120
121hi def link lexAbbrvRegExp	Macro
122hi def link lexAbbrv	SpecialChar
123hi def link lexCFunctions	Function
124hi def link lexMorePat	SpecialChar
125hi def link lexOptions	PreProc
126hi def link lexPatComment	Comment
127hi def link lexPat		Function
128hi def link lexPatString	Function
129hi def link lexPatTag	Special
130hi def link lexSep		Delimiter
131hi def link lexStartState	Statement
132
133let b:current_syntax = "lex"
134
135" vim:ts=10
136