blob: 4ddf078432ab29e1fdb23a3320eeb9649dc1eb38 [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 Moolenaar81af9252010-12-10 20:35:50 +01004" Last Change: Aug 12, 2010
5" Version: 9
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
Bram Moolenaar81af9252010-12-10 20:35:50 +010038syn cluster yaccInitCluster contains=yaccKey,yaccKeyActn,yaccBrkt,yaccType,yaccString,yaccUnionStart,yaccHeader2,yaccComment,yaccDefines,yaccParseParam,yaccParseOption
Bram Moolenaar5c736222010-01-06 20:54:52 +010039syn 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
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020052syn match yaccDefines '^%define\s\+.*$'
Bram Moolenaar81af9252010-12-10 20:35:50 +010053syn match yaccParseParam '%\(parse\|lex\)-param\>' skipwhite nextgroup=yaccParseParamStr
54syn match yaccParseOption '%\%(api\.pure\|pure-parser\|locations\|error-verbose\)\>'
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020055syn region yaccParseParamStr contained matchgroup=Delimiter start='{' end='}' contains=cStructure
56
Bram Moolenaar5c736222010-01-06 20:54:52 +010057syn match yaccDelim "[:|]" contained
58syn match yaccOper "@\d\+" contained
59
60syn match yaccKey "^\s*%\(token\|type\|left\|right\|start\|ident\|nonassoc\)\>" contained
61syn match yaccKey "\s%\(prec\|expect\)\>" contained
62syn match yaccKey "\$\(<[a-zA-Z_][a-zA-Z_0-9]*>\)\=[\$0-9]\+" contained
63syn keyword yaccKeyActn yyerrok yyclearin contained
64
65syn match yaccUnionStart "^%union" skipwhite skipnl nextgroup=yaccUnion contained
66HiFold syn region yaccUnion matchgroup=yaccCurly start="{" matchgroup=yaccCurly end="}" contains=@yaccCode contained
67syn match yaccBrkt "[<>]" contained
68syn match yaccType "<[a-zA-Z_][a-zA-Z0-9_]*>" contains=yaccBrkt contained
69
70HiFold 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
71syn region yaccComment start="/\*" end="\*/"
72syn match yaccString "'[^']*'" contained
73
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar8c8de832008-06-24 22:58:06 +000075" ---------------------------------------------------------------------
76" I'd really like to highlight just the outer {}. Any suggestions??? {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010077syn match yaccCurlyError "[{}]"
78HiFold syn region yaccAction matchgroup=yaccCurly start="{" end="}" contains=@yaccCode contained
Bram Moolenaar071d4272004-06-13 20:20:40 +000079
Bram Moolenaar8c8de832008-06-24 22:58:06 +000080" ---------------------------------------------------------------------
81" Yacc synchronization: {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010082syn sync fromstart
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
Bram Moolenaar8c8de832008-06-24 22:58:06 +000084" ---------------------------------------------------------------------
85" Define the default highlighting. {{{1
Bram Moolenaar5c736222010-01-06 20:54:52 +010086if !exists("did_yacc_syn_inits")
87 command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
Bram Moolenaar8c8de832008-06-24 22:58:06 +000089 " Internal yacc highlighting links {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +000090 HiLink yaccBrkt yaccStmt
91 HiLink yaccKey yaccStmt
92 HiLink yaccOper yaccStmt
93 HiLink yaccUnionStart yaccKey
94
Bram Moolenaar8c8de832008-06-24 22:58:06 +000095 " External yacc highlighting links {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010096 HiLink yaccComment Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +000097 HiLink yaccCurly Delimiter
98 HiLink yaccCurlyError Error
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020099 HiLink yaccDefines cDefine
Bram Moolenaar81af9252010-12-10 20:35:50 +0100100 HiLink yaccParseParam yaccParseOption
101 HiLink yaccParseOption cDefine
Bram Moolenaar5c736222010-01-06 20:54:52 +0100102 HiLink yaccNonterminal Function
103 HiLink yaccDelim Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104 HiLink yaccKeyActn Special
105 HiLink yaccSectionSep Todo
106 HiLink yaccSep Delimiter
Bram Moolenaar5c736222010-01-06 20:54:52 +0100107 HiLink yaccString String
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108 HiLink yaccStmt Statement
109 HiLink yaccType Type
110
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000111 " since Bram doesn't like my Delimiter :| {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112 HiLink Delimiter Type
113
114 delcommand HiLink
115endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100116
117" ---------------------------------------------------------------------
118" Cleanup: {{{1
119delcommand HiFold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120let b:current_syntax = "yacc"
121
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000122" ---------------------------------------------------------------------
123" Modelines: {{{1
124" vim: ts=15 fdm=marker