1" Vim syntax file 2" Language: Yacc 3" Maintainer: Charles E. Campbell, Jr. <[email protected]> 4" Last Change: Aug 12, 2010 5" Version: 9 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" Overall layout of a bison/yacc grammer: 12" %{ 13" Prolog 14" %} 15" Bison/Yacc Declarations 16" %% 17" Grammar Rules 18" %% 19" Epilogue 20 21" --------------------------------------------------------------------- 22" this version of syntax/yacc.vim requires 6.0 or later 23if version < 600 24 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> 36endif 37 38" --------------------------------------------------------------------- 39" Read the C syntax to start with {{{1 40if exists("g:yacc_uses_cpp") 41 syn include @yaccCode <sfile>:p:h/cpp.vim 42else 43 syn include @yaccCode <sfile>:p:h/c.vim 44endif 45 46" --------------------------------------------------------------------- 47" Yacc Clusters: {{{1 48syn cluster yaccInitCluster contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam,yaccParseOption 49syn cluster yaccRulesCluster contains=yaccNonterminal,yaccString 50 51" --------------------------------------------------------------------- 52" 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 59 60" --------------------------------------------------------------------- 61" Yacc Commands: {{{1 62syn match yaccDefines '^%define\s\+.*$' 63syn match yaccParseParam '%\(parse\|lex\)-param\>' skipwhite nextgroup=yaccParseParamStr 64syn match yaccParseOption '%\%(api\.pure\|pure-parser\|locations\|error-verbose\)\>' 65syn region yaccParseParamStr contained matchgroup=Delimiter start='{' end='}' contains=cStructure 66 67syn 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 84 85" --------------------------------------------------------------------- 86" I'd really like to highlight just the outer {}. Any suggestions??? {{{1 87syn match yaccCurlyError "[{}]" 88HiFold syn region yaccAction matchgroup=yaccCurly start="{" end="}" contains=@yaccCode contained 89 90" --------------------------------------------------------------------- 91" Yacc synchronization: {{{1 92syn sync fromstart 93 94" --------------------------------------------------------------------- 95" Define the default highlighting. {{{1 96if !exists("did_yacc_syn_inits") 97 command -nargs=+ HiLink hi def link <args> 98 99 " Internal yacc highlighting links {{{2 100 HiLink yaccBrkt yaccStmt 101 HiLink yaccKey yaccStmt 102 HiLink yaccOper yaccStmt 103 HiLink yaccUnionStart yaccKey 104 105 " External yacc highlighting links {{{2 106 HiLink yaccComment Comment 107 HiLink yaccCurly Delimiter 108 HiLink yaccCurlyError Error 109 HiLink yaccDefines cDefine 110 HiLink yaccParseParam yaccParseOption 111 HiLink yaccParseOption cDefine 112 HiLink yaccNonterminal Function 113 HiLink yaccDelim Delimiter 114 HiLink yaccKeyActn Special 115 HiLink yaccSectionSep Todo 116 HiLink yaccSep Delimiter 117 HiLink yaccString String 118 HiLink yaccStmt Statement 119 HiLink yaccType Type 120 121 " since Bram doesn't like my Delimiter :| {{{2 122 HiLink Delimiter Type 123 124 delcommand HiLink 125endif 126 127" --------------------------------------------------------------------- 128" Cleanup: {{{1 129delcommand HiFold 130let b:current_syntax = "yacc" 131 132" --------------------------------------------------------------------- 133" Modelines: {{{1 134" vim: ts=15 fdm=marker 135