blob: 4e74eabd87e9b587c16337d19f1d5267462da04d [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Yacc
Bram Moolenaar8c8de832008-06-24 22:58:06 +00003" Maintainer: Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
Bram Moolenaar81af9252010-12-10 20:35:50 +01004" Last Change: Aug 12, 2010
5" Version: 9
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00006" URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +00007"
Bram Moolenaar8c8de832008-06-24 22:58:06 +00008" Options: {{{1
Bram Moolenaardf1bdc92006-02-23 21:32:16 +00009" g:yacc_uses_cpp : if this variable exists, then C++ is loaded rather than C
Bram Moolenaar81af9252010-12-10 20:35:50 +010010"
11" Overall layout of a bison/yacc grammer:
12" %{
13" Prolog
14" %}
15" Bison/Yacc Declarations
16" %%
17" Grammar Rules
18" %%
19" Epilogue
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
Bram Moolenaar8c8de832008-06-24 22:58:06 +000021" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010022" this version of syntax/yacc.vim requires 6.0 or later
Bram Moolenaar071d4272004-06-13 20:20:40 +000023if version < 600
Bram Moolenaar5c736222010-01-06 20:54:52 +010024 finish
25endif
26if exists("b:current_syntax")
27 syntax clear
28endif
29
30" ---------------------------------------------------------------------
31" Folding Support {{{1
32if has("folding")
33 com! -nargs=+ HiFold <args> fold
34else
35 com! -nargs=+ HiFold <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000036endif
37
Bram Moolenaar8c8de832008-06-24 22:58:06 +000038" ---------------------------------------------------------------------
39" Read the C syntax to start with {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010040if exists("g:yacc_uses_cpp")
41 syn include @yaccCode <sfile>:p:h/cpp.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000042else
Bram Moolenaar5c736222010-01-06 20:54:52 +010043 syn include @yaccCode <sfile>:p:h/c.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000044endif
45
Bram Moolenaar8c8de832008-06-24 22:58:06 +000046" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010047" Yacc Clusters: {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +010048syn cluster yaccInitCluster contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam,yaccParseOption
Bram Moolenaar5c736222010-01-06 20:54:52 +010049syn cluster yaccRulesCluster contains=yaccNonterminal,yaccString
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
Bram Moolenaar8c8de832008-06-24 22:58:06 +000051" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010052" Yacc Sections: {{{1
53HiFold 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
54HiFold 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
55HiFold syn region yaccHeader2 matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty contained
56HiFold syn region yaccHeader matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty
57HiFold syn region yaccRules matchgroup=yaccSectionSep start='^%%$' end='^%%$'me=e-2,re=e-2 contains=@yaccRulesCluster nextgroup=yaccEndCode skipwhite skipempty contained
58HiFold syn region yaccEndCode matchgroup=yaccSectionSep start='^%%$' end='\%$' contains=@yaccCode contained
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
Bram Moolenaar8c8de832008-06-24 22:58:06 +000060" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010061" Yacc Commands: {{{1
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020062syn match yaccDefines '^%define\s\+.*$'
Bram Moolenaar81af9252010-12-10 20:35:50 +010063syn match yaccParseParam '%\(parse\|lex\)-param\>' skipwhite nextgroup=yaccParseParamStr
64syn match yaccParseOption '%\%(api\.pure\|pure-parser\|locations\|error-verbose\)\>'
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020065syn region yaccParseParamStr contained matchgroup=Delimiter start='{' end='}' contains=cStructure
66
Bram Moolenaar5c736222010-01-06 20:54:52 +010067syn match yaccDelim "[:|]" contained
68syn match yaccOper "@\d\+" contained
69
70syn match yaccKey "^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>" contained
71syn match yaccKey "\s%\(prec\|expect\)\>" contained
72syn match yaccKey "\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+" contained
73syn keyword yaccKeyActn yyerrok yyclearin contained
74
75syn match yaccUnionStart "^%union" skipwhite skipnl nextgroup=yaccUnion contained
76HiFold syn region yaccUnion matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode contained
77syn match yaccBrkt "[<>]" contained
78syn match yaccType "<[a-zA-Z_][a-zA-Z0-9_]*>" contains=yaccBrkt contained
79
80HiFold 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
81syn region yaccComment start="/\*" end="\*/"
82syn match yaccString "'[^']*'" contained
83
Bram Moolenaar071d4272004-06-13 20:20:40 +000084
Bram Moolenaar8c8de832008-06-24 22:58:06 +000085" ---------------------------------------------------------------------
86" I'd really like to highlight just the outer {}. Any suggestions??? {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010087syn match yaccCurlyError "[{}]"
88HiFold syn region yaccAction matchgroup=yaccCurly start="{" end="}" contains=@yaccCode contained
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaar8c8de832008-06-24 22:58:06 +000090" ---------------------------------------------------------------------
91" Yacc synchronization: {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010092syn sync fromstart
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
Bram Moolenaar8c8de832008-06-24 22:58:06 +000094" ---------------------------------------------------------------------
95" Define the default highlighting. {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010096if !exists("did_yacc_syn_inits")
97 command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000098
Bram Moolenaar8c8de832008-06-24 22:58:06 +000099 " Internal yacc highlighting links {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100 HiLink yaccBrkt yaccStmt
101 HiLink yaccKey yaccStmt
102 HiLink yaccOper yaccStmt
103 HiLink yaccUnionStart yaccKey
104
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000105 " External yacc highlighting links {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100106 HiLink yaccComment Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107 HiLink yaccCurly Delimiter
108 HiLink yaccCurlyError Error
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200109 HiLink yaccDefines cDefine
Bram Moolenaar81af9252010-12-10 20:35:50 +0100110 HiLink yaccParseParam yaccParseOption
111 HiLink yaccParseOption cDefine
Bram Moolenaar5c736222010-01-06 20:54:52 +0100112 HiLink yaccNonterminal Function
113 HiLink yaccDelim Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114 HiLink yaccKeyActn Special
115 HiLink yaccSectionSep Todo
116 HiLink yaccSep Delimiter
Bram Moolenaar5c736222010-01-06 20:54:52 +0100117 HiLink yaccString String
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118 HiLink yaccStmt Statement
119 HiLink yaccType Type
120
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000121 " since Bram doesn't like my Delimiter :| {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122 HiLink Delimiter Type
123
124 delcommand HiLink
125endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100126
127" ---------------------------------------------------------------------
128" Cleanup: {{{1
129delcommand HiFold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130let b:current_syntax = "yacc"
131
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000132" ---------------------------------------------------------------------
133" Modelines: {{{1
134" vim: ts=15 fdm=marker