Skip to content

Commit 67a8f29

Browse files
jclsnchrisbra
authored andcommitted
patch 9.1.1821: filetype: Not all PKL files are recognized
Problem: filetype: Not all PKL files are recognized Solution: Detect *.pcf as pkl filetype, detect using the pkl-lsp:// protocol as pkl filetype, include PKL syntax script (Jan Claußen) This adds basic syntax support for the new PKL language by Apple. What works: - Shebang support - Comment support - Integers (decimal, hex, octal and binary) support - Floating point support including exponentials - Basic datatype support - Unicode escape delimiters - Escape code support - String interpolation - Support up to five pounds for custom delimiters - Folding of multi-line comments and blocks What doesn't work: The language heavily uses parameterized type declarations, which can get very complex. It is very hard to highlight this properly. There is official Tree-sitter support for this. Since it is hard to pull this off in a vim syntax file, I opted for basic support of the data types. References: https://github.com/apple/pkl-pantry fixes: #18271 closes: #18274 Signed-off-by: Jan Claußen <jan.claussen10@web.de> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent f77c187 commit 67a8f29

File tree

6 files changed

+179
-5
lines changed

6 files changed

+179
-5
lines changed

.github/MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ runtime/syntax/pbtxt.vim @lakshayg
585585
runtime/syntax/pdf.vim @tpope
586586
runtime/syntax/perl.vim @petdance
587587
runtime/syntax/php.vim @TysonAndre
588+
runtime/syntax/pkl.vim @jclsn
588589
runtime/syntax/plsql.vim @lee-lindley
589590
runtime/syntax/pod.vim @petdance
590591
runtime/syntax/poefilter.vim @ObserverOfTime

runtime/filetype.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2025 Sep 14
4+
" Last Change: 2025 Oct 03
55
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66

77
" Listen very carefully, I will say this only once
@@ -1971,7 +1971,7 @@ au BufNewFile,BufRead Pipfile.lock setf json
19711971
au BufNewFile,BufRead pixi.lock setf yaml
19721972

19731973
" Pkl
1974-
au BufNewFile,BufRead *.pkl setf pkl
1974+
au BufNewFile,BufRead *.pkl,*.pcf,pkl-lsp://* setf pkl
19751975

19761976
" PL/1, PL/I
19771977
au BufNewFile,BufRead *.pli,*.pl1 setf pli

runtime/ftplugin/pkl.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
" Language: Pkl
33
" Maintainer: Riley Bruins <ribru17@gmail.com>
44
" Last Change: 2025 Jul 14
5+
" 2025 Oct 03 by Vim Project Add foldmethod #18274
56

67
if exists('b:did_ftplugin')
78
finish
89
endif
910
let b:did_ftplugin = 1
1011

11-
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
12+
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
1213
setlocal commentstring=//\ %s
14+
setlocal foldmethod=syntax
1315

14-
let b:undo_ftplugin = 'setl com< cms<'
16+
let b:undo_ftplugin = 'setl com< cms< fdm<'

runtime/syntax/pkl.vim

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

src/testdir/test_filetype.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def s:GetFilenameChecks(): dict<list<string>>
615615
pilrc: ['file.rcp'],
616616
pine: ['.pinerc', 'pinerc', '.pinercex', 'pinercex'],
617617
pinfo: ['/etc/pinforc', '/.pinforc', 'any/.pinforc', 'any/etc/pinforc'],
618-
pkl: ['file.pkl'],
618+
pkl: ['file.pkl', 'file.pcf'],
619619
pli: ['file.pli', 'file.pl1'],
620620
plm: ['file.plm', 'file.p36', 'file.pac'],
621621
plp: ['file.plp'],

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1821,
732734
/**/
733735
1820,
734736
/**/

0 commit comments

Comments
 (0)