blob: 1797b7a643cdfd55366655e1c952d30de81bf44d [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Yacc
Bram Moolenaar8c8de832008-06-24 22:58:06 +00003" Maintainer: Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
Bram Moolenaar5c736222010-01-06 20:54:52 +01004" Last Change: Oct 21, 2008
5" Version: 7
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00006" URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +00007"
Bram Moolenaar8c8de832008-06-24 22:58:06 +00008" Options: {{{1
Bram Moolenaardf1bdc92006-02-23 21:32:16 +00009" g:yacc_uses_cpp : if this variable exists, then C++ is loaded rather than C
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
Bram Moolenaar8c8de832008-06-24 22:58:06 +000011" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010012" this version of syntax/yacc.vim requires 6.0 or later
Bram Moolenaar071d4272004-06-13 20:20:40 +000013if version < 600
Bram Moolenaar5c736222010-01-06 20:54:52 +010014 finish
15endif
16if exists("b:current_syntax")
17 syntax clear
18endif
19
20" ---------------------------------------------------------------------
21" Folding Support {{{1
22if has("folding")
23 com! -nargs=+ HiFold <args> fold
24else
25 com! -nargs=+ HiFold <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000026endif
27
Bram Moolenaar8c8de832008-06-24 22:58:06 +000028" ---------------------------------------------------------------------
29" Read the C syntax to start with {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010030if exists("g:yacc_uses_cpp")
31 syn include @yaccCode <sfile>:p:h/cpp.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000032else
Bram Moolenaar5c736222010-01-06 20:54:52 +010033 syn include @yaccCode <sfile>:p:h/c.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000034endif
35
Bram Moolenaar8c8de832008-06-24 22:58:06 +000036" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010037" Yacc Clusters: {{{1
38syn cluster yaccInitCluster contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment
39syn cluster yaccRulesCluster contains=yaccNonterminal,yaccString
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
Bram Moolenaar8c8de832008-06-24 22:58:06 +000041" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010042" Yacc Sections: {{{1
43HiFold 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
44HiFold 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
45HiFold syn region yaccHeader2 matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty contained
46HiFold syn region yaccHeader matchgroup=yaccSep start="^\s*\zs%{" end="^\s*%}" contains=@yaccCode nextgroup=yaccInit skipwhite skipempty
47HiFold syn region yaccRules matchgroup=yaccSectionSep start='^%%$' end='^%%$'me=e-2,re=e-2 contains=@yaccRulesCluster nextgroup=yaccEndCode skipwhite skipempty contained
48HiFold syn region yaccEndCode matchgroup=yaccSectionSep start='^%%$' end='\%$' contains=@yaccCode contained
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
Bram Moolenaar8c8de832008-06-24 22:58:06 +000050" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010051" Yacc Commands: {{{1
52syn match yaccDelim "[:|]" contained
53syn match yaccOper "@\d\+" contained
54
55syn match yaccKey "^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>" contained
56syn match yaccKey "\s%\(prec\|expect\)\>" contained
57syn match yaccKey "\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+" contained
58syn keyword yaccKeyActn yyerrok yyclearin contained
59
60syn match yaccUnionStart "^%union" skipwhite skipnl nextgroup=yaccUnion contained
61HiFold syn region yaccUnion matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode contained
62syn match yaccBrkt "[<>]" contained
63syn match yaccType "<[a-zA-Z_][a-zA-Z0-9_]*>" contains=yaccBrkt contained
64
65HiFold 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
66syn region yaccComment start="/\*" end="\*/"
67syn match yaccString "'[^']*'" contained
68
Bram Moolenaar071d4272004-06-13 20:20:40 +000069
Bram Moolenaar8c8de832008-06-24 22:58:06 +000070" ---------------------------------------------------------------------
71" I'd really like to highlight just the outer {}. Any suggestions??? {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010072syn match yaccCurlyError "[{}]"
73HiFold syn region yaccAction matchgroup=yaccCurly start="{" end="}" contains=@yaccCode contained
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar8c8de832008-06-24 22:58:06 +000075" ---------------------------------------------------------------------
76" Yacc synchronization: {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010077syn sync fromstart
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Bram Moolenaar8c8de832008-06-24 22:58:06 +000079" ---------------------------------------------------------------------
80" Define the default highlighting. {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010081if !exists("did_yacc_syn_inits")
82 command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
Bram Moolenaar8c8de832008-06-24 22:58:06 +000084 " Internal yacc highlighting links {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +000085 HiLink yaccBrkt yaccStmt
86 HiLink yaccKey yaccStmt
87 HiLink yaccOper yaccStmt
88 HiLink yaccUnionStart yaccKey
89
Bram Moolenaar8c8de832008-06-24 22:58:06 +000090 " External yacc highlighting links {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010091 HiLink yaccComment Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 HiLink yaccCurly Delimiter
93 HiLink yaccCurlyError Error
Bram Moolenaar5c736222010-01-06 20:54:52 +010094 HiLink yaccNonterminal Function
95 HiLink yaccDelim Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +000096 HiLink yaccKeyActn Special
97 HiLink yaccSectionSep Todo
98 HiLink yaccSep Delimiter
Bram Moolenaar5c736222010-01-06 20:54:52 +010099 HiLink yaccString String
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100 HiLink yaccStmt Statement
101 HiLink yaccType Type
102
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000103 " since Bram doesn't like my Delimiter :| {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104 HiLink Delimiter Type
105
106 delcommand HiLink
107endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100108
109" ---------------------------------------------------------------------
110" Cleanup: {{{1
111delcommand HiFold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112let b:current_syntax = "yacc"
113
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000114" ---------------------------------------------------------------------
115" Modelines: {{{1
116" vim: ts=15 fdm=marker