robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1" Vim syntax file 2" Language: Bazel rc file 3" Maintainer: Barrett Ruth <br@barrettruth.com> 4" Last Change: 2026 Aug 25 5" Reference: https://bazel.build/run/bazelrc 6 7" quit when a syntax file was already loaded 8if exists ( "b:current_syntax" ) 9finish 10endif 11let s: cpo_save = & cpo 12set cpo & vim 13 14syn case match 15syn iskeyword @,48-57,_,- 16 17" Comments {{{1 18 19" Backslash-newline is removed from the whole file before it is split into 20" lines, so a comment ending in one continues into the line below it. 21syn region bazelrcComment 22 \start = /# / 23 \skip = /\\$ / 24 \end = /$ / 25 \contains = bazelrcTodo , @Spell 26syn keyword bazelrcTodo contained TODO FIXME XXX NOTE 27 28" Words {{{1 29 30" Bazel joins a continued line onto the one above before splitting the file 31" into lines, so what follows is a further option rather than a new command. 32syn match bazelrcContinuation /\\$ / 33 \skipnl 34 \nextgroup = bazelrcContinued 35syn match bazelrcContinued contained transparent /. * / 36 \contains = bazelrcComment , bazelrcContinuation , bazelrcEscape , 37 \bazelrcFlag , bazelrcString 38 39" A backslash escape is absorbed before quoting is considered, so it applies 40" inside single quotes too, and '\#' is a literal '#' rather than a comment. 41syn match bazelrcEscape /\\. / 42" A quote may open part-way through a word. An unterminated one is ignored 43" rather than continued onto the line below. 44syn region bazelrcString oneline 45 \start = /' / 46 \skip = /\\. / 47 \end = /' / 48 \contains = bazelrcEscape 49syn region bazelrcString oneline 50 \start = /" / 51 \skip = /\\. / 52 \end = /" / 53 \contains = bazelrcEscape 54 55" Imports {{{1 56 57syn match bazelrcImport /^\s * try-import-if-bazel-version\> / 58 \skipwhite 59 \nextgroup = bazelrcVersion 60syn match bazelrcImport /^\s * \%(try-\)\=import\> / 61 \skipwhite 62 \nextgroup = bazelrcPath 63" The comparison and the version it applies to are a single word. 64syn match bazelrcVersion contained 65 \ /\%(<=\|>=\|==\|!=\| [ <>~ ] \) [ ^ \t# ] \+ / 66 \skipwhite 67 \nextgroup = bazelrcPath 68syn match bazelrcPath contained 69 \ /\%(\\.\| [ ^ \t# ] \)\+ / 70 \contains = bazelrcEscape , bazelrcString , bazelrcWorkspace 71" Substituted only as a prefix, and the trailing slash belongs to it. 72syn match bazelrcWorkspace contained /\%(^\|\s\)\@1<=%workspace%\/ / 73 74" Commands and options {{{1 75 76syn match bazelrcCommand 77 \ /^\s * \<\%(always\|aquery\|build\|canonicalize-flags\|clean\|common 78\\|config\|coverage\|cquery\|dump\|fetch\|help\|info\|license 79\\|mobile-install\|mod\|print_action\|query\|run\|shutdown\|startup 80\\|test\|vendor\|version\)\> / 81 \nextgroup = bazelrcConfig 82" A command is split on its first colon, so a config name may contain colons. 83syn match bazelrcConfig contained /: [ ^ \t# ] \+ / 84 85syn match bazelrcFlag /-- [ ^ \t#= ] * /nextgroup = bazelrcValue 86syn match bazelrcFlag /\%(^\|\s\)\@1<=- [ a-zA-Z ] \> / 87 \nextgroup = bazelrcValue 88syn region bazelrcValue contained oneline 89 \matchgroup = bazelrcOperator 90 \start = /= / 91 \end = /\ze [ \t# ] / 92 \end = /$ / 93 \contains = bazelrcString , bazelrcEscape 94 95" Syncing {{{1 96 97" A comment may continue onto the following line. 98syn sync linebreaks= 1 99 100" Default Highlighting {{{1 101 102hi def link bazelrcComment Comment 103hi def link bazelrcTodo Todo 104hi def link bazelrcContinuation Special 105hi def link bazelrcEscape SpecialChar 106hi def link bazelrcString String 107hi def link bazelrcImport Include 108hi def link bazelrcVersion Constant 109hi def link bazelrcPath String 110hi def link bazelrcWorkspace PreProc 111hi def link bazelrcCommand Statement 112hi def link bazelrcConfig Type 113hi def link bazelrcFlag Identifier 114hi def link bazelrcOperator Operator 115 116" }}} 117 118let b: current_syntax = "bazelrc" 119 120let & cpo = s: cpo_save 121unlet s: cpo_save 122 123" vim: ts=8 fdm=marker: