File: pkl.vim

package info (click to toggle)
vim 2%3A9.1.1882-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,504 kB
  • sloc: ansic: 432,444; cpp: 6,371; makefile: 4,596; sh: 2,387; java: 2,312; xml: 2,099; python: 1,559; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; sed: 8; csh: 6
file content (169 lines) | stat: -rw-r--r-- 7,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
" Vim syntax file
" Language:		PKL
" Maintainer:		Jan Claußen <jan DOT claussen10 AT web DOT de>
" Last Change:		2025 Sep 24

if exists("b:current_syntax")
  finish
endif

" We use line-continuation here
let s:cpo_save = &cpo
set cpo&vim

" Needed to properly highlight multiline strings
syn sync fromstart

" PKL supports non-Unicode identifiers. So we modify the keyword character
" class to include them
syn iskeyword @,48-57,192-255,$,_

" Declare a variable for identifiers
let s:id  = '\%(\K\+\d*[_$]*\K*\d*[_$]*\)'

" --- Decorator ---
exe $'syn match	pklDecorator     "@{s:id}\{{1,}}"'

" --- Comments ---
syn match	pklComment	"\/\{2}.*"
syn match	pklDocComment	"\/\{3}.*"
syn region	pklMultiComment	start="\/\*" end="\*\/" keepend fold

" --- Strings ---
syn region	pklString	start=+"+ end=+"+ contains=pklEscape,pklUnicodeEscape,pklStringInterpolation oneline
syn region	pklMultiString	start=+"""+ skip=+\\."+ end=+"""+ contains=pklEscape,pklUnicodeEscape keepend fold
syn match	pklEscape	"\\[\\nt0rbaeuf"']" contained containedin=pklString,pklMultiString
syn match	pklUnicode	"[0-9A-Fa-f]\+" contained

" --- String interpolation ---
" Standard interpolation
syn region	pklStringInterpolation matchgroup=pklDelimiter
	  \ start=+\\(+ end=+)+ contains=pklNumbers,pklOperator,pklIdentifier,pklFunction,pklParen,pklString
	  \ contained containedin=pklString,pklMultiString oneline
" Unicode escape sequences
syn region	pklUnicodeEscape matchgroup=pklDelimiter
	  \ start=+\\u{+ end=+}+ contains=pklUnicode
	  \ contained containedin=pklString,pklMultiString

" --- Basic data types ---
syn keyword	pklType
	  \ UInt UInt8 UInt16 UInt32 UInt64 UInt128
	  \ Int Int8 Int16 Int32 Int64 Int128
	  \ Float
	  \ Number
	  \ String
	  \ Boolean
	  \ Null
	  \ Any

syn keyword	pklCollections
	  \ Map Mapping
	  \ List Listing
	  \ Set

" --- Custom string delimiters ---
function! s:DefineCustomStringDelimiters(n)
  for x in range(1, a:n)
    exe $'syn region pklString{x}Pound start=+{repeat("#", x)}"+ end=+"{repeat("#", x)}+ contains=pklStringInterpolation{x}Pound,pklEscape{x}Pound oneline'
    exe $'hi def link pklString{x}Pound String'

    exe $'syn region pklMultiString{x}Pound start=+{repeat("#", x)}"""+ end=+"""{repeat("#", x)}+ contains=pklStringInterpolation{x}Pound,pklEscape{x}Pound keepend fold'
    exe $'hi def link pklMultiString{x}Pound String'

    exe $'syn match pklEscape{x}Pound "\\{repeat("#", x) }[\\nt0rbaeuf"'']" contained containedin=pklString{x}Pound,pklMultiString{x}Pound'
    exe $'hi def link pklEscape{x}Pound SpecialChar'

    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'

    exe $'syn region pklUnicodeEscape{x}Pound matchgroup=pklDelimiter start=+\\{repeat("#", x)}u{{+ end=+}}+ contains=pklUnicode contained containedin=pklString{x}Pound,pklMultiString{x}Pound'
    exe $'hi def link pklUnicodeEscape{x}Pound SpecialChar'
  endfor
endfunction

call s:DefineCustomStringDelimiters(5)

" --- Keywords ---
syn keyword	pklBoolean       false true
syn keyword	pklClass         outer super this module new
syn keyword	pklConditional   if else when
syn keyword	pklConstant      null NaN Infinity
syn keyword	pklException     throw
syn keyword	pklInclude       amends import extends as
syn keyword	pklKeyword       function let out is
syn keyword	pklModifier      abstract const external fixed hidden local open
syn keyword	pklReserved      case delete override protected record switch vararg
syn keyword	pklRepeat        for in
syn keyword	pklSpecial       nothing unknown
syn keyword	pklStatement     trace read
syn keyword	pklStruct        typealias class

" Include all unicode letters
exe $'syn match pklIdentifier "{s:id}"'

" Explicitely make keywords identifiers with backticks
syn region	pklIdentifierExplicit	start=+`+ end=+`+

syn match	pklOperator      ",\||\|+\|*\|->\|?\|-\|==\|=\|!=\|!" contained containedin=pklType

" --- Numbers ---
" decimal numbers
syn match	pklNumbers	display transparent "\<\d\|\.\d" contains=pklNumber,pklFloat,pklOctal
syn match	pklNumber	display contained "\d\%(\d\+\)*\>"
" hex numbers
syn match	pklNumber	display contained "0x\x\%('\=\x\+\)\>"
" binary numbers
syn match	pklNumber	display contained "0b[01]\%('\=[01]\+\)\>"
" octal numbers
syn match	pklOctal	display contained "0o\o\+\>"

"floating point number, with dot, optional exponent
syn match	pklFloat	display contained "\d\+\.\d\+\%(e[-+]\=\d\+\)\="
"floating point number, starting with a dot, optional exponent
syn match	pklFloat	display contained "\.\d\+\%(e[-+]\=\d\+\)\=\>"
"floating point number, without dot, with exponent
syn match	pklFloat	display contained "\d\+e[-+]\=\d\+\>"

" --- Brackets, operators, functions ---
syn region	pklParen	matchgroup=pklBrackets start='(' end=')' contains=ALLBUT,pklUnicode transparent
syn region	pklBracket	matchgroup=pklBrackets start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,pklUnicode transparent
syn region	pklBlock	matchgroup=pklBrackets start="{" end="}" contains=ALLBUT,pklUnicode fold transparent

exe $'syn match	pklFunction	"\<\h{s:id}*\>\ze\_s*[?|\*]\?(" contains=pklType'

" --- Highlight links ---
hi def link	pklBoolean                       Boolean
hi def link	pklBrackets                      Delimiter
hi def link	pklClass                         Statement
hi def link	pklCollections                   Type
hi def link	pklComment                       Comment
hi def link	pklConditional                   Conditional
hi def link	pklConstant                      Constant
hi def link	pklDecorator                     Special
hi def link	pklDelimiter                     Delimiter
hi def link	pklDocComment                    Comment
hi def link	pklEscape                        SpecialChar
hi def link	pklException                     Exception
hi def link	pklFloat                         Number
hi def link	pklFunction                      Function
hi def link	pklInclude                       Include
hi def link	pklKeyword                       Keyword
hi def link	pklModifier                      StorageClass
hi def link	pklMultiComment                  Comment
hi def link	pklMultiString                   String
hi def link	pklNumber                        Number
hi def link	pklNumbers                       Number
hi def link	pklOctal                         Number
hi def link	pklRepeat                        Repeat
hi def link	pklReserved                      Error
hi def link	pklShebang                       Comment
hi def link	pklSpecial                       Special
hi def link	pklStatement                     Statement
hi def link	pklString                        String
hi def link	pklStruct                        Structure
hi def link	pklType                          Type
hi def link	pklUnicodeEscape                 SpecialChar

let b:current_syntax = "pkl"

let &cpo = s:cpo_save
unlet s:cpo_save