xref: /vim-8.2.3635/runtime/syntax/yacc.vim (revision 1d9215b9)
1" Vim syntax file
2" Language:	Yacc
3" Maintainer:	Charles E. Campbell <[email protected]>
4" Last Change:	Mar 25, 2019
5" Version:	17
6" URL:	http://www.drchip.org/astronaut/vim/index.html#SYNTAX_YACC
7"
8" Options: {{{1
9"   g:yacc_uses_cpp : if this variable exists, then C++ is loaded rather than C
10
11" ---------------------------------------------------------------------
12" this version of syntax/yacc.vim requires 6.0 or later
13if exists("b:current_syntax")
14 syntax clear
15endif
16
17" ---------------------------------------------------------------------
18"  Folding Support {{{1
19if has("folding")
20 com! -nargs=+ SynFold	<args> fold
21else
22 com! -nargs=+ SynFold	<args>
23endif
24
25" ---------------------------------------------------------------------
26" Read the C syntax to start with {{{1
27" Read the C/C++ syntax to start with
28let s:Cpath= fnameescape(expand("<sfile>:p:h").(exists("g:yacc_uses_cpp")? "/cpp.vim" : "/c.vim"))
29if !filereadable(s:Cpath)
30 for s:Cpath in split(globpath(&rtp,(exists("g:yacc_uses_cpp")? "syntax/cpp.vim" : "syntax/c.vim")),"\n")
31  if filereadable(fnameescape(s:Cpath))
32   let s:Cpath= fnameescape(s:Cpath)
33   break
34  endif
35 endfor
36endif
37exe "syn include @yaccCode ".s:Cpath
38
39" ---------------------------------------------------------------------
40"  Yacc Clusters: {{{1
41syn cluster yaccInitCluster	contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam,yaccParseOption
42syn cluster yaccRulesCluster	contains=yaccNonterminal,yaccString,yaccComment
43
44" ---------------------------------------------------------------------
45"  Yacc Sections: {{{1
46SynFold syn	region	yaccInit	start='.'ms=s-1,rs=s-1	matchgroup=yaccSectionSep		end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2	contains=@yaccInitCluster	nextgroup=yaccRules	skipwhite skipempty contained
47SynFold syn	region	yaccInit2      start='\%^.'ms=s-1,rs=s-1	matchgroup=yaccSectionSep		end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2	contains=@yaccInitCluster	nextgroup=yaccRules	skipwhite skipempty
48SynFold syn	region	yaccHeader2	matchgroup=yaccSep	start="^\s*\zs%{"		end="^\s*%}"			contains=@yaccCode	nextgroup=yaccInit	skipwhite skipempty contained
49SynFold syn	region	yaccHeader	matchgroup=yaccSep	start="^\s*\zs%{"		end="^\s*%}"			contains=@yaccCode	nextgroup=yaccInit	skipwhite skipempty
50SynFold syn	region	yaccRules	matchgroup=yaccSectionSep	start='^%%\ze\(\s*/[*/].*\)\=$'	end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2	contains=@yaccRulesCluster	nextgroup=yaccEndCode	skipwhite skipempty contained
51SynFold syn	region	yaccEndCode	matchgroup=yaccSectionSep	start='^%%\ze\(\s*/[*/].*\)\=$'	end='\%$'			contains=@yaccCode	contained
52
53" ---------------------------------------------------------------------
54" Yacc Commands: {{{1
55syn	match	yaccDefines	'^%define\s\+.*$'
56syn	match	yaccParseParam	'%\(parse\|lex\)-param\>'		skipwhite	nextgroup=yaccParseParamStr
57syn	match	yaccParseOption '%\%(api\.pure\|pure-parser\|locations\|error-verbose\)\>'
58syn	region	yaccParseParamStr	contained matchgroup=Delimiter	start='{'	end='}'	contains=cStructure
59
60syn	match	yaccDelim	"[:|]"	contained
61syn	match	yaccOper	"@\d\+"	contained
62
63syn	match	yaccKey	"^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>"	contained
64syn	match	yaccKey	"\s%\(prec\|expect\)\>"	contained
65syn	match	yaccKey	"\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+"	contained
66syn	keyword	yaccKeyActn	yyerrok yyclearin	contained
67
68syn	match	yaccUnionStart	"^%union"	skipwhite skipnl nextgroup=yaccUnion	contained
69SynFold syn	region	yaccUnion	matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode	contained
70syn	match	yaccBrkt	"[<>]"	contained
71syn	match	yaccType	"<[a-zA-Z_][a-zA-Z0-9_]*>"	contains=yaccBrkt	contained
72
73SynFold syn	region	yaccNonterminal	start="^\s*\a\w*\ze\_s*\(/\*\_.\{-}\*/\)\=\_s*:"	matchgroup=yaccDelim end=";"	matchgroup=yaccSectionSep end='^%%$'me=e-2,re=e-2 contains=yaccAction,yaccDelim,yaccString,yaccComment	contained
74syn	region	yaccComment	start="/\*"	end="\*/"
75syn	region	yaccComment	start="//"	end="$"
76syn	match	yaccString	"'[^']*'"	contained
77
78
79" ---------------------------------------------------------------------
80" I'd really like to highlight just the outer {}.  Any suggestions??? {{{1
81syn	match	yaccCurlyError	"[{}]"
82SynFold syn	region	yaccAction	matchgroup=yaccCurly start="{" end="}" 	contains=@yaccCode,yaccVar		contained
83syn	match	yaccVar	'\$\d\+\|\$\$\|\$<\I\i*>\$\|\$<\I\i*>\d\+'	containedin=cParen,cPreProc,cMulti	contained
84
85" ---------------------------------------------------------------------
86" Yacc synchronization: {{{1
87syn sync fromstart
88
89" ---------------------------------------------------------------------
90" Define the default highlighting. {{{1
91if !exists("skip_yacc_syn_inits")
92  hi def link yaccBrkt	yaccStmt
93  hi def link yaccComment	Comment
94  hi def link yaccCurly	Delimiter
95  hi def link yaccCurlyError	Error
96  hi def link yaccDefines	cDefine
97  hi def link yaccDelim	Delimiter
98  hi def link yaccKeyActn	Special
99  hi def link yaccKey	yaccStmt
100  hi def link yaccNonterminal	Function
101  hi def link yaccOper	yaccStmt
102  hi def link yaccParseOption	cDefine
103  hi def link yaccParseParam	yaccParseOption
104  hi def link yaccSectionSep	Todo
105  hi def link yaccSep	Delimiter
106  hi def link yaccStmt	Statement
107  hi def link yaccString	String
108  hi def link yaccType	Type
109  hi def link yaccUnionStart	yaccKey
110  hi def link yaccVar	Special
111endif
112
113" ---------------------------------------------------------------------
114"  Cleanup: {{{1
115delcommand SynFold
116let b:current_syntax = "yacc"
117
118" ---------------------------------------------------------------------
119"  Modelines: {{{1
120" vim: ts=15 fdm=marker
121