tree-sitter-beancount 2.0.0 → 2.1.2

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/.clang-format ADDED
@@ -0,0 +1,20 @@
1
+ ---
2
+ BasedOnStyle: LLVM
3
+ IndentWidth: 4
4
+ ---
5
+ Language: Cpp
6
+ # Force pointers to the type for C.
7
+ DerivePointerAlignment: false
8
+ PointerAlignment: Right
9
+
10
+ # Short functions should not be on a single line, unless empty
11
+ AllowShortFunctionsOnASingleLine: Empty
12
+
13
+ # It makes more sense this way
14
+ BreakBeforeBinaryOperators: All
15
+ BreakBeforeTernaryOperators: true
16
+
17
+ # Aesthetic
18
+ AlignOperands: AlignAfterOperator
19
+ BinPackParameters: false
20
+ ---
package/.envrc ADDED
@@ -0,0 +1 @@
1
+ use flake
@@ -0,0 +1,30 @@
1
+ name: cicd
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ branches:
7
+ - '**:**'
8
+
9
+ jobs:
10
+ build:
11
+ name: build
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v2
16
+
17
+ - name: Setup Node
18
+ uses: actions/setup-node@v2-beta
19
+ with:
20
+ node-version: '16'
21
+
22
+ - name: Display Node versions
23
+ run: |
24
+ node --version
25
+ npm --version
26
+ - name: Install dependencies
27
+ run: npm install
28
+
29
+ - name: Test corpus & parse examples
30
+ run: npm test
@@ -0,0 +1,72 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ branches: [master]
5
+
6
+ jobs:
7
+ release-please:
8
+ runs-on: ubuntu-latest
9
+ outputs:
10
+ release_created: ${{ steps.release.outputs.release_created }}
11
+ steps:
12
+ - uses: google-github-actions/release-please-action@v3
13
+ id: release
14
+ with:
15
+ release-type: node
16
+ package-name: tree-sitter-beancount
17
+ bump-minor-pre-major: true
18
+ bump-patch-for-minor-pre-major: true
19
+ extra-files: |
20
+ Cargo.toml
21
+
22
+ publish_cargo:
23
+ name: Publish Crate
24
+ runs-on: ubuntu-latest
25
+ needs: [release-please]
26
+ if: needs.release-please.outputs.release_created
27
+ steps:
28
+ - name: Installing Rust toolchain
29
+ uses: actions-rs/toolchain@v1
30
+ with:
31
+ toolchain: stable
32
+ profile: minimal
33
+ override: true
34
+ - name: Checking out sources
35
+ uses: actions/checkout@v1
36
+ - name: Cache Cargo
37
+ uses: actions/cache@v2
38
+ with:
39
+ path: |
40
+ ~/.cargo/registry
41
+ ~/.cargo/git
42
+ target
43
+ key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
44
+ - name: Installing dependencies
45
+ run: |
46
+ sudo apt-get update
47
+ sudo apt-get install -y -qq pkg-config libssl-dev
48
+ - uses: actions-rs/cargo@v1
49
+ with:
50
+ command: publish
51
+ args: --token ${{ secrets.CARGO_API_KEY }} --allow-dirty
52
+
53
+ publish_npm:
54
+ name: Publish npm
55
+ runs-on: ubuntu-latest
56
+ needs: [release-please]
57
+ if: needs.release-please.outputs.release_created
58
+ steps:
59
+ - name: Checking out sources
60
+ uses: actions/checkout@v1
61
+ - name: Set up Node
62
+ uses: actions/setup-node@v2
63
+ with:
64
+ node-version: '16'
65
+ registry-url: 'https://registry.npmjs.org'
66
+ cache: 'npm'
67
+ - name: Install dependencies
68
+ run: npm install
69
+ - name: Publish to npm
70
+ run: npm publish
71
+ env:
72
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ## [2.1.2](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.1...v2.1.2) (2023-01-28)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * cleanup grammar upon feedback ([015e228](https://github.com/polarmutex/tree-sitter-beancount/commit/015e228ca684bbba5ee3e457020cf9c5d1d20afc))
9
+ * npm publish ([4cbd1f0](https://github.com/polarmutex/tree-sitter-beancount/commit/4cbd1f09cd07c1f1fabf867c2cf354f9da53cc4c))
10
+
11
+ ## [2.1.1](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.0...v2.1.1) (2022-07-02)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * changelog for prior versions ([8197699](https://github.com/polarmutex/tree-sitter-beancount/commit/8197699421b9787a3940b097ced363b9a4ba2f13))
17
+ * npm publish ([a105058](https://github.com/polarmutex/tree-sitter-beancount/commit/a1050584340a2375b6b480ba9e9691aebb9d33d5))
18
+ * rust binding build error ([bfbfa12](https://github.com/polarmutex/tree-sitter-beancount/commit/bfbfa12da0e1c7e598768c0f46f90bbe179d4be5))
19
+
20
+ ## [2.1.0](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.0.0...v2.1.0) (2022-06-28)
21
+
22
+
23
+ ### Features
24
+
25
+ * support org sections ([1b06224](https://github.com/polarmutex/tree-sitter-beancount/commit/1b06224c446f49586b0952de795e1562c6d76e3b))
26
+
27
+ ## [2.0.0] (2021-11-11)
28
+
29
+ ### Features
30
+
31
+ * Initial version of grammar
package/Cargo.lock ADDED
@@ -0,0 +1,59 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.20"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "cc"
16
+ version = "1.0.78"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
19
+
20
+ [[package]]
21
+ name = "memchr"
22
+ version = "2.5.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
25
+
26
+ [[package]]
27
+ name = "regex"
28
+ version = "1.7.1"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
31
+ dependencies = [
32
+ "aho-corasick",
33
+ "memchr",
34
+ "regex-syntax",
35
+ ]
36
+
37
+ [[package]]
38
+ name = "regex-syntax"
39
+ version = "0.6.28"
40
+ source = "registry+https://github.com/rust-lang/crates.io-index"
41
+ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
42
+
43
+ [[package]]
44
+ name = "tree-sitter"
45
+ version = "0.20.9"
46
+ source = "registry+https://github.com/rust-lang/crates.io-index"
47
+ checksum = "d4423c784fe11398ca91e505cdc71356b07b1a924fc8735cfab5333afe3e18bc"
48
+ dependencies = [
49
+ "cc",
50
+ "regex",
51
+ ]
52
+
53
+ [[package]]
54
+ name = "tree-sitter-beancount"
55
+ version = "2.1.1"
56
+ dependencies = [
57
+ "cc",
58
+ "tree-sitter",
59
+ ]
package/Cargo.toml ADDED
@@ -0,0 +1,26 @@
1
+ [package]
2
+ name = "tree-sitter-beancount"
3
+ description = "beancount grammar for the tree-sitter parsing library"
4
+ version = "2.1.2" # {x-release-please-version}
5
+ keywords = ["incremental", "parsing", "beancount", "tree-sitter"]
6
+ categories = ["parsing", "text-editors"]
7
+ repository = "https://github.com/polarmutex/tree-sitter-beancount"
8
+ edition = "2018"
9
+ license = "MIT"
10
+
11
+ build = "bindings/rust/build.rs"
12
+ include = [
13
+ "bindings/rust/*",
14
+ "grammar.js",
15
+ "queries/*",
16
+ "src/*",
17
+ ]
18
+
19
+ [lib]
20
+ path = "bindings/rust/lib.rs"
21
+
22
+ [dependencies]
23
+ tree-sitter = "~0.20.0"
24
+
25
+ [build-dependencies]
26
+ cc = "1.0"
package/README.md CHANGED
@@ -1,2 +1,6 @@
1
1
  # tree-sitter-beancount
2
- a tree-sitter parser for the beancount syntax
2
+ a [tree-sitter](https://github.com/tree-sitter/tree-sitter) parser for the [beancount](https://github.com/beancount/beancount) syntax
3
+
4
+ ## Reference
5
+ [Beancount syntax](https://beancount.github.io/docs/beancount_language_syntax.html)
6
+ [tree-sitter](https://tree-sitter.github.io)
package/binding.gyp CHANGED
@@ -7,8 +7,9 @@
7
7
  "src"
8
8
  ],
9
9
  "sources": [
10
+ "bindings/node/binding.cc",
10
11
  "src/parser.c",
11
- "src/binding.cc"
12
+ # If your language uses an external scanner, add it here.
12
13
  ],
13
14
  "cflags_c": [
14
15
  "-std=c99",
File without changes
@@ -0,0 +1,19 @@
1
+ try {
2
+ module.exports = require("../../build/Release/tree_sitter_beancount_binding");
3
+ } catch (error1) {
4
+ if (error1.code !== 'MODULE_NOT_FOUND') {
5
+ throw error1;
6
+ }
7
+ try {
8
+ module.exports = require("../../build/Debug/tree_sitter_beancount_binding");
9
+ } catch (error2) {
10
+ if (error2.code !== 'MODULE_NOT_FOUND') {
11
+ throw error2;
12
+ }
13
+ throw error1
14
+ }
15
+ }
16
+
17
+ try {
18
+ module.exports.nodeTypeInfo = require("../../src/node-types.json");
19
+ } catch (_) {}
@@ -0,0 +1,38 @@
1
+ fn main() {
2
+ let src_dir = std::path::Path::new("src");
3
+
4
+ let mut c_config = cc::Build::new();
5
+ c_config.include(&src_dir);
6
+ c_config
7
+ .flag_if_supported("-Wno-unused-parameter")
8
+ .flag_if_supported("-Wno-unused-but-set-variable")
9
+ .flag_if_supported("-Wno-trigraphs");
10
+ let parser_path = src_dir.join("parser.c");
11
+ c_config.file(&parser_path);
12
+
13
+ // If your language uses an external scanner written in C,
14
+ // then include this block of code:
15
+
16
+ /*
17
+ let scanner_path = src_dir.join("scanner.c");
18
+ c_config.file(&scanner_path);
19
+ println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
20
+ */
21
+
22
+ c_config.compile("parser");
23
+ println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
24
+
25
+ // If your language uses an external scanner written in C++,
26
+ // then include this block of code:
27
+
28
+ let mut cpp_config = cc::Build::new();
29
+ cpp_config.cpp(true);
30
+ cpp_config.include(&src_dir);
31
+ cpp_config
32
+ .flag_if_supported("-Wno-unused-parameter")
33
+ .flag_if_supported("-Wno-unused-but-set-variable");
34
+ let scanner_path = src_dir.join("scanner.cc");
35
+ cpp_config.file(&scanner_path);
36
+ cpp_config.compile("scanner");
37
+ println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
38
+ }
@@ -0,0 +1,52 @@
1
+ //! This crate provides beancount language support for the [tree-sitter][] parsing library.
2
+ //!
3
+ //! Typically, you will use the [language][language func] function to add this language to a
4
+ //! tree-sitter [Parser][], and then use the parser to parse some code:
5
+ //!
6
+ //! ```
7
+ //! let code = "";
8
+ //! let mut parser = tree_sitter::Parser::new();
9
+ //! parser.set_language(tree_sitter_beancount::language()).expect("Error loading beancount grammar");
10
+ //! let tree = parser.parse(code, None).unwrap();
11
+ //! ```
12
+ //!
13
+ //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14
+ //! [language func]: fn.language.html
15
+ //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16
+ //! [tree-sitter]: https://tree-sitter.github.io/
17
+
18
+ use tree_sitter::Language;
19
+
20
+ extern "C" {
21
+ fn tree_sitter_beancount() -> Language;
22
+ }
23
+
24
+ /// Get the tree-sitter [Language][] for this grammar.
25
+ ///
26
+ /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
27
+ pub fn language() -> Language {
28
+ unsafe { tree_sitter_beancount() }
29
+ }
30
+
31
+ /// The content of the [`node-types.json`][] file for this grammar.
32
+ ///
33
+ /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
34
+ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
35
+
36
+ // Uncomment these to include any queries that this grammar contains
37
+
38
+ // pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
39
+ // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
40
+ // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
41
+ // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
42
+
43
+ #[cfg(test)]
44
+ mod tests {
45
+ #[test]
46
+ fn test_can_load_grammar() {
47
+ let mut parser = tree_sitter::Parser::new();
48
+ parser
49
+ .set_language(super::language())
50
+ .expect("Error loading beancount language");
51
+ }
52
+ }
package/flake.lock ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "nodes": {
3
+ "flake-utils": {
4
+ "locked": {
5
+ "lastModified": 1656065134,
6
+ "narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
7
+ "owner": "numtide",
8
+ "repo": "flake-utils",
9
+ "rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
10
+ "type": "github"
11
+ },
12
+ "original": {
13
+ "owner": "numtide",
14
+ "repo": "flake-utils",
15
+ "type": "github"
16
+ }
17
+ },
18
+ "nixpkgs": {
19
+ "locked": {
20
+ "lastModified": 1656239181,
21
+ "narHash": "sha256-wW1xRFBn376yGloXZ4QzBE4hjipMawpV18Lshd9QSPw=",
22
+ "owner": "NixOS",
23
+ "repo": "nixpkgs",
24
+ "rev": "f2537a505d45c31fe5d9c27ea9829b6f4c4e6ac5",
25
+ "type": "github"
26
+ },
27
+ "original": {
28
+ "owner": "NixOS",
29
+ "ref": "nixos-unstable",
30
+ "repo": "nixpkgs",
31
+ "type": "github"
32
+ }
33
+ },
34
+ "pre-commit-hooks": {
35
+ "inputs": {
36
+ "flake-utils": [
37
+ "flake-utils"
38
+ ],
39
+ "nixpkgs": [
40
+ "nixpkgs"
41
+ ]
42
+ },
43
+ "locked": {
44
+ "lastModified": 1656169028,
45
+ "narHash": "sha256-y9DRauokIeVHM7d29lwT8A+0YoGUBXV3H0VErxQeA8s=",
46
+ "owner": "cachix",
47
+ "repo": "pre-commit-hooks.nix",
48
+ "rev": "db3bd555d3a3ceab208bed48f983ccaa6a71a25e",
49
+ "type": "github"
50
+ },
51
+ "original": {
52
+ "owner": "cachix",
53
+ "repo": "pre-commit-hooks.nix",
54
+ "type": "github"
55
+ }
56
+ },
57
+ "root": {
58
+ "inputs": {
59
+ "flake-utils": "flake-utils",
60
+ "nixpkgs": "nixpkgs",
61
+ "pre-commit-hooks": "pre-commit-hooks"
62
+ }
63
+ }
64
+ },
65
+ "root": "root",
66
+ "version": 7
67
+ }
package/flake.nix ADDED
@@ -0,0 +1,123 @@
1
+ {
2
+ inputs = {
3
+ flake-utils.url = "github:numtide/flake-utils";
4
+ nixpkgs = {
5
+ url = "github:NixOS/nixpkgs/nixos-unstable";
6
+ };
7
+ pre-commit-hooks = {
8
+ url = "github:cachix/pre-commit-hooks.nix";
9
+ inputs = {
10
+ flake-utils.follows = "flake-utils";
11
+ nixpkgs.follows = "nixpkgs";
12
+ };
13
+ };
14
+ };
15
+
16
+ outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
17
+ { } //
18
+ flake-utils.lib.eachDefaultSystem
19
+ (
20
+ system:
21
+ let
22
+ pkgs = import nixpkgs {
23
+ inherit system;
24
+ overlays = [ self.overlays.default ];
25
+ };
26
+
27
+ tree-sitter-env = pkgs.stdenv.mkDerivation {
28
+ name = "tree-sitter-env";
29
+
30
+ nativeBuildInputs = with pkgs; [
31
+ makeWrapper
32
+ ];
33
+
34
+ dontUnpack = true;
35
+
36
+ dontBuild = true;
37
+
38
+ installPhase = ''
39
+ mkdir -p $out/bin
40
+ makeWrapper \
41
+ ${pkgs.tree-sitter}/bin/tree-sitter \
42
+ $out/bin/tree-sitter \
43
+ --prefix PATH : "${with pkgs; lib.makeBinPath [stdenv.cc nodejs]}"
44
+ '';
45
+ };
46
+
47
+ in
48
+ rec {
49
+ checks = {
50
+ pre-commit = pre-commit-hooks.lib.${system}.run {
51
+ src = ./.;
52
+
53
+ hooks = {
54
+ clang-format = {
55
+ enable = true;
56
+ name = "clang-format";
57
+ entry = "${pkgs.clang-tools}/bin/clang-format -style=file -i";
58
+ types = [ "text" "c" ];
59
+ # I don't care for generated files' formatting
60
+ excludes = [ "src/parser.c" "src/tree_sitter/parser.h" ];
61
+ language = "system";
62
+ };
63
+
64
+ nixpkgs-fmt = {
65
+ enable = true;
66
+ };
67
+
68
+ tree-sitter = {
69
+ enable = true;
70
+ name = "tree-sitter tests";
71
+ entry = "${tree-sitter-env}/bin/tree-sitter test";
72
+ pass_filenames = false;
73
+ };
74
+
75
+ tree-sitter-files = {
76
+ enable = true;
77
+ name = "tree-sitter generated files";
78
+ entry = "${tree-sitter-env}/bin/tree-sitter generate";
79
+ pass_filenames = false;
80
+ };
81
+ };
82
+ };
83
+ };
84
+
85
+ devShells = {
86
+ default = pkgs.mkShell {
87
+ nativeBuildInputs = with pkgs; [
88
+ nodejs-16_x
89
+ python39
90
+ nodePackages.typescript
91
+ rustc
92
+ cargo
93
+ rustfmt
94
+ clippy
95
+ (tree-sitter.override { webUISupport = true; })
96
+ ];
97
+
98
+ inherit (checks.pre-commit) shellHook;
99
+ };
100
+ };
101
+
102
+ packages = {
103
+ default = packages.tree-sitter-beancount;
104
+
105
+ inherit (pkgs.tree-sitter.passthru.builtGrammars) tree-sitter-beancount;
106
+
107
+ inherit (pkgs) tree-sitter;
108
+ };
109
+ }
110
+ ) // {
111
+ overlays = {
112
+ default = final: prev: {
113
+ tree-sitter = prev.tree-sitter.override {
114
+ extraGrammars = {
115
+ tree-sitter-beancount = {
116
+ src = ./.;
117
+ };
118
+ };
119
+ };
120
+ };
121
+ };
122
+ };
123
+ }