robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
9bb046d1be
master
1" Vim syntax file 2" Language: R (GNU S) 3" Maintainer: This runtime file is looking for a new maintainer. 4" Former Maintainers: Jakson Aquino <jalvesaq@gmail.com> 5" Vaidotas Zemlys <zemlys@gmail.com> 6" Tom Payne <tom@tompayne.org> 7" Contributor: Johannes Ranke <jranke@uni-bremen.de> 8" Former Repository: https://github.com/jalvesaq/R-Vim-runtime 9" Filenames: *.R *.r *.Rhistory *.Rt 10" Last Change: 2023 Dec 24 08:05AM 11" 2024 Feb 19 by Vim Project (announce adoption) 12" 13" NOTE: The highlighting of R functions might be defined in 14" runtime files created by a filetype plugin, if installed. 15" 16" CONFIGURATION: 17" Syntax folding can be turned on by 18" 19" let r_syntax_folding = 1 20" 21" ROxygen highlighting can be turned off by 22" 23" let r_syntax_hl_roxygen = 0 24" 25" Some lines of code were borrowed from Zhuojun Chen. 26 27if exists ( "b:current_syntax" ) 28finish 29endif 30 31syn iskeyword @,48-57,_,. 32 33" The variables g:r_hl_roxygen and g:r_syn_minlines were renamed on April 8, 2017. 34if exists ( "g:r_hl_roxygen" ) 35let g: r_syntax_hl_roxygen = g: r_hl_roxygen 36endif 37if exists ( "g:r_syn_minlines" ) 38let g: r_syntax_minlines = g: r_syn_minlines 39endif 40 41if exists ( "g:r_syntax_folding" ) && g: r_syntax_folding 42setlocal foldmethod = syntax 43endif 44 45let g: r_syntax_hl_roxygen = get ( g:, 'r_syntax_hl_roxygen' , 1 ) 46 47syn case match 48 49" Comment 50syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\): " 51syn match rTodoParen contained "\(BUG\|FIXME\|NOTE\|TODO\)\s * (.\{-})\s * : "contains = rTodoKeyw , rTodoInfo transparent 52syn keyword rTodoKeyw BUG FIXME NOTE TODO contained 53syn match rTodoInfo "(\zs.\{-}\ze) "contained 54syn match rComment contains = @Spell,rCommentTodo,rTodoParen "#. * " 55 56" Roxygen 57if g: r_syntax_hl_roxygen 58" A roxygen block can start at the beginning of a file (first version) and 59" after a blank line (second version). It ends when a line appears that does not 60" contain a roxygen comment. In the following comments, any line containing 61" a roxygen comment marker (one or two hash signs # followed by a single 62" quote ' and preceded only by whitespace) is called a roxygen line. A 63" roxygen line containing only a roxygen comment marker, optionally followed 64" by whitespace is called an empty roxygen line. 65 66syn match rOCommentKey "^\s * #\{1,2}' "contained 67syn region rOExamples start = "^\s * #\{1,2}' @examples. * "rs= e+1, hs= e+1end = "^\(#\{1,2}' @. * \)\@= "end = "^\(#\{1,2}'\)\@! "contained contains = rOTag fold 68 69" R6 classes may contain roxygen lines independent of roxygen blocks 70syn region rOR6Class start = /R6Class( /end = /) /transparent contains = ALLBUT , rError , rBraceError , rCurlyError fold 71syn match rOR6Block "#\{1,2}'. * "contains = rOTag , rOExamples , @Spell containedin = rOR6Class contained 72syn match rOR6Block "^\s * #\{1,2}'. * "contains = rOTag , rOExamples , @Spell containedin = rOR6Class contained 73 74" First we match all roxygen blocks as containing only a title. In case an 75" empty roxygen line ending the title or a tag is found, this will be 76" overridden later by the definitions of rOBlock. 77syn match rOTitleBlock "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{1,} "contains = rOCommentKey , rOTitleTag 78 79" A title as part of a block is always at the beginning of the block, i.e. 80" either at the start of a file or after a completely empty line. 81syn match rOTitle "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{-1,}\s * #\{1,2}'\s * $ "contained contains = rOCommentKey , rOTitleTag 82syn match rOTitleTag contained "@title " 83 84" When a roxygen block has a title and additional content, the title 85" consists of one or more roxygen lines (as little as possible are matched), 86" followed either by an empty roxygen line 87syn region rOBlock start = "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{-1,}\s * #\{1,2}'\s * $ "end = "^\s * \(#\{1,2}'\)\@! "contains = rOTitle , rOTag , rOExamples , @Spell keepend fold 88 89" or by a roxygen tag (we match everything starting with @ but not @@ which is used as escape sequence for a literal @). 90syn region rOBlock start = "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{-}\s * #\{1,2}' @\(@\)\@! "end = "^\s * \(#\{1,2}'\)\@! "contains = rOTitle , rOTag , rOExamples , @Spell keepend fold 91 92" If a block contains an @rdname, @describeIn tag, it may have paragraph breaks, but does not have a title 93syn region rOBlockNoTitle start = "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{-1,}\s * #\{1,2}'\s * \n\(\s * #\{1,2}'. * \n\)\{-}\s * #\{1,2}' @rdname "end = "^\s * \(#\{1,2}'\)\@! "contains = rOTag , rOExamples , @Spell keepend fold 94syn region rOBlockNoTitle start = "\(\%^\|^\s * \n\)\@<=\(\s * #\{1,2}' . * \n\)\{-1,}\s * #\{1,2}'\s * \n\(\s * #\{1,2}'. * \n\)\{-}\s * #\{1,2}' @describeIn "end = "^\s * \(#\{1,2}'\)\@! "contains = rOTag , rOExamples , @Spell keepend fold 95 96" rOTag list originally generated from the lists that were available in 97" https://github.com/klutometis/roxygen/R/rd.R and 98" https://github.com/klutometis/roxygen/R/namespace.R 99" using s/^ \([A-Za-z0-9]*\) = .*/ syn match rOTag contained "@\1"/ 100" Plus we need the @include tag 101 102" rd.R 103syn match rOTag contained "@aliases " 104syn match rOTag contained "@author " 105syn match rOTag contained "@backref " 106syn match rOTag contained "@concept " 107syn match rOTag contained "@describeIn " 108syn match rOTag contained "@description " 109syn match rOTag contained "@details " 110syn match rOTag contained "@docType " 111syn match rOTag contained "@encoding " 112syn match rOTag contained "@evalRd " 113syn match rOTag contained "@example " 114syn match rOTag contained "@examples " 115syn match rOTag contained "@family " 116syn match rOTag contained "@field " 117syn match rOTag contained "@format " 118syn match rOTag contained "@inherit " 119syn match rOTag contained "@inheritParams " 120syn match rOTag contained "@inheritDotParams " 121syn match rOTag contained "@inheritSection " 122syn match rOTag contained "@keywords " 123syn match rOTag contained "@method " 124syn match rOTag contained "@name " 125syn match rOTag contained "@md " 126syn match rOTag contained "@noMd " 127syn match rOTag contained "@noRd " 128syn match rOTag contained "@note " 129syn match rOTag contained "@param " 130syn match rOTag contained "@rdname " 131syn match rOTag contained "@rawRd " 132syn match rOTag contained "@references " 133syn match rOTag contained "@return " 134syn match rOTag contained "@section " 135syn match rOTag contained "@seealso " 136syn match rOTag contained "@slot " 137syn match rOTag contained "@source " 138syn match rOTag contained "@template " 139syn match rOTag contained "@templateVar " 140syn match rOTag contained "@title " 141syn match rOTag contained "@usage " 142" namespace.R 143syn match rOTag contained "@export " 144syn match rOTag contained "@exportClass " 145syn match rOTag contained "@exportMethod " 146syn match rOTag contained "@exportPattern " 147syn match rOTag contained "@import " 148syn match rOTag contained "@importClassesFrom " 149syn match rOTag contained "@importFrom " 150syn match rOTag contained "@importMethodsFrom " 151syn match rOTag contained "@rawNamespace " 152syn match rOTag contained "@S3method " 153syn match rOTag contained "@useDynLib " 154" other 155syn match rOTag contained "@eval " 156syn match rOTag contained "@include " 157syn match rOTag contained "@includeRmd " 158syn match rOTag contained "@order " 159endif 160 161 162if & filetype == "rhelp" 163" string enclosed in double quotes 164syn region rString contains = rSpecial , @Spell start = /" /skip = /\\\\\|\\" /end = /" / 165" string enclosed in single quotes 166syn region rString contains = rSpecial , @Spell start = /' /skip = /\\\\\|\\' /end = /' / 167else 168" string enclosed in double quotes 169syn region rString contains = rSpecial , rStrError , @Spell start = /" /skip = /\\\\\|\\" /end = /" / 170" string enclosed in single quotes 171syn region rString contains = rSpecial , rStrError , @Spell start = /' /skip = /\\\\\|\\' /end = /' / 172endif 173 174syn match rStrError display contained "\\. " 175 176 177" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash 178syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\ " 179 180" Hexadecimal and Octal digits 181syn match rSpecial display contained "\\\(x\x\{1,2}\| [ 0-8 ] \{1,3}\) " 182 183" Unicode characters 184syn match rSpecial display contained "\\u\x\{1,4} " 185syn match rSpecial display contained "\\U\x\{1,8} " 186syn match rSpecial display contained "\\u{\x\{1,4}} " 187syn match rSpecial display contained "\\U{\x\{1,8}} " 188 189" Raw string 190syn region rRawString matchgroup = rRawStrDelim start = /[ rR ] \z( [ '" ] \)\z(- * \)( /end = /)\z2\z1 /keepend 191syn region rRawString matchgroup = rRawStrDelim start = /[ rR ] \z( [ '" ] \)\z(- * \){ /end = /}\z2\z1 /keepend 192syn region rRawString matchgroup = rRawStrDelim start = /[ rR ] \z( [ '" ] \)\z(- * \)\[ /end = /\]\z2\z1 /keepend 193 194" Statement 195syn keyword rStatement break next return 196syn keyword rConditional if else 197syn keyword rRepeat for in repeat while 198 199" Constant (not really) 200syn keyword rConstant T F LETTERS letters month .abb month.name pi 201syn keyword rConstant R .version.string 202 203syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_ 204 205" Constants 206syn keyword rConstant NULL 207syn keyword rBoolean FALSE TRUE 208syn keyword rNumber NA Inf NaN 209 210" integer 211syn match rInteger "\<\d\+L " 212syn match rInteger "\<0x\( [ 0-9 ] \| [ a-f ] \| [ A-F ] \)\+L " 213syn match rInteger "\<\d\+ [ Ee ] +\=\d\+L " 214 215" number with no fractional part or exponent 216syn match rNumber "\<\d\+\> " 217" hexadecimal number 218syn match rNumber "\<0x\( [ 0-9 ] \| [ a-f ] \| [ A-F ] \)\+ " 219 220" floating point number with integer and fractional parts and optional exponent 221syn match rFloat "\<\d\+\.\d * \( [ Ee ][ -+ ] \=\d\+\)\= " 222" floating point number with no integer part and optional exponent 223syn match rFloat "\<\.\d\+\( [ Ee ][ -+ ] \=\d\+\)\= " 224" floating point number with no fractional part and optional exponent 225syn match rFloat "\<\d\+ [ Ee ][ -+ ] \=\d\+ " 226 227" complex number 228syn match rComplex "\<\d\+i " 229syn match rComplex "\<\d\++\d\+i " 230syn match rComplex "\<0x\( [ 0-9 ] \| [ a-f ] \| [ A-F ] \)\+i " 231syn match rComplex "\<\d\+\.\d * \( [ Ee ][ -+ ] \=\d\+\)\=i " 232syn match rComplex "\<\.\d\+\( [ Ee ][ -+ ] \=\d\+\)\=i " 233syn match rComplex "\<\d\+ [ Ee ][ -+ ] \=\d\+i " 234 235syn match rAssign '= ' 236syn match rOperator "& " 237syn match rOperator '- ' 238syn match rOperator '\* ' 239syn match rOperator '+ ' 240if & filetype == "quarto" || & filetype == "rmd" || & filetype == "rrst" 241syn match rOperator "[ |!<>^~`/: ] " 242else 243syn match rOperator "[ |!<>^~/: ] " 244endif 245syn match rOperator "%\{2}\|%\S\{-}% " 246syn match rOperator '\( [ !>< ] \)\@<== ' 247syn match rOperator '== ' 248syn match rOperator '|> ' 249syn match rOpError '\*\{3} ' 250syn match rOpError '// ' 251syn match rOpError '&&& ' 252syn match rOpError '||| ' 253syn match rOpError '<< ' 254syn match rOpError '>> ' 255 256syn match rAssign "<\{1,2}- " 257syn match rAssign "->\{1,2} " 258 259" Special 260syn match rDelimiter "[ ,;: ] " 261 262" Error 263if exists ( "g:r_syntax_folding" ) 264syn region rRegion matchgroup = Delimiter start = /( /matchgroup = Delimiter end = /) /transparent contains = ALLBUT , rError , rBraceError , rCurlyError fold 265syn region rRegion matchgroup = Delimiter start = /{ /matchgroup = Delimiter end = /} /transparent contains = ALLBUT , rError , rBraceError , rParenError fold 266syn region rRegion matchgroup = Delimiter start = /\[ /matchgroup = Delimiter end = /] /transparent contains = ALLBUT , rError , rCurlyError , rParenError fold 267syn region rSection matchgroup = Title start = /^#. * [ -=# ] \{4,} /end = /^#. * [ -=# ] \{4,} /ms= s-2, me= s-1transparent contains = ALL fold 268else 269syn region rRegion matchgroup = Delimiter start = /( /matchgroup = Delimiter end = /) /transparent contains = ALLBUT , rError , rBraceError , rCurlyError 270syn region rRegion matchgroup = Delimiter start = /{ /matchgroup = Delimiter end = /} /transparent contains = ALLBUT , rError , rBraceError , rParenError 271syn region rRegion matchgroup = Delimiter start = /\[ /matchgroup = Delimiter end = /] /transparent contains = ALLBUT , rError , rCurlyError , rParenError 272endif 273 274syn match rError "[ )\]} ] " 275syn match rBraceError "[ )} ] "contained 276syn match rCurlyError "[ )\] ] "contained 277syn match rParenError "[ \]} ] "contained 278 279" Use Nvim-R to highlight functions dynamically if it is installed 280if ! exists ( "g:r_syntax_fun_pattern" ) 281let s: ff = split ( substitute ( globpath ( & rtp , "R/functions.vim" ), "functions.vim" , "" , "g" ), "\n" ) 282if len ( s: ff ) > 0 283let g: r_syntax_fun_pattern = 0 284else 285let g: r_syntax_fun_pattern = 1 286endif 287endif 288 289" Only use Nvim-R to highlight functions if they should not be highlighted 290" according to a generic pattern 291if g: r_syntax_fun_pattern == 1 292syn match rFunction '[ 0-9a-zA-Z_\. ] \+\s * \ze( ' 293else 294" Nvim-R: 295runtime R/functions.vim 296endif 297 298syn match rDollar display contained "\$ " 299syn match rDollar display contained "@ " 300 301" List elements will not be highlighted as functions: 302syn match rLstElmt "\$ [ a-zA-Z0-9\\._ ] * "contains = rDollar 303syn match rLstElmt "@ [ a-zA-Z0-9\\._ ] * "contains = rDollar 304 305" Functions that may add new objects 306syn keyword rPreProc library require attach detach source 307 308if & filetype == "rhelp" 309syn match rHelpIdent '\\method ' 310syn match rHelpIdent '\\S4method ' 311endif 312 313" Type 314syn match rType "\\ " 315syn keyword rType array category character complex double function integer list logical matrix numeric vector data .frame 316 317" Name of object with spaces 318if & filetype == "rmd" || & filetype == "rrst" || & filetype == "quarto" 319syn region rNameWSpace start = "` "end = "` "contains = rSpaceFun containedin = rmdrChunk 320else 321syn region rNameWSpace start = "` "end = "` "contains = rSpaceFun 322endif 323 324if & filetype == "rhelp" 325syn match rhPreProc "^#ifdef. * " 326syn match rhPreProc "^#endif. * " 327syn match rhSection "\\dontrun\> " 328endif 329 330if exists ( "r_syntax_minlines" ) 331exe "syn sync minlines=" . r_syntax_minlines 332else 333syn sync minlines= 40 334endif 335 336" Define the default highlighting. 337hi def link rAssign Statement 338hi def link rBoolean Boolean 339hi def link rBraceError Error 340hi def link rComment Comment 341hi def link rTodoParen Comment 342hi def link rTodoInfo SpecialComment 343hi def link rCommentTodo Todo 344hi def link rTodoKeyw Todo 345hi def link rComplex Number 346hi def link rConditional Conditional 347hi def link rConstant Constant 348hi def link rCurlyError Error 349hi def link rDelimiter Delimiter 350hi def link rDollar SpecialChar 351hi def link rError Error 352hi def link rFloat Float 353hi def link rFunction Function 354hi def link rSpaceFun Function 355hi def link rHelpIdent Identifier 356hi def link rhPreProc PreProc 357hi def link rhSection PreCondit 358hi def link rInteger Number 359hi def link rLstElmt Normal 360hi def link rNameWSpace Normal 361hi def link rNumber Number 362hi def link rOperator Operator 363hi def link rOpError Error 364hi def link rParenError Error 365hi def link rPreProc PreProc 366hi def link rRawString String 367hi def link rRawStrDelim Delimiter 368hi def link rRepeat Repeat 369hi def link rSpecial SpecialChar 370hi def link rStatement Statement 371hi def link rString String 372hi def link rStrError Error 373hi def link rType Type 374if g: r_syntax_hl_roxygen 375hi def link rOTitleTag Operator 376hi def link rOTag Operator 377hi def link rOTitleBlock Title 378hi def link rOBlock Comment 379hi def link rOBlockNoTitle Comment 380hi def link rOR6Block Comment 381hi def link rOTitle Title 382hi def link rOCommentKey Comment 383hi def link rOExamples SpecialComment 384endif 385 386let b: current_syntax = "r" 387 388" vim: ts=8 sw=2