1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-17 23:37:08 +01:00
vim/runtime/syntax/yacc.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
5.6 KiB
VimL
Raw Permalink Normal View History

2004-06-13 20:20:40 +00:00
" Vim syntax file
" Language: Yacc
" Former Maintainer: Charles E. Campbell
2019-04-04 13:11:03 +02:00
" Last Change: Mar 25, 2019
2020-01-25 13:27:42 +01:00
" Version: 17
" 2024 Feb 19 by Vim Project (announce adoption)
" Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_YACC
2004-06-13 20:20:40 +00:00
"
2008-06-24 22:58:06 +00:00
" Options: {{{1
2006-02-23 21:32:16 +00:00
" g:yacc_uses_cpp : if this variable exists, then C++ is loaded rather than C
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
2010-01-06 20:54:52 +01:00
" this version of syntax/yacc.vim requires 6.0 or later
if exists("b:current_syntax")
syntax clear
endif
" ---------------------------------------------------------------------
" Folding Support {{{1
if has("folding")
2012-11-15 21:28:22 +01:00
com! -nargs=+ SynFold <args> fold
2010-01-06 20:54:52 +01:00
else
2012-11-15 21:28:22 +01:00
com! -nargs=+ SynFold <args>
2004-06-13 20:20:40 +00:00
endif
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
" Read the C syntax to start with {{{1
2012-11-15 21:28:22 +01:00
" Read the C/C++ syntax to start with
let s:Cpath= fnameescape(expand("<sfile>:p:h").(exists("g:yacc_uses_cpp")? "/cpp.vim" : "/c.vim"))
if !filereadable(s:Cpath)
for s:Cpath in split(globpath(&rtp,(exists("g:yacc_uses_cpp")? "syntax/cpp.vim" : "syntax/c.vim")),"\n")
if filereadable(fnameescape(s:Cpath))
let s:Cpath= fnameescape(s:Cpath)
break
endif
endfor
2004-06-13 20:20:40 +00:00
endif
2012-11-15 21:28:22 +01:00
exe "syn include @yaccCode ".s:Cpath
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
2010-01-06 20:54:52 +01:00
" Yacc Clusters: {{{1
2010-12-10 20:35:50 +01:00
syn cluster yaccInitCluster contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam,yaccParseOption
2015-01-14 12:52:36 +01:00
syn cluster yaccRulesCluster contains=yaccNonterminal,yaccString,yaccComment
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
2010-01-06 20:54:52 +01:00
" Yacc Sections: {{{1
2019-04-04 13:11:03 +02:00
SynFold syn region yaccInit start='.'ms=s-1,rs=s-1 matchgroup=yaccSectionSep end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2 contains=@yaccInitCluster nextgroup=yaccRules skipwhite skipempty contained
SynFold syn region yaccInit2 start='\%^.'ms=s-1,rs=s-1 matchgroup=yaccSectionSep end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2 contains=@yaccInitCluster nextgroup=yaccRules skipwhite skipempty
SynFold syn region yaccHeader2 matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty contained
SynFold syn region yaccHeader matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty
SynFold syn region yaccRules matchgroup=yaccSectionSep start='^%%\ze\(\s*/[*/].*\)\=$' end='^%%\ze\(\s*/[*/].*\)\=$'me=e-2,re=e-2 contains=@yaccRulesCluster nextgroup=yaccEndCode skipwhite skipempty contained
SynFold syn region yaccEndCode matchgroup=yaccSectionSep start='^%%\ze\(\s*/[*/].*\)\=$' end='\%$' contains=@yaccCode contained
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
2010-01-06 20:54:52 +01:00
" Yacc Commands: {{{1
syn match yaccDefines '^%define\s\+.*$'
2010-12-10 20:35:50 +01:00
syn match yaccParseParam '%\(parse\|lex\)-param\>' skipwhite nextgroup=yaccParseParamStr
syn match yaccParseOption '%\%(api\.pure\|pure-parser\|locations\|error-verbose\)\>'
syn region yaccParseParamStr contained matchgroup=Delimiter start='{' end='}' contains=cStructure
2010-01-06 20:54:52 +01:00
syn match yaccDelim "[:|]" contained
syn match yaccOper "@\d\+" contained
syn match yaccKey "^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>" contained
syn match yaccKey "\s%\(prec\|expect\)\>" contained
syn match yaccKey "\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+" contained
syn keyword yaccKeyActn yyerrok yyclearin contained
syn match yaccUnionStart "^%union" skipwhite skipnl nextgroup=yaccUnion contained
2012-11-15 21:28:22 +01:00
SynFold syn region yaccUnion matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode contained
2010-01-06 20:54:52 +01:00
syn match yaccBrkt "[<>]" contained
syn match yaccType "<[a-zA-Z_][a-zA-Z0-9_]*>" contains=yaccBrkt contained
2012-11-15 21:28:22 +01:00
SynFold 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
2010-01-06 20:54:52 +01:00
syn region yaccComment start="/\*" end="\*/"
2019-04-04 13:11:03 +02:00
syn region yaccComment start="//" end="$"
2010-01-06 20:54:52 +01:00
syn match yaccString "'[^']*'" contained
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
" I'd really like to highlight just the outer {}. Any suggestions??? {{{1
2010-01-06 20:54:52 +01:00
syn match yaccCurlyError "[{}]"
2012-11-15 21:28:22 +01:00
SynFold syn region yaccAction matchgroup=yaccCurly start="{" end="}" contains=@yaccCode,yaccVar contained
syn match yaccVar '\$\d\+\|\$\$\|\$<\I\i*>\$\|\$<\I\i*>\d\+' containedin=cParen,cPreProc,cMulti contained
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
" Yacc synchronization: {{{1
2010-01-06 20:54:52 +01:00
syn sync fromstart
2004-06-13 20:20:40 +00:00
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
" Define the default highlighting. {{{1
if !exists("skip_yacc_syn_inits")
2012-11-15 21:28:22 +01:00
hi def link yaccBrkt yaccStmt
hi def link yaccComment Comment
hi def link yaccCurly Delimiter
hi def link yaccCurlyError Error
hi def link yaccDefines cDefine
hi def link yaccDelim Delimiter
hi def link yaccKeyActn Special
hi def link yaccKey yaccStmt
hi def link yaccNonterminal Function
hi def link yaccOper yaccStmt
hi def link yaccParseOption cDefine
hi def link yaccParseParam yaccParseOption
hi def link yaccSectionSep Todo
hi def link yaccSep Delimiter
hi def link yaccStmt Statement
hi def link yaccString String
hi def link yaccType Type
hi def link yaccUnionStart yaccKey
hi def link yaccVar Special
2004-06-13 20:20:40 +00:00
endif
2010-01-06 20:54:52 +01:00
" ---------------------------------------------------------------------
" Cleanup: {{{1
2012-11-15 21:28:22 +01:00
delcommand SynFold
2004-06-13 20:20:40 +00:00
let b:current_syntax = "yacc"
2008-06-24 22:58:06 +00:00
" ---------------------------------------------------------------------
" Modelines: {{{1
" vim: ts=15 fdm=marker