robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2c76a50e20
master
1" Vim syntax file 2" Language: PKL 3" Maintainer: Jan Claußen <jan DOT claussen10 AT web DOT de> 4" Last Change: 2025 Sep 24 5 6if exists ( "b:current_syntax" ) 7finish 8endif 9 10" We use line-continuation here 11let s: cpo_save = & cpo 12set cpo & vim 13 14" Needed to properly highlight multiline strings 15syn sync fromstart 16 17" PKL supports non-Unicode identifiers. So we modify the keyword character 18" class to include them 19syn iskeyword @,48-57,192-255,$,_ 20 21" Declare a variable for identifiers 22let s: id = '\%(\K\+\d*[_$]*\K*\d*[_$]*\)' 23 24" --- Decorator --- 25exe $ 'syn match pklDecorator "@{s: id }\{{1,}}"' 26 27" --- Comments --- 28syn match pklComment "\/\{2}. * " 29syn match pklDocComment "\/\{3}. * " 30syn region pklMultiComment start = "\/\* "end = "\*\/ "keepend fold 31 32" --- Strings --- 33syn region pklString start = +" +end = +" +contains = pklEscape , pklUnicodeEscape , pklStringInterpolation oneline 34syn region pklMultiString start = +""" +skip = +\\." +end = +""" +contains = pklEscape , pklUnicodeEscape keepend fold 35syn match pklEscape "\\ [ \\nt0rbaeuf"' ] "contained containedin = pklString , pklMultiString 36syn match pklUnicode "[ 0-9A-Fa-f ] \+ "contained 37 38" --- String interpolation --- 39" Standard interpolation 40syn region pklStringInterpolation matchgroup = pklDelimiter 41 \start = +\\( +end = +) +contains = pklNumbers , pklOperator , pklIdentifier , pklFunction , pklParen , pklString 42 \contained containedin = pklString , pklMultiString oneline 43" Unicode escape sequences 44syn region pklUnicodeEscape matchgroup = pklDelimiter 45 \start = +\\u{ +end = +} +contains = pklUnicode 46 \contained containedin = pklString , pklMultiString 47 48" --- Basic data types --- 49syn keyword pklType 50 \UInt UInt8 UInt16 UInt32 UInt64 UInt128 51 \Int Int8 Int16 Int32 Int64 Int128 52 \Float 53 \Number 54 \String 55 \Boolean 56 \Null 57 \Any 58 59syn keyword pklCollections 60 \Map Mapping 61 \List Listing 62 \Set 63 64" --- Custom string delimiters --- 65function ! s: DefineCustomStringDelimiters ( n ) 66for x in range ( 1 , a: n ) 67exe $ 'syn region pklString{x}Pound start=+{repeat("#", x)}"+ end=+"{repeat("#", x)}+ contains=pklStringInterpolation{x}Pound,pklEscape{x}Pound oneline' 68exe $ 'hi def link pklString{x}Pound String' 69 70exe $ 'syn region pklMultiString{x}Pound start=+{repeat("#", x)}"""+ end=+"""{repeat("#", x)}+ contains=pklStringInterpolation{x}Pound,pklEscape{x}Pound keepend fold' 71exe $ 'hi def link pklMultiString{x}Pound String' 72 73exe $ 'syn match pklEscape{x}Pound "\\{repeat("#", x) }[\\nt0rbaeuf"'']" contained containedin=pklString{x}Pound,pklMultiString{x}Pound' 74exe $ 'hi def link pklEscape{x}Pound SpecialChar' 75 76exe $ 'syn region pklStringInterpolation{x}Pound matchgroup=pklDelimiter start=+\\{repeat("#", x)}(+ end=+)+ contains=pklNumbers,pklOperator,pklIdentifier,pklFunction,pklParen,pklString contained containedin=pklString{x}Pound,pklMultiString{x}Pound oneline' 77 78exe $ 'syn region pklUnicodeEscape{x}Pound matchgroup=pklDelimiter start=+\\{repeat("#", x)}u{{+ end=+}}+ contains=pklUnicode contained containedin=pklString{x}Pound,pklMultiString{x}Pound' 79exe $ 'hi def link pklUnicodeEscape{x}Pound SpecialChar' 80endfor 81endfunction 82 83call s: DefineCustomStringDelimiters ( 5 ) 84 85" --- Keywords --- 86syn keyword pklBoolean false true 87syn keyword pklClass outer super this module new 88syn keyword pklConditional if else when 89syn keyword pklConstant null NaN Infinity 90syn keyword pklException throw 91syn keyword pklInclude amends import extends as 92syn keyword pklKeyword function let out is 93syn keyword pklModifier abstract const external fixed hidden local open 94syn keyword pklReserved case delete override protected record switch vararg 95syn keyword pklRepeat for in 96syn keyword pklSpecial nothing unknown 97syn keyword pklStatement trace read 98syn keyword pklStruct typealias class 99 100" Include all unicode letters 101exe $ 'syn match pklIdentifier "{s: id }"' 102 103" Explicitely make keywords identifiers with backticks 104syn region pklIdentifierExplicit start = +` +end = +` + 105 106syn match pklOperator ",\||\|+\|*\|->\|?\|-\|==\|=\|!=\|! "contained containedin = pklType 107 108" --- Numbers --- 109" decimal numbers 110syn match pklNumbers display transparent "\<\d\|\.\d "contains = pklNumber , pklFloat , pklOctal 111syn match pklNumber display contained "\d\%(\d\+\) * \> " 112" hex numbers 113syn match pklNumber display contained "0x\x\%('\=\x\+\)\> " 114" binary numbers 115syn match pklNumber display contained "0b [ 01 ] \%('\= [ 01 ] \+\)\> " 116" octal numbers 117syn match pklOctal display contained "0o\o\+\> " 118 119"floating point number, with dot, optional exponent 120syn match pklFloat display contained "\d\+\.\d\+\%(e [ -+ ] \=\d\+\)\= " 121"floating point number, starting with a dot, optional exponent 122syn match pklFloat display contained "\.\d\+\%(e [ -+ ] \=\d\+\)\=\> " 123"floating point number, without dot, with exponent 124syn match pklFloat display contained "\d\+e [ -+ ] \=\d\+\> " 125 126" --- Brackets, operators, functions --- 127syn region pklParen matchgroup = pklBrackets start = '( 'end = ') 'contains = ALLBUT , pklUnicode transparent 128syn region pklBracket matchgroup = pklBrackets start = '\[\|<::\@! 'end = ']\|:> 'contains = ALLBUT , pklUnicode transparent 129syn region pklBlock matchgroup = pklBrackets start = "{ "end = "} "contains = ALLBUT , pklUnicode fold transparent 130 131exe $ 'syn match pklFunction "\<\h{s: id }*\>\ze\_s*[?|\*]\?(" contains=pklType' 132 133" --- Highlight links --- 134hi def link pklBoolean Boolean 135hi def link pklBrackets Delimiter 136hi def link pklClass Statement 137hi def link pklCollections Type 138hi def link pklComment Comment 139hi def link pklConditional Conditional 140hi def link pklConstant Constant 141hi def link pklDecorator Special 142hi def link pklDelimiter Delimiter 143hi def link pklDocComment Comment 144hi def link pklEscape SpecialChar 145hi def link pklException Exception 146hi def link pklFloat Number 147hi def link pklFunction Function 148hi def link pklInclude Include 149hi def link pklKeyword Keyword 150hi def link pklModifier StorageClass 151hi def link pklMultiComment Comment 152hi def link pklMultiString String 153hi def link pklNumber Number 154hi def link pklNumbers Number 155hi def link pklOctal Number 156hi def link pklRepeat Repeat 157hi def link pklReserved Error 158hi def link pklShebang Comment 159hi def link pklSpecial Special 160hi def link pklStatement Statement 161hi def link pklString String 162hi def link pklStruct Structure 163hi def link pklType Type 164hi def link pklUnicodeEscape SpecialChar 165 166let b: current_syntax = "pkl" 167 168let & cpo = s: cpo_save 169unlet s: cpo_save