yacc.vim 5.4 KB

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