xref: /vim-8.2.3635/runtime/syntax/yacc.vim (revision 00a927d6)
1" Vim syntax file
2" Language:	Yacc
3" Maintainer:	Charles E. Campbell, Jr. <[email protected]>
4" Last Change:	Oct 21, 2008
5" Version:	7
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
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	yaccDelim	"[:|]"	contained
53syn	match	yaccOper	"@\d\+"	contained
54
55syn	match	yaccKey	"^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>"	contained
56syn	match	yaccKey	"\s%\(prec\|expect\)\>"	contained
57syn	match	yaccKey	"\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+"	contained
58syn	keyword	yaccKeyActn	yyerrok yyclearin	contained
59
60syn	match	yaccUnionStart	"^%union"	skipwhite skipnl nextgroup=yaccUnion	contained
61HiFold syn	region	yaccUnion	matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode	contained
62syn	match	yaccBrkt	"[<>]"	contained
63syn	match	yaccType	"<[a-zA-Z_][a-zA-Z0-9_]*>"	contains=yaccBrkt	contained
64
65HiFold 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
66syn	region	yaccComment	start="/\*"	end="\*/"
67syn	match	yaccString	"'[^']*'"	contained
68
69
70" ---------------------------------------------------------------------
71" I'd really like to highlight just the outer {}.  Any suggestions??? {{{1
72syn	match	yaccCurlyError	"[{}]"
73HiFold syn	region	yaccAction	matchgroup=yaccCurly start="{" end="}" contains=@yaccCode	contained
74
75" ---------------------------------------------------------------------
76" Yacc synchronization: {{{1
77syn sync fromstart
78
79" ---------------------------------------------------------------------
80" Define the default highlighting. {{{1
81if !exists("did_yacc_syn_inits")
82  command -nargs=+ HiLink hi def link <args>
83
84  " Internal yacc highlighting links {{{2
85  HiLink yaccBrkt	yaccStmt
86  HiLink yaccKey	yaccStmt
87  HiLink yaccOper	yaccStmt
88  HiLink yaccUnionStart	yaccKey
89
90  " External yacc highlighting links {{{2
91  HiLink yaccComment	Comment
92  HiLink yaccCurly	Delimiter
93  HiLink yaccCurlyError	Error
94  HiLink yaccNonterminal	Function
95  HiLink yaccDelim	Delimiter
96  HiLink yaccKeyActn	Special
97  HiLink yaccSectionSep	Todo
98  HiLink yaccSep	Delimiter
99  HiLink yaccString	String
100  HiLink yaccStmt	Statement
101  HiLink yaccType	Type
102
103  " since Bram doesn't like my Delimiter :| {{{2
104  HiLink Delimiter	Type
105
106  delcommand HiLink
107endif
108
109" ---------------------------------------------------------------------
110"  Cleanup: {{{1
111delcommand HiFold
112let b:current_syntax = "yacc"
113
114" ---------------------------------------------------------------------
115"  Modelines: {{{1
116" vim: ts=15 fdm=marker
117