@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.
Files changed (58) hide show
  1. package/CHANGELOG.adoc +40 -0
  2. package/Cargo.lock +1 -1
  3. package/Cargo.toml +1 -1
  4. package/Package.swift +24 -0
  5. package/README.md +42 -0
  6. package/bindings/c/tree-sitter-pkl.h +16 -0
  7. package/bindings/swift/TreeSitterPkl/pkl.h +16 -0
  8. package/grammar.js +147 -63
  9. package/package.json +3 -4
  10. package/queries/highlights.scm +3 -8
  11. package/queries/injections.scm +3 -3
  12. package/src/grammar.json +750 -353
  13. package/src/node-types.json +1768 -1043
  14. package/src/parser.c +45772 -50670
  15. package/src/scanner.c +60 -28
  16. package/src/tree_sitter/alloc.h +54 -0
  17. package/src/tree_sitter/array.h +290 -0
  18. package/src/tree_sitter/parser.h +54 -13
  19. package/test/corpus/basic/annotation.txt +243 -0
  20. package/test/corpus/basic/comments.txt +41 -0
  21. package/test/corpus/basic/shebangComment.txt +15 -0
  22. package/test/corpus/basic/types.txt +232 -0
  23. package/test/corpus/class/constModifier.txt +24 -0
  24. package/test/corpus/class/fixedModifier.txt +24 -0
  25. package/test/corpus/expr/binary.txt +109 -0
  26. package/test/corpus/expr/functionLiteral.txt +23 -0
  27. package/test/corpus/expr/if.txt +15 -0
  28. package/test/corpus/expr/import.txt +20 -0
  29. package/test/corpus/expr/let.txt +17 -0
  30. package/test/corpus/expr/new.txt +36 -0
  31. package/test/corpus/expr/qualifiedAccess.txt +95 -0
  32. package/test/corpus/expr/read.txt +29 -0
  33. package/test/corpus/expr/throw.txt +14 -0
  34. package/test/corpus/expr/trace.txt +14 -0
  35. package/test/corpus/module/moduleHeader1.txt +23 -0
  36. package/test/corpus/module/moduleHeader2.txt +29 -0
  37. package/test/corpus/module/moduleHeader3.error.txt +23 -0
  38. package/test/corpus/module/moduleHeader4.txt +34 -0
  39. package/test/corpus/module/moduleHeader5.txt +16 -0
  40. package/test/corpus/module/moduleHeader6.txt +17 -0
  41. package/test/corpus/number/underscores.txt +99 -0
  42. package/test/corpus/object/objectAmendChain.txt +38 -0
  43. package/test/corpus/object/objectElementsWithParens.txt +51 -0
  44. package/test/corpus/object/objectGenerator.txt +53 -0
  45. package/test/corpus/object/objectMember.txt +129 -0
  46. package/test/corpus/object/objectMemberPredicate.txt +41 -0
  47. package/test/corpus/object/objectSpread.txt +51 -0
  48. package/test/corpus/object/objectWhenGenerator.txt +71 -0
  49. package/test/corpus/string/customStringDelimiters.txt +397 -0
  50. package/test/corpus/string/missingDelimiter.txt +28 -0
  51. package/test/corpus/string/multiline.txt +39 -0
  52. package/test/corpus/string/multilineInterpolation.txt +102 -0
  53. package/test/corpus/string/simple.txt +13 -0
  54. package/test/corpus/string/singleLineEscapes.txt +64 -0
  55. package/test/corpus/string/singleLineInterpolation.txt +94 -0
  56. package/test/corpus/string/stringWithTwoSlashes.txt +20 -0
  57. package/README.adoc +0 -61
  58. package/src/synctests.ts +0 -44
@@ -0,0 +1,15 @@
1
+ ===
2
+ if
3
+ ===
4
+
5
+ foo = if (true) 1 else 2
6
+
7
+ ---
8
+
9
+ (module
10
+ (classProperty
11
+ (identifier)
12
+ (ifExpr
13
+ (trueLiteral)
14
+ (intLiteral)
15
+ (intLiteral))))
@@ -0,0 +1,20 @@
1
+ ================================================================================
2
+ import
3
+ ================================================================================
4
+
5
+ res1 = import("foo.txt")
6
+ res2 = import*("foo.txt")
7
+
8
+ --------------------------------------------------------------------------------
9
+
10
+ (module
11
+ (classProperty
12
+ (identifier)
13
+ (importExpr
14
+ (stringConstant
15
+ (slStringLiteralPart))))
16
+ (classProperty
17
+ (identifier)
18
+ (importGlobExpr
19
+ (stringConstant
20
+ (slStringLiteralPart)))))
@@ -0,0 +1,17 @@
1
+ ===
2
+ let
3
+ ===
4
+
5
+ foo = let (prop = 1) prop
6
+
7
+ ---
8
+
9
+ (module
10
+ (classProperty
11
+ (identifier)
12
+ (letExpr
13
+ (typedIdentifier
14
+ (identifier))
15
+ (intLiteral)
16
+ (variableExpr
17
+ (identifier)))))
@@ -0,0 +1,36 @@
1
+ ===
2
+ new
3
+ ===
4
+
5
+ res1 = new {}
6
+
7
+ res2 = new Dynamic {}
8
+
9
+ res3 = new Dynamic {} {} {}
10
+ ---
11
+
12
+ (module
13
+ (classProperty
14
+ (identifier)
15
+ (newExpr
16
+ (objectBody)))
17
+ (classProperty
18
+ (identifier)
19
+ (newExpr
20
+ (type
21
+ (declaredType
22
+ (qualifiedIdentifier
23
+ (identifier))))
24
+ (objectBody)))
25
+ (classProperty
26
+ (identifier)
27
+ (objectLiteral
28
+ (objectLiteral
29
+ (newExpr
30
+ (type
31
+ (declaredType
32
+ (qualifiedIdentifier
33
+ (identifier))))
34
+ (objectBody))
35
+ (objectBody))
36
+ (objectBody))))
@@ -0,0 +1,95 @@
1
+ ===
2
+ qualifiedAccess
3
+ ===
4
+
5
+ res1 = foo.bar
6
+
7
+ res2 = foo
8
+ .bar
9
+
10
+ res3 = foo.bar()
11
+
12
+ res4 = foo
13
+ .bar()
14
+
15
+ res5 = foo?.bar
16
+
17
+ res6 = foo
18
+ ?.bar
19
+
20
+ res7 = foo?.bar()
21
+
22
+ res8 = foo
23
+ ?.bar()
24
+
25
+ // permit newline as terminator of qualified access (treated as error)
26
+ res9 = foo.
27
+
28
+ res10 = foo.bar
29
+ ---
30
+
31
+ (module
32
+ (classProperty
33
+ (identifier)
34
+ (propertyCallExpr
35
+ (variableExpr
36
+ (identifier))
37
+ (identifier)))
38
+ (classProperty
39
+ (identifier)
40
+ (propertyCallExpr
41
+ (variableExpr
42
+ (identifier))
43
+ (identifier)))
44
+ (classProperty
45
+ (identifier)
46
+ (methodCallExpr
47
+ (variableExpr
48
+ (identifier))
49
+ (identifier)
50
+ (argumentList)))
51
+ (classProperty
52
+ (identifier)
53
+ (methodCallExpr
54
+ (variableExpr
55
+ (identifier))
56
+ (identifier)
57
+ (argumentList)))
58
+ (classProperty
59
+ (identifier)
60
+ (propertyCallExpr
61
+ (variableExpr
62
+ (identifier))
63
+ (identifier)))
64
+ (classProperty
65
+ (identifier)
66
+ (propertyCallExpr
67
+ (variableExpr
68
+ (identifier))
69
+ (identifier)))
70
+ (classProperty
71
+ (identifier)
72
+ (methodCallExpr
73
+ (variableExpr
74
+ (identifier))
75
+ (identifier)
76
+ (argumentList)))
77
+ (classProperty
78
+ (identifier)
79
+ (methodCallExpr
80
+ (variableExpr
81
+ (identifier))
82
+ (identifier)
83
+ (argumentList)))
84
+ (lineComment)
85
+ (classProperty
86
+ (identifier)
87
+ (propertyCallExpr
88
+ (variableExpr
89
+ (identifier))))
90
+ (classProperty
91
+ (identifier)
92
+ (propertyCallExpr
93
+ (variableExpr
94
+ (identifier))
95
+ (identifier))))
@@ -0,0 +1,29 @@
1
+ ================================================================================
2
+ read
3
+ ================================================================================
4
+
5
+ res1 = read("foo.txt")
6
+ res2 = read*("*.txt")
7
+ res3 = read?("foo.txt")
8
+
9
+ --------------------------------------------------------------------------------
10
+
11
+ (module
12
+ (classProperty
13
+ (identifier)
14
+ (readExpr
15
+ (parenthesizedExpr
16
+ (slStringLiteral
17
+ (slStringLiteralPart)))))
18
+ (classProperty
19
+ (identifier)
20
+ (readGlobExpr
21
+ (parenthesizedExpr
22
+ (slStringLiteral
23
+ (slStringLiteralPart)))))
24
+ (classProperty
25
+ (identifier)
26
+ (readOrNullExpr
27
+ (parenthesizedExpr
28
+ (slStringLiteral
29
+ (slStringLiteralPart))))))
@@ -0,0 +1,14 @@
1
+ ===
2
+ throw
3
+ ===
4
+
5
+ res1 = throw("Uh oh!")
6
+ ---
7
+
8
+ (module
9
+ (classProperty
10
+ (identifier)
11
+ (throwExpr
12
+ (parenthesizedExpr
13
+ (slStringLiteral
14
+ (slStringLiteralPart))))))
@@ -0,0 +1,14 @@
1
+ ===
2
+ trace
3
+ ===
4
+
5
+ res1 = trace("foo")
6
+ ---
7
+
8
+ (module
9
+ (classProperty
10
+ (identifier)
11
+ (traceExpr
12
+ (parenthesizedExpr
13
+ (slStringLiteral
14
+ (slStringLiteralPart))))))
@@ -0,0 +1,23 @@
1
+ ================================================================================
2
+ moduleHeader1
3
+ ================================================================================
4
+
5
+ @ModuleInfo { minPklVersion = "0.21.1" }
6
+
7
+ amends "foo.pkl"
8
+
9
+ --------------------------------------------------------------------------------
10
+
11
+ (module
12
+ (moduleHeader
13
+ (annotation
14
+ (qualifiedIdentifier
15
+ (identifier))
16
+ (objectBody
17
+ (objectProperty
18
+ (identifier)
19
+ (slStringLiteral
20
+ (slStringLiteralPart)))))
21
+ (extendsOrAmendsClause
22
+ (stringConstant
23
+ (slStringLiteralPart)))))
@@ -0,0 +1,29 @@
1
+ ================================================================================
2
+ moduleHeader2
3
+ ================================================================================
4
+
5
+ @ModuleInfo { minPklVersion = "0.21.1" }
6
+ module com.apple.foo
7
+
8
+ amends "foo.pkl"
9
+
10
+ --------------------------------------------------------------------------------
11
+
12
+ (module
13
+ (moduleHeader
14
+ (annotation
15
+ (qualifiedIdentifier
16
+ (identifier))
17
+ (objectBody
18
+ (objectProperty
19
+ (identifier)
20
+ (slStringLiteral
21
+ (slStringLiteralPart)))))
22
+ (moduleClause
23
+ (qualifiedIdentifier
24
+ (identifier)
25
+ (identifier)
26
+ (identifier)))
27
+ (extendsOrAmendsClause
28
+ (stringConstant
29
+ (slStringLiteralPart)))))
@@ -0,0 +1,23 @@
1
+ ================================================================================
2
+ moduleHeader3.error
3
+ ================================================================================
4
+
5
+ @ModuleInfo { minPklVersion = "0.21.1" }
6
+
7
+ import "foo.pkl"
8
+
9
+ --------------------------------------------------------------------------------
10
+
11
+ (module
12
+ (ERROR
13
+ (annotation
14
+ (qualifiedIdentifier
15
+ (identifier))
16
+ (objectBody
17
+ (objectProperty
18
+ (identifier)
19
+ (slStringLiteral
20
+ (slStringLiteralPart)))))
21
+ (identifier)
22
+ (identifier)
23
+ (identifier)))
@@ -0,0 +1,34 @@
1
+ ================================================================================
2
+ moduleHeader4
3
+ ================================================================================
4
+
5
+ @ModuleInfo { minPklVersion = "0.21.1" }
6
+ module com.apple.foo
7
+
8
+ extends "foo.pkl"
9
+
10
+ import "bar.pkl"
11
+
12
+ --------------------------------------------------------------------------------
13
+
14
+ (module
15
+ (moduleHeader
16
+ (annotation
17
+ (qualifiedIdentifier
18
+ (identifier))
19
+ (objectBody
20
+ (objectProperty
21
+ (identifier)
22
+ (slStringLiteral
23
+ (slStringLiteralPart)))))
24
+ (moduleClause
25
+ (qualifiedIdentifier
26
+ (identifier)
27
+ (identifier)
28
+ (identifier)))
29
+ (extendsOrAmendsClause
30
+ (stringConstant
31
+ (slStringLiteralPart))))
32
+ (importClause
33
+ (stringConstant
34
+ (slStringLiteralPart))))
@@ -0,0 +1,16 @@
1
+ ================================================================================
2
+ moduleHeader5
3
+ ================================================================================
4
+
5
+ import "foo.pkl"
6
+ import "bar.pkl"
7
+
8
+ --------------------------------------------------------------------------------
9
+
10
+ (module
11
+ (importClause
12
+ (stringConstant
13
+ (slStringLiteralPart)))
14
+ (importClause
15
+ (stringConstant
16
+ (slStringLiteralPart))))
@@ -0,0 +1,17 @@
1
+ ================================================================================
2
+ moduleHeader6
3
+ ================================================================================
4
+
5
+ import* "foo.pkl"
6
+ import* "bar.pkl" as bar
7
+
8
+ --------------------------------------------------------------------------------
9
+
10
+ (module
11
+ (importGlobClause
12
+ (stringConstant
13
+ (slStringLiteralPart)))
14
+ (importGlobClause
15
+ (stringConstant
16
+ (slStringLiteralPart))
17
+ (identifier)))
@@ -0,0 +1,99 @@
1
+ ================================================================================
2
+ underscores
3
+ ================================================================================
4
+
5
+ res1 = 1_000_000
6
+ res2 = 1___
7
+ res3 = 1___1
8
+ res4 = 1__000_0
9
+ res5 = -1__000_0
10
+ res6 = 0x42_ab_AB_de_12
11
+ res7 = 0x41__
12
+ res8 = 0x59__9
13
+ res9 = -0x59__9
14
+ res10 = 0b1011_0110
15
+ res11 = 0b01__10
16
+ res12 = 0b1____0
17
+ res13 = -0b1_____
18
+ res14 = 123_456_789.123_456_789
19
+ res15 = 1____.1____
20
+ res16 = 123.4_56e7
21
+ res17 = 123.4_56e-7
22
+ res18 = 123.456e1_0
23
+ res19 = 1_23.456e-1_0
24
+ res20 = .123_456_789
25
+ res21 = 0o755
26
+ res22 = 0o7_5_5__
27
+
28
+ --------------------------------------------------------------------------------
29
+
30
+ (module
31
+ (classProperty
32
+ (identifier)
33
+ (intLiteral))
34
+ (classProperty
35
+ (identifier)
36
+ (intLiteral))
37
+ (classProperty
38
+ (identifier)
39
+ (intLiteral))
40
+ (classProperty
41
+ (identifier)
42
+ (intLiteral))
43
+ (classProperty
44
+ (identifier)
45
+ (unaryExpr
46
+ (intLiteral)))
47
+ (classProperty
48
+ (identifier)
49
+ (intLiteral))
50
+ (classProperty
51
+ (identifier)
52
+ (intLiteral))
53
+ (classProperty
54
+ (identifier)
55
+ (intLiteral))
56
+ (classProperty
57
+ (identifier)
58
+ (unaryExpr
59
+ (intLiteral)))
60
+ (classProperty
61
+ (identifier)
62
+ (intLiteral))
63
+ (classProperty
64
+ (identifier)
65
+ (intLiteral))
66
+ (classProperty
67
+ (identifier)
68
+ (intLiteral))
69
+ (classProperty
70
+ (identifier)
71
+ (unaryExpr
72
+ (intLiteral)))
73
+ (classProperty
74
+ (identifier)
75
+ (floatLiteral))
76
+ (classProperty
77
+ (identifier)
78
+ (floatLiteral))
79
+ (classProperty
80
+ (identifier)
81
+ (floatLiteral))
82
+ (classProperty
83
+ (identifier)
84
+ (floatLiteral))
85
+ (classProperty
86
+ (identifier)
87
+ (floatLiteral))
88
+ (classProperty
89
+ (identifier)
90
+ (floatLiteral))
91
+ (classProperty
92
+ (identifier)
93
+ (floatLiteral))
94
+ (classProperty
95
+ (identifier)
96
+ (intLiteral))
97
+ (classProperty
98
+ (identifier)
99
+ (intLiteral)))
@@ -0,0 +1,38 @@
1
+ ================================================================================
2
+ objectAmendChain
3
+ ================================================================================
4
+
5
+ res {
6
+ foo = 1
7
+ } {
8
+ bar = 2
9
+ baz {
10
+ biz = 3
11
+ } {
12
+ buz = 4
13
+ }
14
+ }
15
+
16
+ --------------------------------------------------------------------------------
17
+
18
+ (module
19
+ (classProperty
20
+ (identifier)
21
+ (objectBody
22
+ (objectProperty
23
+ (identifier)
24
+ (intLiteral)))
25
+ (objectBody
26
+ (objectProperty
27
+ (identifier)
28
+ (intLiteral))
29
+ (objectProperty
30
+ (identifier)
31
+ (objectBody
32
+ (objectProperty
33
+ (identifier)
34
+ (intLiteral)))
35
+ (objectBody
36
+ (objectProperty
37
+ (identifier)
38
+ (intLiteral)))))))
@@ -0,0 +1,51 @@
1
+ ====
2
+ objectElementsWithParens
3
+ ====
4
+
5
+ res13 {
6
+ foo
7
+ foo(bar)
8
+ bar
9
+ (baz)
10
+ qux
11
+ (quux) {
12
+ 1
13
+ 2
14
+ }
15
+ }
16
+
17
+ ----
18
+
19
+ (module
20
+ (classProperty
21
+ (identifier)
22
+ (objectBody
23
+ (objectElement
24
+ (variableExpr
25
+ (identifier)))
26
+ (objectElement
27
+ (methodCallExpr
28
+ (identifier)
29
+ (argumentList
30
+ (variableExpr
31
+ (identifier)))))
32
+ (objectElement
33
+ (variableExpr
34
+ (identifier)))
35
+ (objectElement
36
+ (parenthesizedExpr
37
+ (variableExpr
38
+ (identifier))))
39
+ (objectElement
40
+ (variableExpr
41
+ (identifier)))
42
+ (objectElement
43
+ (objectLiteral
44
+ (parenthesizedExpr
45
+ (variableExpr
46
+ (identifier)))
47
+ (objectBody
48
+ (objectElement
49
+ (intLiteral))
50
+ (objectElement
51
+ (intLiteral))))))))
@@ -0,0 +1,53 @@
1
+ ===
2
+ objectGenerator
3
+ ===
4
+
5
+ foo {
6
+ for (bar in baz) {
7
+ bar
8
+ }
9
+
10
+ for (foo, bar in baz) {
11
+ bar
12
+ }
13
+
14
+ when (corge == null) {
15
+ qux = 15
16
+ }
17
+ }
18
+
19
+ ---
20
+
21
+ (module
22
+ (classProperty
23
+ (identifier)
24
+ (objectBody
25
+ (forGenerator
26
+ (typedIdentifier
27
+ (identifier))
28
+ (variableExpr
29
+ (identifier))
30
+ (objectBody
31
+ (objectElement
32
+ (variableExpr
33
+ (identifier)))))
34
+ (forGenerator
35
+ (typedIdentifier
36
+ (identifier))
37
+ (typedIdentifier
38
+ (identifier))
39
+ (variableExpr
40
+ (identifier))
41
+ (objectBody
42
+ (objectElement
43
+ (variableExpr
44
+ (identifier)))))
45
+ (whenGenerator
46
+ (binaryExpr
47
+ (variableExpr
48
+ (identifier))
49
+ (nullLiteral))
50
+ (objectBody
51
+ (objectProperty
52
+ (identifier)
53
+ (intLiteral)))))))