neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

yacc.vim (5674B)


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