@apple/tree-sitter-pkl 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CODE_OF_CONDUCT.adoc +78 -0
- package/CONTRIBUTING.adoc +52 -0
- package/Cargo.lock +80 -0
- package/Cargo.toml +29 -0
- package/LICENSE.txt +202 -0
- package/MAINTAINERS.adoc +11 -0
- package/NOTICE.txt +4 -0
- package/README.adoc +61 -0
- package/SECURITY.adoc +13 -0
- package/binding.gyp +19 -0
- package/bindings/node/binding.cc +28 -0
- package/bindings/node/index.js +19 -0
- package/grammar.js +779 -0
- package/package.json +51 -0
- package/queries/highlights.scm +138 -0
- package/queries/injections.scm +9 -0
- package/queries/locals.scm +38 -0
- package/src/grammar.json +3962 -0
- package/src/node-types.json +5668 -0
- package/src/parser.c +59696 -0
- package/src/scanner.c +285 -0
- package/src/synctests.ts +44 -0
- package/src/tree_sitter/parser.h +224 -0
- package/tsconfig.json +101 -0
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apple/tree-sitter-pkl",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "Pkl grammar for node-tree-sitter",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/apple/tree-sitter-pkl"
|
|
8
|
+
},
|
|
9
|
+
"main": "bindings/node",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"parser",
|
|
12
|
+
"lexer"
|
|
13
|
+
],
|
|
14
|
+
"author": "pkl-oss@group.apple.com",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/apple/tree-sitter-pkl/issues"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": "18.17.0",
|
|
21
|
+
"npm": "9.6.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"nan": "^2.17.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/glob": "^8.1.0",
|
|
28
|
+
"@types/node": "^20.4.5",
|
|
29
|
+
"node-gyp": "^9.1.0",
|
|
30
|
+
"tree-sitter-cli": "^0.20.0",
|
|
31
|
+
"ts-node": "^10.0.0",
|
|
32
|
+
"typescript": "^4.9.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tree-sitter generate && node-gyp configure && node-gyp build",
|
|
36
|
+
"test": "tree-sitter test",
|
|
37
|
+
"synctests": "ts-node src/synctests.ts",
|
|
38
|
+
"getVersion": "node -p \"require('./package.json').version\""
|
|
39
|
+
},
|
|
40
|
+
"tree-sitter": [
|
|
41
|
+
{
|
|
42
|
+
"scope": "source.pkl",
|
|
43
|
+
"file-types": [
|
|
44
|
+
"pkl",
|
|
45
|
+
"pcf"
|
|
46
|
+
],
|
|
47
|
+
"first-line-regex": "#!.*\\bpkl$",
|
|
48
|
+
"injection-regex": "pkl"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
; Types
|
|
2
|
+
|
|
3
|
+
(clazz (identifier) @type)
|
|
4
|
+
(typeAlias (identifier) @type)
|
|
5
|
+
((identifier) @type
|
|
6
|
+
(match? @type "^[A-Z]"))
|
|
7
|
+
|
|
8
|
+
(typeArgumentList
|
|
9
|
+
"<" @punctuation.bracket
|
|
10
|
+
">" @punctuation.bracket)
|
|
11
|
+
|
|
12
|
+
; Method calls
|
|
13
|
+
|
|
14
|
+
(methodCallExpr
|
|
15
|
+
(identifier) @function.method)
|
|
16
|
+
|
|
17
|
+
; Method definitions
|
|
18
|
+
|
|
19
|
+
(classMethod (methodHeader (identifier)) @function.method)
|
|
20
|
+
(objectMethod (methodHeader (identifier)) @function.method)
|
|
21
|
+
|
|
22
|
+
; Identifiers
|
|
23
|
+
|
|
24
|
+
(classProperty (identifier) @property)
|
|
25
|
+
(objectProperty (identifier) @property)
|
|
26
|
+
|
|
27
|
+
(parameterList (typedIdentifier (identifier) @variable.parameter))
|
|
28
|
+
(objectBodyParameters (typedIdentifier (identifier) @variable.parameter))
|
|
29
|
+
|
|
30
|
+
(identifier) @variable
|
|
31
|
+
|
|
32
|
+
; Literals
|
|
33
|
+
|
|
34
|
+
(stringConstant) @string
|
|
35
|
+
(slStringLiteral) @string
|
|
36
|
+
(mlStringLiteral) @string
|
|
37
|
+
|
|
38
|
+
(escapeSequence) @escape
|
|
39
|
+
|
|
40
|
+
(intLiteral) @number
|
|
41
|
+
(floatLiteral) @number
|
|
42
|
+
|
|
43
|
+
(interpolationExpr
|
|
44
|
+
"\\(" @punctuation.special
|
|
45
|
+
")" @punctuation.special) @embedded
|
|
46
|
+
|
|
47
|
+
(interpolationExpr
|
|
48
|
+
"\\#(" @punctuation.special
|
|
49
|
+
")" @punctuation.special) @embedded
|
|
50
|
+
|
|
51
|
+
(interpolationExpr
|
|
52
|
+
"\\##(" @punctuation.special
|
|
53
|
+
")" @punctuation.special) @embedded
|
|
54
|
+
|
|
55
|
+
(lineComment) @comment
|
|
56
|
+
(blockComment) @comment
|
|
57
|
+
(docComment) @comment
|
|
58
|
+
|
|
59
|
+
; Operators
|
|
60
|
+
|
|
61
|
+
"??" @operator
|
|
62
|
+
"@" @operator
|
|
63
|
+
"=" @operator
|
|
64
|
+
"<" @operator
|
|
65
|
+
">" @operator
|
|
66
|
+
"!" @operator
|
|
67
|
+
"==" @operator
|
|
68
|
+
"!=" @operator
|
|
69
|
+
"<=" @operator
|
|
70
|
+
">=" @operator
|
|
71
|
+
"&&" @operator
|
|
72
|
+
"||" @operator
|
|
73
|
+
"+" @operator
|
|
74
|
+
"-" @operator
|
|
75
|
+
"**" @operator
|
|
76
|
+
"*" @operator
|
|
77
|
+
"/" @operator
|
|
78
|
+
"~/" @operator
|
|
79
|
+
"%" @operator
|
|
80
|
+
"|>" @operator
|
|
81
|
+
|
|
82
|
+
"?" @operator.type
|
|
83
|
+
"|" @operator.type
|
|
84
|
+
"->" @operator.type
|
|
85
|
+
|
|
86
|
+
"," @punctuation.delimiter
|
|
87
|
+
":" @punctuation.delimiter
|
|
88
|
+
"." @punctuation.delimiter
|
|
89
|
+
"?." @punctuation.delimiter
|
|
90
|
+
|
|
91
|
+
"(" @punctuation.bracket
|
|
92
|
+
")" @punctuation.bracket
|
|
93
|
+
; "[" @punctuation.bracket TODO: FIGURE OUT HOW TO REFER TO CUSTOM TOKENS
|
|
94
|
+
"]" @punctuation.bracket
|
|
95
|
+
"{" @punctuation.bracket
|
|
96
|
+
"}" @punctuation.bracket
|
|
97
|
+
|
|
98
|
+
; Keywords
|
|
99
|
+
|
|
100
|
+
"abstract" @keyword
|
|
101
|
+
"amends" @keyword
|
|
102
|
+
"as" @keyword
|
|
103
|
+
"class" @keyword
|
|
104
|
+
"else" @keyword
|
|
105
|
+
"extends" @keyword
|
|
106
|
+
"external" @keyword
|
|
107
|
+
(falseLiteral) @constant.builtin
|
|
108
|
+
"for" @keyword
|
|
109
|
+
"function" @keyword
|
|
110
|
+
"hidden" @keyword
|
|
111
|
+
"if" @keyword
|
|
112
|
+
(importExpr "import" @function.method.builtin)
|
|
113
|
+
(importGlobExpr "import*" @function.method.builtin)
|
|
114
|
+
"import" @keyword
|
|
115
|
+
"import*" @keyword
|
|
116
|
+
"in" @keyword
|
|
117
|
+
"is" @keyword
|
|
118
|
+
"let" @keyword
|
|
119
|
+
"local" @keyword
|
|
120
|
+
(moduleExpr "module" @type.builtin)
|
|
121
|
+
"module" @keyword
|
|
122
|
+
"new" @keyword
|
|
123
|
+
"nothing" @type.builtin
|
|
124
|
+
(nullLiteral) @constant.builtin
|
|
125
|
+
"open" @keyword
|
|
126
|
+
"out" @keyword
|
|
127
|
+
(outerExpr) @variable.builtin
|
|
128
|
+
"read" @function.method.builtin
|
|
129
|
+
"read?" @function.method.builtin
|
|
130
|
+
"read*" @function.method.builtin
|
|
131
|
+
"super" @variable.builtin
|
|
132
|
+
(thisExpr) @variable.builtin
|
|
133
|
+
"throw" @function.method.builtin
|
|
134
|
+
"trace" @function.method.builtin
|
|
135
|
+
(trueLiteral) @constant.builtin
|
|
136
|
+
"typealias" @keyword
|
|
137
|
+
"unknown" @type.builtin
|
|
138
|
+
"when" @keyword
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
; this definition is imprecise in that
|
|
2
|
+
; * any qualified or unqualified call to a method named "Regex" is considered a regex
|
|
3
|
+
; * string delimiters are considered part of the regex
|
|
4
|
+
(
|
|
5
|
+
((methodCallExpr (identifier) @methodName (argumentList (slStringLiteral) @injection.content))
|
|
6
|
+
(set! injection.language "regex"))
|
|
7
|
+
(eq? @methodName "Regex"))
|
|
8
|
+
|
|
9
|
+
; TODO: inject markdown into doc comments
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
; Scopes
|
|
2
|
+
|
|
3
|
+
(module) @local.scope
|
|
4
|
+
(clazz) @local.scope
|
|
5
|
+
(classMethod) @local.scope
|
|
6
|
+
(objectMethod) @local.scope
|
|
7
|
+
(functionLiteral) @local.scope
|
|
8
|
+
(objectBody) @local.scope
|
|
9
|
+
(letExpr) @local.scope
|
|
10
|
+
(forGenerator) @local.scope
|
|
11
|
+
|
|
12
|
+
; Definitions
|
|
13
|
+
|
|
14
|
+
(clazz
|
|
15
|
+
(identifier) @local.definition)
|
|
16
|
+
|
|
17
|
+
(typeAlias
|
|
18
|
+
(identifier) @local.definition)
|
|
19
|
+
|
|
20
|
+
(classMethod
|
|
21
|
+
(methodHeader (identifier)) @local.definition)
|
|
22
|
+
|
|
23
|
+
(objectMethod
|
|
24
|
+
(methodHeader (identifier)) @local.definition)
|
|
25
|
+
|
|
26
|
+
(classProperty
|
|
27
|
+
(identifier) @local.definition)
|
|
28
|
+
|
|
29
|
+
(objectProperty
|
|
30
|
+
(identifier) @local.definition)
|
|
31
|
+
|
|
32
|
+
(typedIdentifier
|
|
33
|
+
(identifier) @local.definition)
|
|
34
|
+
|
|
35
|
+
; References
|
|
36
|
+
|
|
37
|
+
(variableExpr
|
|
38
|
+
(identifier) @local.reference)
|