@apple/tree-sitter-pkl 0.16.0 → 0.17.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/CHANGELOG.adoc +40 -0
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/Package.swift +24 -0
- package/README.md +42 -0
- package/bindings/c/tree-sitter-pkl.h +16 -0
- package/bindings/swift/TreeSitterPkl/pkl.h +16 -0
- package/grammar.js +147 -63
- package/package.json +3 -4
- package/queries/highlights.scm +3 -8
- package/queries/injections.scm +3 -3
- package/src/grammar.json +750 -353
- package/src/node-types.json +1768 -1043
- package/src/parser.c +45772 -50670
- package/src/scanner.c +60 -28
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +290 -0
- package/src/tree_sitter/parser.h +54 -13
- package/test/corpus/basic/annotation.txt +243 -0
- package/test/corpus/basic/comments.txt +41 -0
- package/test/corpus/basic/shebangComment.txt +15 -0
- package/test/corpus/basic/types.txt +232 -0
- package/test/corpus/class/constModifier.txt +24 -0
- package/test/corpus/class/fixedModifier.txt +24 -0
- package/test/corpus/expr/binary.txt +109 -0
- package/test/corpus/expr/functionLiteral.txt +23 -0
- package/test/corpus/expr/if.txt +15 -0
- package/test/corpus/expr/import.txt +20 -0
- package/test/corpus/expr/let.txt +17 -0
- package/test/corpus/expr/new.txt +36 -0
- package/test/corpus/expr/qualifiedAccess.txt +95 -0
- package/test/corpus/expr/read.txt +29 -0
- package/test/corpus/expr/throw.txt +14 -0
- package/test/corpus/expr/trace.txt +14 -0
- package/test/corpus/module/moduleHeader1.txt +23 -0
- package/test/corpus/module/moduleHeader2.txt +29 -0
- package/test/corpus/module/moduleHeader3.error.txt +23 -0
- package/test/corpus/module/moduleHeader4.txt +34 -0
- package/test/corpus/module/moduleHeader5.txt +16 -0
- package/test/corpus/module/moduleHeader6.txt +17 -0
- package/test/corpus/number/underscores.txt +99 -0
- package/test/corpus/object/objectAmendChain.txt +38 -0
- package/test/corpus/object/objectElementsWithParens.txt +51 -0
- package/test/corpus/object/objectGenerator.txt +53 -0
- package/test/corpus/object/objectMember.txt +129 -0
- package/test/corpus/object/objectMemberPredicate.txt +41 -0
- package/test/corpus/object/objectSpread.txt +51 -0
- package/test/corpus/object/objectWhenGenerator.txt +71 -0
- package/test/corpus/string/customStringDelimiters.txt +397 -0
- package/test/corpus/string/missingDelimiter.txt +28 -0
- package/test/corpus/string/multiline.txt +39 -0
- package/test/corpus/string/multilineInterpolation.txt +102 -0
- package/test/corpus/string/simple.txt +13 -0
- package/test/corpus/string/singleLineEscapes.txt +64 -0
- package/test/corpus/string/singleLineInterpolation.txt +94 -0
- package/test/corpus/string/stringWithTwoSlashes.txt +20 -0
- package/README.adoc +0 -61
- package/src/synctests.ts +0 -44
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
multiline
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
res1 = """
|
|
6
|
+
Hi there
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
res2 = #"""
|
|
10
|
+
"AS IS"
|
|
11
|
+
"""#
|
|
12
|
+
|
|
13
|
+
res3 = #"""
|
|
14
|
+
""AS IS""
|
|
15
|
+
"""#
|
|
16
|
+
|
|
17
|
+
res4 = #"""
|
|
18
|
+
"""""AS IS"""""
|
|
19
|
+
"""#
|
|
20
|
+
|
|
21
|
+
--------------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
(module
|
|
24
|
+
(classProperty
|
|
25
|
+
(identifier)
|
|
26
|
+
(mlStringLiteral
|
|
27
|
+
(mlStringLiteralPart)))
|
|
28
|
+
(classProperty
|
|
29
|
+
(identifier)
|
|
30
|
+
(mlStringLiteral
|
|
31
|
+
(mlStringLiteralPart)))
|
|
32
|
+
(classProperty
|
|
33
|
+
(identifier)
|
|
34
|
+
(mlStringLiteral
|
|
35
|
+
(mlStringLiteralPart)))
|
|
36
|
+
(classProperty
|
|
37
|
+
(identifier)
|
|
38
|
+
(mlStringLiteral
|
|
39
|
+
(mlStringLiteralPart))))
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
multilineInterpolation
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
res1 = """
|
|
6
|
+
Well hello there how are you?
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
res2 = """
|
|
10
|
+
Hi \(bob)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
res3 = #"""
|
|
14
|
+
Hi \(bob)
|
|
15
|
+
"""#
|
|
16
|
+
|
|
17
|
+
res4 = #"""
|
|
18
|
+
Hi \#(bob)
|
|
19
|
+
"""#
|
|
20
|
+
|
|
21
|
+
res5 = ##"""
|
|
22
|
+
Hi \#(bob)
|
|
23
|
+
"""##
|
|
24
|
+
|
|
25
|
+
res6 = ###"""
|
|
26
|
+
Hi \###(bob)
|
|
27
|
+
"""###
|
|
28
|
+
|
|
29
|
+
res7 = ####"""
|
|
30
|
+
Hi \####(bob)
|
|
31
|
+
"""####
|
|
32
|
+
|
|
33
|
+
res8 = #####"""
|
|
34
|
+
Hi \#####(bob)
|
|
35
|
+
"""#####
|
|
36
|
+
|
|
37
|
+
res9 = ######"""
|
|
38
|
+
Hi \######(bob)
|
|
39
|
+
"""######
|
|
40
|
+
--------------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
(module
|
|
43
|
+
(classProperty
|
|
44
|
+
(identifier)
|
|
45
|
+
(mlStringLiteral
|
|
46
|
+
(mlStringLiteralPart)))
|
|
47
|
+
(classProperty
|
|
48
|
+
(identifier)
|
|
49
|
+
(mlStringLiteral
|
|
50
|
+
(mlStringLiteralPart)
|
|
51
|
+
(interpolationExpr
|
|
52
|
+
(variableExpr
|
|
53
|
+
(identifier)))
|
|
54
|
+
(mlStringLiteralPart)))
|
|
55
|
+
(classProperty
|
|
56
|
+
(identifier)
|
|
57
|
+
(mlStringLiteral
|
|
58
|
+
(mlStringLiteralPart)))
|
|
59
|
+
(classProperty
|
|
60
|
+
(identifier)
|
|
61
|
+
(mlStringLiteral
|
|
62
|
+
(mlStringLiteralPart)
|
|
63
|
+
(interpolationExpr
|
|
64
|
+
(variableExpr
|
|
65
|
+
(identifier)))
|
|
66
|
+
(mlStringLiteralPart)))
|
|
67
|
+
(classProperty
|
|
68
|
+
(identifier)
|
|
69
|
+
(mlStringLiteral
|
|
70
|
+
(mlStringLiteralPart)))
|
|
71
|
+
(classProperty
|
|
72
|
+
(identifier)
|
|
73
|
+
(mlStringLiteral
|
|
74
|
+
(mlStringLiteralPart)
|
|
75
|
+
(interpolationExpr
|
|
76
|
+
(variableExpr
|
|
77
|
+
(identifier)))
|
|
78
|
+
(mlStringLiteralPart)))
|
|
79
|
+
(classProperty
|
|
80
|
+
(identifier)
|
|
81
|
+
(mlStringLiteral
|
|
82
|
+
(mlStringLiteralPart)
|
|
83
|
+
(interpolationExpr
|
|
84
|
+
(variableExpr
|
|
85
|
+
(identifier)))
|
|
86
|
+
(mlStringLiteralPart)))
|
|
87
|
+
(classProperty
|
|
88
|
+
(identifier)
|
|
89
|
+
(mlStringLiteral
|
|
90
|
+
(mlStringLiteralPart)
|
|
91
|
+
(interpolationExpr
|
|
92
|
+
(variableExpr
|
|
93
|
+
(identifier)))
|
|
94
|
+
(mlStringLiteralPart)))
|
|
95
|
+
(classProperty
|
|
96
|
+
(identifier)
|
|
97
|
+
(mlStringLiteral
|
|
98
|
+
(mlStringLiteralPart)
|
|
99
|
+
(interpolationExpr
|
|
100
|
+
(variableExpr
|
|
101
|
+
(identifier)))
|
|
102
|
+
(mlStringLiteralPart))))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
simple
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
str = "Hello there"
|
|
6
|
+
|
|
7
|
+
--------------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
(module
|
|
10
|
+
(classProperty
|
|
11
|
+
(identifier)
|
|
12
|
+
(slStringLiteral
|
|
13
|
+
(slStringLiteralPart))))
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
===
|
|
2
|
+
singleLineEscapes
|
|
3
|
+
===
|
|
4
|
+
|
|
5
|
+
res1 = "bar \\t \t baz"
|
|
6
|
+
|
|
7
|
+
res2 = #"bar \t \#t baz"#
|
|
8
|
+
|
|
9
|
+
res3 = ##"bar \#t \##t baz"##
|
|
10
|
+
|
|
11
|
+
res4 = ###"bar \##t \###t baz"###
|
|
12
|
+
|
|
13
|
+
res5 = ####"bar \###t \####t baz"####
|
|
14
|
+
|
|
15
|
+
res6 = #####"bar \####t \#####t baz"#####
|
|
16
|
+
|
|
17
|
+
res7 = ######"bar \#####t \######t baz"######
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
(module
|
|
21
|
+
(classProperty
|
|
22
|
+
(identifier)
|
|
23
|
+
(slStringLiteral
|
|
24
|
+
(slStringLiteralPart)
|
|
25
|
+
(escapeSequence)
|
|
26
|
+
(slStringLiteralPart)
|
|
27
|
+
(escapeSequence)
|
|
28
|
+
(slStringLiteralPart)))
|
|
29
|
+
(classProperty
|
|
30
|
+
(identifier)
|
|
31
|
+
(slStringLiteral
|
|
32
|
+
(slStringLiteralPart)
|
|
33
|
+
(escapeSequence)
|
|
34
|
+
(slStringLiteralPart)))
|
|
35
|
+
(classProperty
|
|
36
|
+
(identifier)
|
|
37
|
+
(slStringLiteral
|
|
38
|
+
(slStringLiteralPart)
|
|
39
|
+
(escapeSequence)
|
|
40
|
+
(slStringLiteralPart)))
|
|
41
|
+
(classProperty
|
|
42
|
+
(identifier)
|
|
43
|
+
(slStringLiteral
|
|
44
|
+
(slStringLiteralPart)
|
|
45
|
+
(escapeSequence)
|
|
46
|
+
(slStringLiteralPart)))
|
|
47
|
+
(classProperty
|
|
48
|
+
(identifier)
|
|
49
|
+
(slStringLiteral
|
|
50
|
+
(slStringLiteralPart)
|
|
51
|
+
(escapeSequence)
|
|
52
|
+
(slStringLiteralPart)))
|
|
53
|
+
(classProperty
|
|
54
|
+
(identifier)
|
|
55
|
+
(slStringLiteral
|
|
56
|
+
(slStringLiteralPart)
|
|
57
|
+
(escapeSequence)
|
|
58
|
+
(slStringLiteralPart)))
|
|
59
|
+
(classProperty
|
|
60
|
+
(identifier)
|
|
61
|
+
(slStringLiteral
|
|
62
|
+
(slStringLiteralPart)
|
|
63
|
+
(escapeSequence)
|
|
64
|
+
(slStringLiteralPart))))
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
singleLineInterpolation
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
res1 = "Hi there \(bob)"
|
|
6
|
+
|
|
7
|
+
res2 = #"Hi there \(bob)"#
|
|
8
|
+
|
|
9
|
+
res3 = #"Hi there \#(bob)"#
|
|
10
|
+
|
|
11
|
+
res4 = ##"Hi there \#(bob)"##
|
|
12
|
+
|
|
13
|
+
res5 = ##"Hi there \##(bob)"##
|
|
14
|
+
|
|
15
|
+
res6 = ##"Hi there \##(#"Hi there \#(bob)"#)"##
|
|
16
|
+
|
|
17
|
+
res7 = ###"Hi there \###(bob)"###
|
|
18
|
+
|
|
19
|
+
res8 = ####"Hi there \####(bob)"####
|
|
20
|
+
|
|
21
|
+
res9 = #####"Hi there \#####(bob)"#####
|
|
22
|
+
|
|
23
|
+
res10 = ######"Hi there \######(bob)"######
|
|
24
|
+
|
|
25
|
+
--------------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
(module
|
|
28
|
+
(classProperty
|
|
29
|
+
(identifier)
|
|
30
|
+
(slStringLiteral
|
|
31
|
+
(slStringLiteralPart)
|
|
32
|
+
(interpolationExpr
|
|
33
|
+
(variableExpr
|
|
34
|
+
(identifier)))))
|
|
35
|
+
(classProperty
|
|
36
|
+
(identifier)
|
|
37
|
+
(slStringLiteral
|
|
38
|
+
(slStringLiteralPart)))
|
|
39
|
+
(classProperty
|
|
40
|
+
(identifier)
|
|
41
|
+
(slStringLiteral
|
|
42
|
+
(slStringLiteralPart)
|
|
43
|
+
(interpolationExpr
|
|
44
|
+
(variableExpr
|
|
45
|
+
(identifier)))))
|
|
46
|
+
(classProperty
|
|
47
|
+
(identifier)
|
|
48
|
+
(slStringLiteral
|
|
49
|
+
(slStringLiteralPart)))
|
|
50
|
+
(classProperty
|
|
51
|
+
(identifier)
|
|
52
|
+
(slStringLiteral
|
|
53
|
+
(slStringLiteralPart)
|
|
54
|
+
(interpolationExpr
|
|
55
|
+
(variableExpr
|
|
56
|
+
(identifier)))))
|
|
57
|
+
(classProperty
|
|
58
|
+
(identifier)
|
|
59
|
+
(slStringLiteral
|
|
60
|
+
(slStringLiteralPart)
|
|
61
|
+
(interpolationExpr
|
|
62
|
+
(slStringLiteral
|
|
63
|
+
(slStringLiteralPart)
|
|
64
|
+
(interpolationExpr
|
|
65
|
+
(variableExpr
|
|
66
|
+
(identifier)))))))
|
|
67
|
+
(classProperty
|
|
68
|
+
(identifier)
|
|
69
|
+
(slStringLiteral
|
|
70
|
+
(slStringLiteralPart)
|
|
71
|
+
(interpolationExpr
|
|
72
|
+
(variableExpr
|
|
73
|
+
(identifier)))))
|
|
74
|
+
(classProperty
|
|
75
|
+
(identifier)
|
|
76
|
+
(slStringLiteral
|
|
77
|
+
(slStringLiteralPart)
|
|
78
|
+
(interpolationExpr
|
|
79
|
+
(variableExpr
|
|
80
|
+
(identifier)))))
|
|
81
|
+
(classProperty
|
|
82
|
+
(identifier)
|
|
83
|
+
(slStringLiteral
|
|
84
|
+
(slStringLiteralPart)
|
|
85
|
+
(interpolationExpr
|
|
86
|
+
(variableExpr
|
|
87
|
+
(identifier)))))
|
|
88
|
+
(classProperty
|
|
89
|
+
(identifier)
|
|
90
|
+
(slStringLiteral
|
|
91
|
+
(slStringLiteralPart)
|
|
92
|
+
(interpolationExpr
|
|
93
|
+
(variableExpr
|
|
94
|
+
(identifier))))))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
===
|
|
2
|
+
stringWithTwoSlashes
|
|
3
|
+
===
|
|
4
|
+
|
|
5
|
+
foo = "// this is string text"
|
|
6
|
+
|
|
7
|
+
bar = """
|
|
8
|
+
// this is string text
|
|
9
|
+
"""
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
(module
|
|
13
|
+
(classProperty
|
|
14
|
+
(identifier)
|
|
15
|
+
(slStringLiteral
|
|
16
|
+
(slStringLiteralPart)))
|
|
17
|
+
(classProperty
|
|
18
|
+
(identifier)
|
|
19
|
+
(mlStringLiteral
|
|
20
|
+
(mlStringLiteralPart))))
|
package/README.adoc
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
A tree-sitter grammar for Pkl.
|
|
2
|
-
|
|
3
|
-
[source, shell]
|
|
4
|
-
----
|
|
5
|
-
# install dependencies
|
|
6
|
-
$ npm install
|
|
7
|
-
|
|
8
|
-
# build parser
|
|
9
|
-
$ npm run build
|
|
10
|
-
|
|
11
|
-
# parse some code
|
|
12
|
-
$ ./node_modules/.bin/tree-sitter parse test.pkl
|
|
13
|
-
----
|
|
14
|
-
|
|
15
|
-
== Tests
|
|
16
|
-
|
|
17
|
-
Tree sitter comes with its own test framework.
|
|
18
|
-
Files in `corpus/` describe one test each.
|
|
19
|
-
All tests in `corpus/` are performed by the command
|
|
20
|
-
|
|
21
|
-
[source,shell]
|
|
22
|
-
---
|
|
23
|
-
$ tree-sitter test
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
The script `src/synctests.ts` creates `corpus/` test files from tests in `pkl`'s `LanguageSnippetTests`.
|
|
27
|
-
The script assumes that `../pkl` is a checked out `pkl` repository (and that the tests are under `pkl-core/src/test/files/LanguageSnippetFiles/input`).
|
|
28
|
-
A pre-condition of the script is that `tree-sitter test` currently passes.
|
|
29
|
-
If broken tests need replacing, the broken tests must first be deleted.
|
|
30
|
-
|
|
31
|
-
It can be executed by running
|
|
32
|
-
|
|
33
|
-
[source,shell]
|
|
34
|
-
---
|
|
35
|
-
$ npm run synctests
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
== Upgrading tree-sitter
|
|
39
|
-
|
|
40
|
-
Upgrading tree-sitter involves upgrading the NPM package.
|
|
41
|
-
|
|
42
|
-
1. Run `npm update tree-sitter` to install the newer version of tree-sitter.
|
|
43
|
-
2. Commit to main, and push.
|
|
44
|
-
|
|
45
|
-
== Releasing
|
|
46
|
-
|
|
47
|
-
1. Run the build & test to make sure everything is up-to-date and passes (check 0 diff).
|
|
48
|
-
2. Create a `Prepare 1.2.3 release` (with appropriate version number) commit where
|
|
49
|
-
* Versions are bumped in `package.json`, `Cargo.toml`
|
|
50
|
-
* Lockfiles are updated (`npm install`, `cargo check`)
|
|
51
|
-
* You have checked the previous release PR for any changes in process not described in this `README.adoc`; if any
|
|
52
|
-
- Adopt the changes accordingly
|
|
53
|
-
- Update this description to capture the changed process
|
|
54
|
-
3. Merge into `main` & push
|
|
55
|
-
4. Check that CI release succeeded (https://app.circleci.com/pipelines/github/apple/tree-sitter-pkl[release pipeline])
|
|
56
|
-
5. Check the publication is reachable, https://www.npmjs.com/package/@apple/tree-sitter-pkl[on NPM]
|
|
57
|
-
|
|
58
|
-
== Resources
|
|
59
|
-
|
|
60
|
-
- https://tree-sitter.github.io/tree-sitter/[Tree-sitter docs]
|
|
61
|
-
- https://gist.github.com/Aerijo/df27228d70c633e088b0591b8857eeef[Guide to your first Tree-sitter grammar]
|
package/src/synctests.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { glob as _glob } from 'glob'
|
|
17
|
-
import * as fs from 'fs/promises'
|
|
18
|
-
import { promisify } from 'util'
|
|
19
|
-
import * as path from 'path'
|
|
20
|
-
import { spawn as _spawn } from 'child_process'
|
|
21
|
-
|
|
22
|
-
const glob = promisify(_glob);
|
|
23
|
-
const spawn = promisify(_spawn);
|
|
24
|
-
|
|
25
|
-
const testDir = '../pkl/pkl-core/src/test/files/LanguageSnippetTests/input';
|
|
26
|
-
const pattern = '**/*.pkl';
|
|
27
|
-
const treeSitterCmd = 'node_modules/.bin/tree-sitter';
|
|
28
|
-
|
|
29
|
-
(async () => {
|
|
30
|
-
await fs.rmdir('corpus/snippetTests/', { recursive: true });
|
|
31
|
-
|
|
32
|
-
const srcFiles = await glob(`${testDir}/${pattern}`);
|
|
33
|
-
for (const srcFile of srcFiles) {
|
|
34
|
-
const contents = await fs.readFile(srcFile, { encoding: 'utf-8' })
|
|
35
|
-
const testName = srcFile.replace(testDir + '/', '').replace(/.pkl$/, '')
|
|
36
|
-
const output = `==========\n${testName}\n==========\n\n${contents.trim()}\n\n---\n\n`
|
|
37
|
-
const dest = `corpus/snippetTests/${testName}.txt`;
|
|
38
|
-
// const destExists = await fs.
|
|
39
|
-
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
40
|
-
await fs.writeFile(dest, output, { encoding: 'utf-8' });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await spawn(treeSitterCmd, ['test', '--update'], { stdio: 'inherit' });
|
|
44
|
-
})();
|