1" Vim syntax file
2" Language:	Yacc
3" Maintainer:	Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
4" Last Change:	Aug 2, 2010
5" Version:	8
6" URL:	http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
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 version < 600
14 finish
15endif
16if exists("b:current_syntax")
17 syntax clear
18endif
19
20" ---------------------------------------------------------------------
21"  Folding Support {{{1
22if has("folding")
23 com! -nargs=+ HiFold	<args> fold
24else
25 com! -nargs=+ HiFold	<args>
26endif
27
28" ---------------------------------------------------------------------
29" Read the C syntax to start with {{{1
30if exists("g:yacc_uses_cpp")
31 syn include @yaccCode	<sfile>:p:h/cpp.vim
32else
33 syn include @yaccCode	<sfile>:p:h/c.vim
34endif
35
36" ---------------------------------------------------------------------
37"  Yacc Clusters: {{{1
38syn cluster yaccInitCluster	contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam
39syn cluster yaccRulesCluster	contains=yaccNonterminal,yaccString
40
41" ---------------------------------------------------------------------
42"  Yacc Sections: {{{1
43HiFold syn	region	yaccInit	start='.'ms=s-1,rs=s-1	matchgroup=yaccSectionSep	end='^%%$'me=e-2,re=e-2	contains=@yaccInitCluster	nextgroup=yaccRules	skipwhite skipempty contained
44HiFold syn	region	yaccInit2      start='\%^.'ms=s-1,rs=s-1	matchgroup=yaccSectionSep	end='^%%$'me=e-2,re=e-2	contains=@yaccInitCluster	nextgroup=yaccRules	skipwhite skipempty
45HiFold syn	region	yaccHeader2	matchgroup=yaccSep	start="^\s*\zs%{"	end="^\s*%}"		contains=@yaccCode	nextgroup=yaccInit	skipwhite skipempty contained
46HiFold syn	region	yaccHeader	matchgroup=yaccSep	start="^\s*\zs%{"	end="^\s*%}"		contains=@yaccCode	nextgroup=yaccInit	skipwhite skipempty
47HiFold syn	region	yaccRules	matchgroup=yaccSectionSep	start='^%%$'		end='^%%$'me=e-2,re=e-2	contains=@yaccRulesCluster	nextgroup=yaccEndCode	skipwhite skipempty contained
48HiFold syn	region	yaccEndCode	matchgroup=yaccSectionSep	start='^%%$'		end='\%$'		contains=@yaccCode	contained
49
50" ---------------------------------------------------------------------
51" Yacc Commands: {{{1
52syn	match	yaccDefines	'^%define\s\+.*$'
53syn	match	yaccParseParam	'%parse-param\>'	skipwhite	nextgroup=yaccParseParamStr
54syn	region	yaccParseParamStr	contained matchgroup=Delimiter	start='{'	end='}'	contains=cStructure
55
56syn	match	yaccDelim	"[:|]"	contained
57syn	match	yaccOper	"@\d\+"	contained
58
59syn	match	yaccKey	"^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>"	contained
60syn	match	yaccKey	"\s%\(prec\|expect\)\>"	contained
61syn	match	yaccKey	"\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+"	contained
62syn	keyword	yaccKeyActn	yyerrok yyclearin	contained
63
64syn	match	yaccUnionStart	"^%union"	skipwhite skipnl nextgroup=yaccUnion	contained
65HiFold syn	region	yaccUnion	matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode	contained
66syn	match	yaccBrkt	"[<>]"	contained
67syn	match	yaccType	"<[a-zA-Z_][a-zA-Z0-9_]*>"	contains=yaccBrkt	contained
68
69HiFold 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
70syn	region	yaccComment	start="/\*"	end="\*/"
71syn	match	yaccString	"'[^']*'"	contained
72
73
74" ---------------------------------------------------------------------
75" I'd really like to highlight just the outer {}.  Any suggestions??? {{{1
76syn	match	yaccCurlyError	"[{}]"
77HiFold syn	region	yaccAction	matchgroup=yaccCurly start="{" end="}" contains=@yaccCode	contained
78
79" ---------------------------------------------------------------------
80" Yacc synchronization: {{{1
81syn sync fromstart
82
83" ---------------------------------------------------------------------
84" Define the default highlighting. {{{1
85if !exists("did_yacc_syn_inits")
86  command -nargs=+ HiLink hi def link <args>
87
88  " Internal yacc highlighting links {{{2
89  HiLink yaccBrkt	yaccStmt
90  HiLink yaccKey	yaccStmt
91  HiLink yaccOper	yaccStmt
92  HiLink yaccUnionStart	yaccKey
93
94  " External yacc highlighting links {{{2
95  HiLink yaccComment	Comment
96  HiLink yaccCurly	Delimiter
97  HiLink yaccCurlyError	Error
98  HiLink yaccDefines	cDefine
99  HiLink yaccParseParam	cDefine
100  HiLink yaccNonterminal	Function
101  HiLink yaccDelim	Delimiter
102  HiLink yaccKeyActn	Special
103  HiLink yaccSectionSep	Todo
104  HiLink yaccSep	Delimiter
105  HiLink yaccString	String
106  HiLink yaccStmt	Statement
107  HiLink yaccType	Type
108
109  " since Bram doesn't like my Delimiter :| {{{2
110  HiLink Delimiter	Type
111
112  delcommand HiLink
113endif
114
115" ---------------------------------------------------------------------
116"  Cleanup: {{{1
117delcommand HiFold
118let b:current_syntax = "yacc"
119
120" ---------------------------------------------------------------------
121"  Modelines: {{{1
122" vim: ts=15 fdm=marker
123