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