tree-sitter-kdl 1.0.3 → 1.1.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.
@@ -1,12 +1,11 @@
1
1
  name: Publish
2
2
 
3
3
  on:
4
- push:
5
- branches:
6
- - master
7
- tags:
8
- - "v*"
9
- workflow_dispatch:
4
+ pull_request:
5
+ types: [closed]
6
+
7
+ permissions:
8
+ contents: write
10
9
 
11
10
  jobs:
12
11
  build:
@@ -19,33 +18,64 @@ jobs:
19
18
  - run: npm install
20
19
  - run: npm test
21
20
 
22
- publish-npm:
23
- if: startsWith(github.ref, 'refs/tags/v')
21
+ publish:
22
+ if: github.event.pull_request.merged && startsWith(github.event.pull_request.title, 'chore(master):')
24
23
  needs: build
25
24
  runs-on: ubuntu-latest
26
-
27
25
  steps:
28
26
  - uses: actions/checkout@v3
29
- - uses: actions/setup-node@v3
27
+ with:
28
+ ref: ${{ github.event.pull_request.merge_commit_sha }}
29
+ token: ${{ secrets.GITHUB_TOKEN }}
30
+ - name: Extract version
31
+ id: extract_version
32
+ run: |
33
+ PR_TITLE="${{ github.event.pull_request.title }}"
34
+ VERSION=$(echo "$PR_TITLE" | grep -oP '(?<=release ).*$')
35
+ echo "::set-output name=version::$VERSION"
36
+ - name: Update versions
37
+ run: |
38
+ version="${{ steps.extract_version.outputs.version }}"
39
+ repo_name="${{ github.repository }}"
40
+ repo_name="${repo_name##*/}"
41
+
42
+ git config user.name github-actions[bot]
43
+ git config user.email github-actions[bot]@users.noreply.github.com
44
+ git fetch origin master
45
+ git checkout master
46
+
47
+ sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$version\"/g" package.json
48
+ sed -i "s/version = \"[^\"]*\"/version = \"$version\"/g" Cargo.toml
49
+ sed -i "s/$repo_name = \"[^\"]*\"/$repo_name = \"$version\"/g" bindings/rust/README.md
50
+
51
+ git add package.json Cargo.toml bindings/rust/README.md
52
+ git commit -m "chore(manifests): bump version to $version"
53
+ git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:master
54
+ - name: Setup Node.js
55
+ uses: actions/setup-node@v3
30
56
  with:
31
57
  node-version: 16
32
58
  registry-url: https://registry.npmjs.org/
33
- - run: npm install
34
59
  - run: npm publish
35
60
  env:
36
61
  NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
37
-
38
- publish-crates:
39
- if: startsWith(github.ref, 'refs/tags/v')
40
- needs: build
41
- runs-on: ubuntu-latest
42
- steps:
43
- - uses: actions/checkout@v3
44
- - uses: actions-rs/toolchain@v1
62
+ - name: Setup Rust
63
+ uses: actions-rs/toolchain@v1
45
64
  with:
46
65
  profile: minimal
47
66
  toolchain: stable
48
67
  override: true
49
- - uses: katyo/publish-crates@v2
68
+ - name: Publish to Crates.io
69
+ uses: katyo/publish-crates@v2
50
70
  with:
51
71
  registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
72
+ - uses: actions/checkout@v3
73
+ - name: Tag stable versions
74
+ run: |
75
+ git config user.name github-actions[bot]
76
+ git config user.email github-actions[bot]@users.noreply.github.com
77
+ git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git"
78
+ git tag -d stable || true
79
+ git push origin :stable || true
80
+ git tag -a stable -m "Last Stable Release"
81
+ git push origin stable
@@ -0,0 +1,35 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write
11
+ pull-requests: write
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - uses: actions/setup-node@v3
19
+ with:
20
+ node-version: 16
21
+ - run: npm install
22
+ - run: npm test
23
+
24
+ release:
25
+ name: release
26
+ if: ${{ github.ref == 'refs/heads/master' }}
27
+ needs:
28
+ - build
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - uses: google-github-actions/release-please-action@v3
32
+ id: release
33
+ with:
34
+ release-type: simple
35
+ package-name: tree-sitter-kdl
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## [1.1.0](https://github.com/amaanq/tree-sitter-kdl/compare/v1.0.3...v1.1.0) (2023-05-13)
4
+
5
+
6
+ ### Features
7
+
8
+ * add release action ([245f6e0](https://github.com/amaanq/tree-sitter-kdl/commit/245f6e0ba4f7a5c81ca0e1075dfc875ff9f4edd0))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add lint script to package.json ([e36f054](https://github.com/amaanq/tree-sitter-kdl/commit/e36f054a60c4d9e5ae29567d439fdb8790b53b30))
14
+ * rename EOF to _EOF to avoid conflicts with stdio.h ([d118f93](https://github.com/amaanq/tree-sitter-kdl/commit/d118f9376ef4f0461975289302fe74a28f073876))
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "tree-sitter-kdl"
3
3
  description = "KDL grammar for tree-sitter"
4
- version = "1.0.3"
4
+ version = "1.1.0"
5
5
  authors = [
6
6
  "Amaan Qureshi <amaanq12@gmail.com>",
7
7
  "Andrew Hlynskyi <ahlincq@gmail.com>",
@@ -21,7 +21,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
21
21
  path = "bindings/rust/lib.rs"
22
22
 
23
23
  [dependencies]
24
- tree-sitter = "~0.20.3"
24
+ tree-sitter = "~0.20.10"
25
25
 
26
26
  [build-dependencies]
27
27
  cc = "1.0"
@@ -11,18 +11,18 @@ namespace {
11
11
  NAN_METHOD(New) {}
12
12
 
13
13
  void Init(Local<Object> exports, Local<Object> module) {
14
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15
- tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
-
18
- Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
- Local<Object> instance =
20
- constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
21
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_kdl());
22
-
23
- Nan::Set(instance, Nan::New("name").ToLocalChecked(),
24
- Nan::New("kdl").ToLocalChecked());
25
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
14
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15
+ tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
+
18
+ Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
+ Local<Object> instance =
20
+ constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
21
+ Nan::SetInternalFieldPointer(instance, 0, tree_sitter_kdl());
22
+
23
+ Nan::Set(instance, Nan::New("name").ToLocalChecked(),
24
+ Nan::New("kdl").ToLocalChecked());
25
+ Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
26
26
  }
27
27
 
28
28
  NODE_MODULE(tree_sitter_kdl_binding, Init)
@@ -8,8 +8,8 @@ way.)
8
8
 
9
9
  ```toml
10
10
  [dependencies]
11
- tree-sitter = "~0.20.3"
12
- tree-sitter-kdl = "1.0.2"
11
+ tree-sitter = "~0.20.10"
12
+ tree-sitter-kdl = "1.1.0"
13
13
  ```
14
14
 
15
15
  Typically, you will use the [language][language func] function to add this
@@ -17,9 +17,12 @@ grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
17
17
 
18
18
  ```rust
19
19
  let code = r#"
20
- fn double(x: i32) -> i32 {
21
- x * 2
22
- }
20
+ contents {
21
+ section "First section" {
22
+ paragraph "This is the first paragraph"
23
+ paragraph "This is the second paragraph"
24
+ }
25
+ }
23
26
  "#;
24
27
  let mut parser = Parser::new();
25
28
  parser.set_language(tree_sitter_kdl::language()).expect("Error loading KDL grammar");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-kdl",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "KDL grammar for tree-sitter",
5
5
  "main": "bindings/node",
6
6
  "keywords": [
@@ -21,20 +21,22 @@
21
21
  "nan": "^2.17.0"
22
22
  },
23
23
  "devDependencies": {
24
- "eslint": "^8.32.0",
24
+ "eslint": "^8.40.0",
25
25
  "eslint-config-google": "^0.14.0",
26
- "tree-sitter-cli": "^0.20.7"
26
+ "tree-sitter-cli": "^0.20.8"
27
27
  },
28
28
  "repository": "https://github.com/amaanq/tree-sitter-kdl",
29
29
  "scripts": {
30
30
  "build": "tree-sitter generate && node-gyp build",
31
- "test": "tree-sitter test && script/parse-examples",
31
+ "lint": "eslint grammar.js",
32
32
  "parse": "tree-sitter parse",
33
+ "test": "tree-sitter test && script/parse-examples",
33
34
  "test-windows": "tree-sitter test"
34
35
  },
35
36
  "tree-sitter": [
36
37
  {
37
38
  "scope": "source.kdl",
39
+ "injection-regex": "kdl",
38
40
  "file-types": [
39
41
  "kdl"
40
42
  ],
package/src/scanner.c CHANGED
@@ -2,7 +2,7 @@
2
2
  #include "wctype.h"
3
3
  #include <ctype.h>
4
4
 
5
- enum { EOF, MULTI_LINE_COMMENT };
5
+ enum { _EOF, MULTI_LINE_COMMENT };
6
6
 
7
7
  void *tree_sitter_kdl_external_scanner_create() { return NULL; }
8
8
 
@@ -10,67 +10,68 @@ void tree_sitter_kdl_external_scanner_destroy(void *payload) {}
10
10
 
11
11
  unsigned tree_sitter_kdl_external_scanner_serialize(void *payload,
12
12
  char *buffer) {
13
- return 0;
13
+ return 0;
14
14
  }
15
15
 
16
- void tree_sitter_kdl_external_scanner_deserialize(void *payload,
16
+ void tree_sitter_kdl_external_scanner_deserialize(void *payload,
17
17
  const char *buffer,
18
- unsigned length) {}
18
+ unsigned length) {}
19
19
 
20
20
  static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
21
21
 
22
22
  bool tree_sitter_kdl_external_scanner_scan(void *payload, TSLexer *lexer,
23
23
  const bool *valid_symbols) {
24
- // check for End-of-file
25
- if (valid_symbols[EOF] && lexer->lookahead == 0) {
26
- lexer->result_symbol = EOF;
27
- advance(lexer);
28
- return true;
29
- }
30
-
31
- // multi-line-comment := '/*' commented-block
32
- if (lexer->lookahead == '/') {
33
- advance(lexer);
34
- if (lexer->lookahead != '*')
35
- return false;
36
- advance(lexer);
24
+ // check for End-of-file
25
+ if (valid_symbols[_EOF] && lexer->lookahead == 0) {
26
+ lexer->result_symbol = _EOF;
27
+ advance(lexer);
28
+ return true;
29
+ }
37
30
 
38
- bool after_star = false;
39
- unsigned nesting_depth = 1;
40
- // commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+) commented-block
41
- for (;;) {
42
- switch (lexer->lookahead) {
43
- case '\0':
44
- return false;
45
- case '*':
31
+ // multi-line-comment := '/*' commented-block
32
+ if (lexer->lookahead == '/') {
46
33
  advance(lexer);
47
- after_star = true;
48
- break;
49
- case '/':
50
- if (after_star) {
51
- advance(lexer);
52
- after_star = false;
53
- nesting_depth--;
54
- if (nesting_depth == 0) {
55
- lexer->result_symbol = MULTI_LINE_COMMENT;
56
- return true;
57
- }
58
- } else {
59
- advance(lexer);
60
- after_star = false;
61
- if (lexer->lookahead == '*') {
62
- nesting_depth++;
63
- advance(lexer);
64
- }
65
- }
66
- break;
67
- default:
34
+ if (lexer->lookahead != '*')
35
+ return false;
68
36
  advance(lexer);
69
- after_star = false;
70
- break;
71
- }
37
+
38
+ bool after_star = false;
39
+ unsigned nesting_depth = 1;
40
+ // commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+)
41
+ // commented-block
42
+ for (;;) {
43
+ switch (lexer->lookahead) {
44
+ case '\0':
45
+ return false;
46
+ case '*':
47
+ advance(lexer);
48
+ after_star = true;
49
+ break;
50
+ case '/':
51
+ if (after_star) {
52
+ advance(lexer);
53
+ after_star = false;
54
+ nesting_depth--;
55
+ if (nesting_depth == 0) {
56
+ lexer->result_symbol = MULTI_LINE_COMMENT;
57
+ return true;
58
+ }
59
+ } else {
60
+ advance(lexer);
61
+ after_star = false;
62
+ if (lexer->lookahead == '*') {
63
+ nesting_depth++;
64
+ advance(lexer);
65
+ }
66
+ }
67
+ break;
68
+ default:
69
+ advance(lexer);
70
+ after_star = false;
71
+ break;
72
+ }
73
+ }
72
74
  }
73
- }
74
75
 
75
- return false;
76
+ return false;
76
77
  }