beancount-format 0.1.17__tar.gz → 0.1.18__tar.gz

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 (61) hide show
  1. {beancount_format-0.1.17 → beancount_format-0.1.18}/Cargo.lock +4 -4
  2. {beancount_format-0.1.17 → beancount_format-0.1.18}/Cargo.toml +1 -1
  3. {beancount_format-0.1.17 → beancount_format-0.1.18}/PKG-INFO +1 -1
  4. beancount_format-0.1.18/patches/tree-sitter-language/Cargo.toml +19 -0
  5. beancount_format-0.1.18/patches/tree-sitter-language/LICENSE +21 -0
  6. beancount_format-0.1.18/patches/tree-sitter-language/README.md +4 -0
  7. beancount_format-0.1.18/patches/tree-sitter-language/build.rs +13 -0
  8. beancount_format-0.1.18/patches/tree-sitter-language/src/language.rs +23 -0
  9. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/assert.h +14 -0
  10. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/ctype.h +8 -0
  11. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/endian.h +12 -0
  12. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/inttypes.h +8 -0
  13. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/stdint.h +46 -0
  14. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/stdio.h +36 -0
  15. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/stdlib.h +15 -0
  16. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/string.h +18 -0
  17. beancount_format-0.1.18/patches/tree-sitter-language/wasm/include/wctype.h +168 -0
  18. beancount_format-0.1.18/patches/tree-sitter-language/wasm/src/stdio.c +299 -0
  19. beancount_format-0.1.18/patches/tree-sitter-language/wasm/src/stdlib.c +161 -0
  20. beancount_format-0.1.18/patches/tree-sitter-language/wasm/src/string.c +66 -0
  21. {beancount_format-0.1.17 → beancount_format-0.1.18}/pyproject.toml +2 -1
  22. {beancount_format-0.1.17 → beancount_format-0.1.18}/LICENSE +0 -0
  23. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/Cargo.toml +0 -0
  24. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/configuration/configuration.rs +0 -0
  25. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/configuration/mod.rs +0 -0
  26. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/configuration/new_line_kind.rs +0 -0
  27. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/format.rs +0 -0
  28. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/lib.rs +0 -0
  29. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/src/parse.rs +0 -0
  30. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/applies_configured_crlf_newlines.config.json +0 -0
  31. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/applies_configured_crlf_newlines.expected.bean +0 -0
  32. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/applies_configured_crlf_newlines.input.bean +0 -0
  33. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/caps_blank_lines_between_directives.expected.bean +0 -0
  34. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/caps_blank_lines_between_directives.input.bean +0 -0
  35. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_all_directives.config.json +0 -0
  36. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_all_directives.expected.bean +0 -0
  37. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_all_directives.input.bean +0 -0
  38. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_transaction_preserves_postings.expected.bean +0 -0
  39. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_transaction_preserves_postings.input.bean +0 -0
  40. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_without_changes_returns_none.expected.bean +0 -0
  41. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/formats_without_changes_returns_none.input.bean +0 -0
  42. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/normalizes_tabs_and_trailing_spaces.expected.bean +0 -0
  43. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/normalizes_tabs_and_trailing_spaces.input.bean +0 -0
  44. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve-meta.expected.bean +0 -0
  45. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve-meta.input.bean +0 -0
  46. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve_comments.expected.bean +0 -0
  47. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve_comments.input.bean +0 -0
  48. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve_file_path_header.expected.bean +0 -0
  49. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/preserve_file_path_header.input.bean +0 -0
  50. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/support_input_without_eol.expected.bean +0 -0
  51. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format-and-check/support_input_without_eol.input.bean +0 -0
  52. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter/tests/format_cases.rs +0 -0
  53. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-cli/Cargo.toml +0 -0
  54. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-cli/src/lib.rs +0 -0
  55. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-cli/src/main.rs +0 -0
  56. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-cli/tests/cli_e2e.rs +0 -0
  57. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-py/Cargo.toml +0 -0
  58. {beancount_format-0.1.17 → beancount_format-0.1.18}/crates/beancount-formatter-py/src/lib.rs +0 -0
  59. {beancount_format-0.1.17 → beancount_format-0.1.18}/python/README.md +0 -0
  60. {beancount_format-0.1.17 → beancount_format-0.1.18}/python/src/beancount_format/__init__.py +0 -0
  61. {beancount_format-0.1.17 → beancount_format-0.1.18}/python/src/beancount_format/beancount_format.pyi +0 -0
@@ -128,7 +128,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
128
128
 
129
129
  [[package]]
130
130
  name = "beancount-formatter"
131
- version = "0.1.17"
131
+ version = "0.1.18"
132
132
  dependencies = [
133
133
  "anyhow",
134
134
  "beancount-parser",
@@ -140,7 +140,7 @@ dependencies = [
140
140
 
141
141
  [[package]]
142
142
  name = "beancount-formatter-cli"
143
- version = "0.1.17"
143
+ version = "0.1.18"
144
144
  dependencies = [
145
145
  "anyhow",
146
146
  "assert_cmd",
@@ -154,7 +154,7 @@ dependencies = [
154
154
 
155
155
  [[package]]
156
156
  name = "beancount-formatter-py"
157
- version = "0.1.17"
157
+ version = "0.1.18"
158
158
  dependencies = [
159
159
  "beancount-formatter",
160
160
  "beancount-formatter-cli",
@@ -408,7 +408,7 @@ dependencies = [
408
408
 
409
409
  [[package]]
410
410
  name = "dprint-plugin-beancount"
411
- version = "0.1.17"
411
+ version = "0.1.18"
412
412
  dependencies = [
413
413
  "anyhow",
414
414
  "beancount-formatter",
@@ -3,7 +3,7 @@ members = ["crates/*"]
3
3
  resolver = "3"
4
4
 
5
5
  [workspace.package]
6
- version = "0.1.17"
6
+ version = "0.1.18"
7
7
  authors = ["Trim21 <trim21.me@gmail.com>"]
8
8
  edition = "2024"
9
9
  homepage = "https://github.com/trim21/beancount-format"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beancount-format
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python
6
6
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,19 @@
1
+ [package]
2
+ name = "tree-sitter-language"
3
+ version = "0.1.6"
4
+ authors = [
5
+ "Max Brunsfeld <maxbrunsfeld@gmail.com>",
6
+ "Amaan Qureshi <amaanq12@gmail.com>",
7
+ ]
8
+ categories = ["api-bindings", "development-tools::ffi", "parsing"]
9
+ documentation = "https://docs.rs/tree-sitter-language"
10
+ edition = "2021"
11
+ readme = "README.md"
12
+ rust-version = "1.77"
13
+ description = "The tree-sitter Language type, used by the library and by language implementations"
14
+
15
+ build = "build.rs"
16
+ links = "tree-sitter-language"
17
+
18
+ [lib]
19
+ path = "src/language.rs"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Max Brunsfeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ # Tree-sitter Language
2
+
3
+ This crate provides a `LanguageFn` type for grammars to create `Language` instances from a parser,
4
+ without having to worry about the `tree-sitter` crate version not matching.
@@ -0,0 +1,13 @@
1
+ fn main() {
2
+ if std::env::var("TARGET")
3
+ .unwrap_or_default()
4
+ .starts_with("wasm32-unknown")
5
+ {
6
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
7
+ let wasm_headers = std::path::Path::new(&manifest_dir).join("wasm/include");
8
+ let wasm_src = std::path::Path::new(&manifest_dir).join("wasm/src");
9
+
10
+ println!("cargo::metadata=wasm-headers={}", wasm_headers.display());
11
+ println!("cargo::metadata=wasm-src={}", wasm_src.display());
12
+ }
13
+ }
@@ -0,0 +1,23 @@
1
+ #![no_std]
2
+ /// `LanguageFn` wraps a C function that returns a pointer to a tree-sitter grammar.
3
+ #[repr(transparent)]
4
+ #[derive(Clone, Copy)]
5
+ pub struct LanguageFn(unsafe extern "C" fn() -> *const ());
6
+
7
+ impl LanguageFn {
8
+ /// Creates a [`LanguageFn`].
9
+ ///
10
+ /// # Safety
11
+ ///
12
+ /// Only call this with language functions generated from grammars
13
+ /// by the Tree-sitter CLI.
14
+ pub const unsafe fn from_raw(f: unsafe extern "C" fn() -> *const ()) -> Self {
15
+ Self(f)
16
+ }
17
+
18
+ /// Gets the function wrapped by this [`LanguageFn`].
19
+ #[must_use]
20
+ pub const fn into_raw(self) -> unsafe extern "C" fn() -> *const () {
21
+ self.0
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef TREE_SITTER_WASM_ASSERT_H_
2
+ #define TREE_SITTER_WASM_ASSERT_H_
3
+
4
+ #ifdef NDEBUG
5
+ #define assert(e) ((void)0)
6
+ #else
7
+ __attribute__((noreturn)) void __assert_fail(const char *assertion, const char *file, unsigned line, const char *function) {
8
+ __builtin_trap();
9
+ }
10
+ #define assert(expression) \
11
+ ((expression) ? (void)0 : __assert_fail(#expression, __FILE__, __LINE__, __func__))
12
+ #endif
13
+
14
+ #endif // TREE_SITTER_WASM_ASSERT_H_
@@ -0,0 +1,8 @@
1
+ #ifndef TREE_SITTER_WASM_CTYPE_H_
2
+ #define TREE_SITTER_WASM_CTYPE_H_
3
+
4
+ static inline int isprint(int c) {
5
+ return c >= 0x20 && c <= 0x7E;
6
+ }
7
+
8
+ #endif // TREE_SITTER_WASM_CTYPE_H_
@@ -0,0 +1,12 @@
1
+ #ifndef TREE_SITTER_WASM_ENDIAN_H_
2
+ #define TREE_SITTER_WASM_ENDIAN_H_
3
+
4
+ #define be16toh(x) __builtin_bswap16(x)
5
+ #define be32toh(x) __builtin_bswap32(x)
6
+ #define be64toh(x) __builtin_bswap64(x)
7
+ #define le16toh(x) (x)
8
+ #define le32toh(x) (x)
9
+ #define le64toh(x) (x)
10
+
11
+
12
+ #endif // TREE_SITTER_WASM_ENDIAN_H_
@@ -0,0 +1,8 @@
1
+ #ifndef TREE_SITTER_WASM_INTTYPES_H_
2
+ #define TREE_SITTER_WASM_INTTYPES_H_
3
+
4
+ // https://github.com/llvm/llvm-project/blob/0c3cf200f5b918fb5c1114e9f1764c2d54d1779b/libc/include/llvm-libc-macros/inttypes-macros.h#L209
5
+
6
+ #define PRId32 "d"
7
+
8
+ #endif // TREE_SITTER_WASM_INTTYPES_H_
@@ -0,0 +1,46 @@
1
+ #ifndef TREE_SITTER_WASM_STDINT_H_
2
+ #define TREE_SITTER_WASM_STDINT_H_
3
+
4
+ // https://github.com/llvm/llvm-project/blob/0c3cf200f5b918fb5c1114e9f1764c2d54d1779b/clang/test/Preprocessor/init.c#L1672
5
+
6
+ typedef signed char int8_t;
7
+
8
+ typedef short int16_t;
9
+
10
+ typedef int int32_t;
11
+
12
+ typedef long long int int64_t;
13
+
14
+ typedef unsigned char uint8_t;
15
+
16
+ typedef unsigned short uint16_t;
17
+
18
+ typedef unsigned int uint32_t;
19
+
20
+ typedef long long unsigned int uint64_t;
21
+
22
+ typedef long unsigned int size_t;
23
+
24
+ typedef long unsigned int uintptr_t;
25
+
26
+ #define INT8_MAX 127
27
+ #define INT16_MAX 32767
28
+ #define INT32_MAX 2147483647L
29
+ #define INT64_MAX 9223372036854775807LL
30
+
31
+ #define UINT8_MAX 255
32
+ #define UINT16_MAX 65535
33
+ #define UINT32_MAX 4294967295U
34
+ #define UINT64_MAX 18446744073709551615ULL
35
+
36
+ #if defined(__wasm32__)
37
+
38
+ #define SIZE_MAX 4294967295UL
39
+
40
+ #elif defined(__wasm64__)
41
+
42
+ #define SIZE_MAX 18446744073709551615UL
43
+
44
+ #endif
45
+
46
+ #endif // TREE_SITTER_WASM_STDINT_H_
@@ -0,0 +1,36 @@
1
+ #ifndef TREE_SITTER_WASM_STDIO_H_
2
+ #define TREE_SITTER_WASM_STDIO_H_
3
+
4
+ #include <stdbool.h>
5
+ #include <stdint.h>
6
+
7
+ typedef struct FILE FILE;
8
+
9
+ typedef __builtin_va_list va_list;
10
+ #define va_start(ap, last) __builtin_va_start(ap, last)
11
+ #define va_end(ap) __builtin_va_end(ap)
12
+ #define va_arg(ap, type) __builtin_va_arg(ap, type)
13
+
14
+ #define stdout ((FILE *)0)
15
+
16
+ #define stderr ((FILE *)1)
17
+
18
+ #define stdin ((FILE *)2)
19
+
20
+ int fclose(FILE *stream);
21
+
22
+ FILE *fdopen(int fd, const char *mode);
23
+
24
+ int fputc(int c, FILE *stream);
25
+
26
+ int fputs(const char *restrict s, FILE *restrict stream);
27
+
28
+ size_t fwrite(const void *restrict buffer, size_t size, size_t nmemb, FILE *restrict stream);
29
+
30
+ int fprintf(FILE *restrict stream, const char *restrict format, ...);
31
+
32
+ int snprintf(char *restrict buffer, size_t buffsz, const char *restrict format, ...);
33
+
34
+ int vsnprintf(char *restrict buffer, size_t buffsz, const char *restrict format, va_list vlist);
35
+
36
+ #endif // TREE_SITTER_WASM_STDIO_H_
@@ -0,0 +1,15 @@
1
+ #ifndef TREE_SITTER_WASM_STDLIB_H_
2
+ #define TREE_SITTER_WASM_STDLIB_H_
3
+
4
+ #include <stdint.h>
5
+
6
+ #define NULL ((void*)0)
7
+
8
+ void* malloc(size_t);
9
+ void* calloc(size_t, size_t);
10
+ void free(void*);
11
+ void* realloc(void*, size_t);
12
+
13
+ __attribute__((noreturn)) void abort(void);
14
+
15
+ #endif // TREE_SITTER_WASM_STDLIB_H_
@@ -0,0 +1,18 @@
1
+ #ifndef TREE_SITTER_WASM_STRING_H_
2
+ #define TREE_SITTER_WASM_STRING_H_
3
+
4
+ #include <stdint.h>
5
+
6
+ int memcmp(const void *lhs, const void *rhs, size_t count);
7
+
8
+ void *memcpy(void *restrict dst, const void *restrict src, size_t size);
9
+
10
+ void *memmove(void *dst, const void *src, size_t count);
11
+
12
+ void *memset(void *dst, int value, size_t count);
13
+
14
+ int strncmp(const char *left, const char *right, size_t n);
15
+
16
+ size_t strlen(const char *str);
17
+
18
+ #endif // TREE_SITTER_WASM_STRING_H_
@@ -0,0 +1,168 @@
1
+ #ifndef TREE_SITTER_WASM_WCTYPE_H_
2
+ #define TREE_SITTER_WASM_WCTYPE_H_
3
+
4
+ typedef int wint_t;
5
+
6
+ static inline bool iswalpha(wint_t wch) {
7
+ switch (wch) {
8
+ case L'a':
9
+ case L'b':
10
+ case L'c':
11
+ case L'd':
12
+ case L'e':
13
+ case L'f':
14
+ case L'g':
15
+ case L'h':
16
+ case L'i':
17
+ case L'j':
18
+ case L'k':
19
+ case L'l':
20
+ case L'm':
21
+ case L'n':
22
+ case L'o':
23
+ case L'p':
24
+ case L'q':
25
+ case L'r':
26
+ case L's':
27
+ case L't':
28
+ case L'u':
29
+ case L'v':
30
+ case L'w':
31
+ case L'x':
32
+ case L'y':
33
+ case L'z':
34
+ case L'A':
35
+ case L'B':
36
+ case L'C':
37
+ case L'D':
38
+ case L'E':
39
+ case L'F':
40
+ case L'G':
41
+ case L'H':
42
+ case L'I':
43
+ case L'J':
44
+ case L'K':
45
+ case L'L':
46
+ case L'M':
47
+ case L'N':
48
+ case L'O':
49
+ case L'P':
50
+ case L'Q':
51
+ case L'R':
52
+ case L'S':
53
+ case L'T':
54
+ case L'U':
55
+ case L'V':
56
+ case L'W':
57
+ case L'X':
58
+ case L'Y':
59
+ case L'Z':
60
+ return true;
61
+ default:
62
+ return false;
63
+ }
64
+ }
65
+
66
+ static inline bool iswdigit(wint_t wch) {
67
+ switch (wch) {
68
+ case L'0':
69
+ case L'1':
70
+ case L'2':
71
+ case L'3':
72
+ case L'4':
73
+ case L'5':
74
+ case L'6':
75
+ case L'7':
76
+ case L'8':
77
+ case L'9':
78
+ return true;
79
+ default:
80
+ return false;
81
+ }
82
+ }
83
+
84
+ static inline bool iswalnum(wint_t wch) {
85
+ switch (wch) {
86
+ case L'a':
87
+ case L'b':
88
+ case L'c':
89
+ case L'd':
90
+ case L'e':
91
+ case L'f':
92
+ case L'g':
93
+ case L'h':
94
+ case L'i':
95
+ case L'j':
96
+ case L'k':
97
+ case L'l':
98
+ case L'm':
99
+ case L'n':
100
+ case L'o':
101
+ case L'p':
102
+ case L'q':
103
+ case L'r':
104
+ case L's':
105
+ case L't':
106
+ case L'u':
107
+ case L'v':
108
+ case L'w':
109
+ case L'x':
110
+ case L'y':
111
+ case L'z':
112
+ case L'A':
113
+ case L'B':
114
+ case L'C':
115
+ case L'D':
116
+ case L'E':
117
+ case L'F':
118
+ case L'G':
119
+ case L'H':
120
+ case L'I':
121
+ case L'J':
122
+ case L'K':
123
+ case L'L':
124
+ case L'M':
125
+ case L'N':
126
+ case L'O':
127
+ case L'P':
128
+ case L'Q':
129
+ case L'R':
130
+ case L'S':
131
+ case L'T':
132
+ case L'U':
133
+ case L'V':
134
+ case L'W':
135
+ case L'X':
136
+ case L'Y':
137
+ case L'Z':
138
+ case L'0':
139
+ case L'1':
140
+ case L'2':
141
+ case L'3':
142
+ case L'4':
143
+ case L'5':
144
+ case L'6':
145
+ case L'7':
146
+ case L'8':
147
+ case L'9':
148
+ return true;
149
+ default:
150
+ return false;
151
+ }
152
+ }
153
+
154
+ static inline bool iswspace(wint_t wch) {
155
+ switch (wch) {
156
+ case L' ':
157
+ case L'\t':
158
+ case L'\n':
159
+ case L'\v':
160
+ case L'\f':
161
+ case L'\r':
162
+ return true;
163
+ default:
164
+ return false;
165
+ }
166
+ }
167
+
168
+ #endif // TREE_SITTER_WASM_WCTYPE_H_
@@ -0,0 +1,299 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+
4
+ typedef struct {
5
+ bool left_justify; // -
6
+ bool zero_pad; // 0
7
+ bool show_sign; // +
8
+ bool space_prefix; // ' '
9
+ bool alternate_form; // #
10
+ } format_flags_t;
11
+
12
+ static const char* parse_format_spec(
13
+ const char *format,
14
+ int *width,
15
+ int *precision,
16
+ format_flags_t *flags
17
+ ) {
18
+ *width = 0;
19
+ *precision = -1;
20
+ flags->left_justify = false;
21
+ flags->zero_pad = false;
22
+ flags->show_sign = false;
23
+ flags->space_prefix = false;
24
+ flags->alternate_form = false;
25
+
26
+ const char *p = format;
27
+
28
+ // Parse flags
29
+ while (*p == '-' || *p == '+' || *p == ' ' || *p == '#' || *p == '0') {
30
+ switch (*p) {
31
+ case '-': flags->left_justify = true; break;
32
+ case '0': flags->zero_pad = true; break;
33
+ case '+': flags->show_sign = true; break;
34
+ case ' ': flags->space_prefix = true; break;
35
+ case '#': flags->alternate_form = true; break;
36
+ }
37
+ p++;
38
+ }
39
+
40
+ // width
41
+ while (*p >= '0' && *p <= '9') {
42
+ *width = (*width * 10) + (*p - '0');
43
+ p++;
44
+ }
45
+
46
+ // precision
47
+ if (*p == '.') {
48
+ p++;
49
+ *precision = 0;
50
+ while (*p >= '0' && *p <= '9') {
51
+ *precision = (*precision * 10) + (*p - '0');
52
+ p++;
53
+ }
54
+ }
55
+
56
+ return p;
57
+ }
58
+
59
+ static int int_to_str(
60
+ long long value,
61
+ char *buffer,
62
+ int base,
63
+ bool is_signed,
64
+ bool uppercase
65
+ ) {
66
+ if (base < 2 || base > 16) return 0;
67
+
68
+ const char *digits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
69
+ char temp[32];
70
+ int i = 0, len = 0;
71
+ bool is_negative = false;
72
+
73
+ if (value == 0) {
74
+ buffer[0] = '0';
75
+ buffer[1] = '\0';
76
+ return 1;
77
+ }
78
+
79
+ if (is_signed && value < 0 && base == 10) {
80
+ is_negative = true;
81
+ value = -value;
82
+ }
83
+
84
+ unsigned long long uval = (unsigned long long)value;
85
+ while (uval > 0) {
86
+ temp[i++] = digits[uval % base];
87
+ uval /= base;
88
+ }
89
+
90
+ if (is_negative) {
91
+ buffer[len++] = '-';
92
+ }
93
+
94
+ while (i > 0) {
95
+ buffer[len++] = temp[--i];
96
+ }
97
+
98
+ buffer[len] = '\0';
99
+ return len;
100
+ }
101
+
102
+ static int ptr_to_str(void *ptr, char *buffer) {
103
+ buffer[0] = '0';
104
+ buffer[1] = 'x';
105
+ int len = int_to_str((uintptr_t)ptr, buffer + 2, 16, 0, 0);
106
+ return 2 + len;
107
+ }
108
+
109
+ char *strncpy(char *dest, const char *src, size_t n) {
110
+ char *d = dest;
111
+ const char *s = src;
112
+ while (n-- && (*d++ = *s++));
113
+ if (n == (size_t)-1) *d = '\0';
114
+ return dest;
115
+ }
116
+
117
+ static int write_formatted_to_buffer(
118
+ char *buffer,
119
+ size_t buffer_size,
120
+ size_t *pos,
121
+ const char *str,
122
+ int width,
123
+ const format_flags_t *flags
124
+ ) {
125
+ int len = strlen(str);
126
+ int written = 0;
127
+ int pad_len = (width > len) ? (width - len) : 0;
128
+ int zero_pad = flags->zero_pad && !flags->left_justify;
129
+
130
+ if (!flags->left_justify && pad_len > 0) {
131
+ char pad_char = zero_pad ? '0' : ' ';
132
+ for (int i = 0; i < pad_len && *pos < buffer_size - 1; i++) {
133
+ buffer[(*pos)++] = pad_char;
134
+ written++;
135
+ }
136
+ }
137
+
138
+ for (int i = 0; i < len && *pos < buffer_size - 1; i++) {
139
+ buffer[(*pos)++] = str[i];
140
+ written++;
141
+ }
142
+
143
+ if (flags->left_justify && pad_len > 0) {
144
+ for (int i = 0; i < pad_len && *pos < buffer_size - 1; i++) {
145
+ buffer[(*pos)++] = ' ';
146
+ written++;
147
+ }
148
+ }
149
+
150
+ return written;
151
+ }
152
+
153
+ static int vsnprintf_impl(char *buffer, size_t buffsz, const char *format, va_list args) {
154
+ if (!buffer || buffsz == 0 || !format) return -1;
155
+
156
+ size_t pos = 0;
157
+ int total_chars = 0;
158
+ const char *p = format;
159
+
160
+ while (*p) {
161
+ if (*p == '%') {
162
+ p++;
163
+ if (*p == '%') {
164
+ if (pos < buffsz - 1) buffer[pos++] = '%';
165
+ total_chars++;
166
+ p++;
167
+ continue;
168
+ }
169
+
170
+ int width, precision;
171
+ format_flags_t flags;
172
+ p = parse_format_spec(p, &width, &precision, &flags);
173
+
174
+ char temp_buf[64];
175
+ const char *output_str = temp_buf;
176
+
177
+ switch (*p) {
178
+ case 's': {
179
+ const char *str = va_arg(args, const char*);
180
+ if (!str) str = "(null)";
181
+
182
+ int str_len = strlen(str);
183
+ if (precision >= 0 && str_len > precision) {
184
+ strncpy(temp_buf, str, precision);
185
+ temp_buf[precision] = '\0';
186
+ output_str = temp_buf;
187
+ } else {
188
+ output_str = str;
189
+ }
190
+ break;
191
+ }
192
+ case 'd':
193
+ case 'i': {
194
+ int value = va_arg(args, int);
195
+ int_to_str(value, temp_buf, 10, true, false);
196
+ break;
197
+ }
198
+ case 'u': {
199
+ unsigned int value = va_arg(args, unsigned int);
200
+ int_to_str(value, temp_buf, 10, false, false);
201
+ break;
202
+ }
203
+ case 'x': {
204
+ unsigned int value = va_arg(args, unsigned int);
205
+ int_to_str(value, temp_buf, 16, false, false);
206
+ break;
207
+ }
208
+ case 'X': {
209
+ unsigned int value = va_arg(args, unsigned int);
210
+ int_to_str(value, temp_buf, 16, false, true);
211
+ break;
212
+ }
213
+ case 'p': {
214
+ void *ptr = va_arg(args, void*);
215
+ ptr_to_str(ptr, temp_buf);
216
+ break;
217
+ }
218
+ case 'c': {
219
+ int c = va_arg(args, int);
220
+ temp_buf[0] = (char)c;
221
+ temp_buf[1] = '\0';
222
+ break;
223
+ }
224
+ case 'z': {
225
+ if (*(p + 1) == 'u') {
226
+ size_t value = va_arg(args, size_t);
227
+ int_to_str(value, temp_buf, 10, false, false);
228
+ p++;
229
+ } else {
230
+ temp_buf[0] = 'z';
231
+ temp_buf[1] = '\0';
232
+ }
233
+ break;
234
+ }
235
+ default:
236
+ temp_buf[0] = '%';
237
+ temp_buf[1] = *p;
238
+ temp_buf[2] = '\0';
239
+ break;
240
+ }
241
+
242
+ int str_len = strlen(output_str);
243
+ int formatted_len = (width > str_len) ? width : str_len;
244
+ total_chars += formatted_len;
245
+
246
+ if (pos < buffsz - 1) {
247
+ write_formatted_to_buffer(buffer, buffsz, &pos, output_str, width, &flags);
248
+ }
249
+
250
+ } else {
251
+ if (pos < buffsz - 1) buffer[pos++] = *p;
252
+ total_chars++;
253
+ }
254
+ p++;
255
+ }
256
+
257
+ if (buffsz > 0) buffer[pos < buffsz ? pos : buffsz - 1] = '\0';
258
+
259
+ return total_chars;
260
+ }
261
+
262
+ int snprintf(char *restrict buffer, size_t buffsz, const char *restrict format, ...) {
263
+ if (!buffer || buffsz == 0 || !format) return -1;
264
+
265
+ va_list args;
266
+ va_start(args, format);
267
+ int result = vsnprintf_impl(buffer, buffsz, format, args);
268
+ va_end(args);
269
+
270
+ return result;
271
+ }
272
+
273
+ int vsnprintf(char *restrict buffer, size_t buffsz, const char *restrict format, va_list vlist) {
274
+ return vsnprintf_impl(buffer, buffsz, format, vlist);
275
+ }
276
+
277
+ int fclose(FILE *stream) {
278
+ return 0;
279
+ }
280
+
281
+ FILE* fdopen(int fd, const char *mode) {
282
+ return 0;
283
+ }
284
+
285
+ int fputc(int c, FILE *stream) {
286
+ return c;
287
+ }
288
+
289
+ int fputs(const char *restrict str, FILE *restrict stream) {
290
+ return 0;
291
+ }
292
+
293
+ size_t fwrite(const void *restrict buffer, size_t size, size_t nmemb, FILE *restrict stream) {
294
+ return size * nmemb;
295
+ }
296
+
297
+ int fprintf(FILE *restrict stream, const char *restrict format, ...) {
298
+ return 0;
299
+ }
@@ -0,0 +1,161 @@
1
+ // This file implements a very simple allocator for external scanners running
2
+ // in Wasm. Allocation is just bumping a static pointer and growing the heap
3
+ // as needed, and freeing is just adding the freed region to a free list.
4
+ // When additional memory is allocated, the free list is searched first.
5
+ // If there is not a suitable region in the free list, the heap is
6
+ // grown as necessary, and the allocation is made at the end of the heap.
7
+ // When the heap is reset, all allocated memory is considered freed.
8
+
9
+ #include <stdint.h>
10
+ #include <stdlib.h>
11
+ #include <string.h>
12
+
13
+ extern void tree_sitter_debug_message(const char *, size_t);
14
+
15
+ #define PAGESIZE 0x10000
16
+ #define MAX_HEAP_SIZE (4 * 1024 * 1024)
17
+
18
+ typedef struct {
19
+ size_t size;
20
+ struct Region *next;
21
+ char data[0];
22
+ } Region;
23
+
24
+ static Region *heap_end = NULL;
25
+ static Region *heap_start = NULL;
26
+ static Region *next = NULL;
27
+ static Region *free_list = NULL;
28
+
29
+ // Get the region metadata for the given heap pointer.
30
+ static inline Region *region_for_ptr(void *ptr) { return ((Region *)ptr) - 1; }
31
+
32
+ // Get the location of the next region after the given region,
33
+ // if the given region had the given size.
34
+ static inline Region *region_after(Region *self, size_t len) {
35
+ char *address = self->data + len;
36
+ char *aligned = (char *)((uintptr_t)(address + 3) & ~0x3);
37
+ return (Region *)aligned;
38
+ }
39
+
40
+ static void *get_heap_end() {
41
+ return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE);
42
+ }
43
+
44
+ static int grow_heap(size_t size) {
45
+ size_t new_page_count = ((size - 1) / PAGESIZE) + 1;
46
+ return __builtin_wasm_memory_grow(0, new_page_count) != SIZE_MAX;
47
+ }
48
+
49
+ // Clear out the heap, and move it to the given address.
50
+ void reset_heap(void *new_heap_start) {
51
+ heap_start = new_heap_start;
52
+ next = new_heap_start;
53
+ heap_end = get_heap_end();
54
+ free_list = NULL;
55
+ }
56
+
57
+ void *malloc(size_t size) {
58
+ if (size == 0)
59
+ return NULL;
60
+
61
+ Region *prev = NULL;
62
+ Region *curr = free_list;
63
+ while (curr != NULL) {
64
+ if (curr->size >= size) {
65
+ if (prev == NULL) {
66
+ free_list = curr->next;
67
+ } else {
68
+ prev->next = curr->next;
69
+ }
70
+ return &curr->data;
71
+ }
72
+ prev = curr;
73
+ curr = curr->next;
74
+ }
75
+
76
+ Region *region_end = region_after(next, size);
77
+
78
+ if (region_end > heap_end) {
79
+ if ((char *)region_end - (char *)heap_start > MAX_HEAP_SIZE) {
80
+ return NULL;
81
+ }
82
+ if (!grow_heap(size))
83
+ return NULL;
84
+ heap_end = get_heap_end();
85
+ }
86
+
87
+ void *result = &next->data;
88
+ next->size = size;
89
+ next = region_end;
90
+
91
+ return result;
92
+ }
93
+
94
+ void free(void *ptr) {
95
+ if (ptr == NULL)
96
+ return;
97
+
98
+ Region *region = region_for_ptr(ptr);
99
+ Region *region_end = region_after(region, region->size);
100
+
101
+ // When freeing the last allocated pointer, re-use that
102
+ // pointer for the next allocation.
103
+ if (region_end == next) {
104
+ next = region;
105
+ } else {
106
+ region->next = free_list;
107
+ free_list = region;
108
+ }
109
+ }
110
+
111
+ void *calloc(size_t count, size_t size) {
112
+ void *result = malloc(count * size);
113
+ if (!result)
114
+ return NULL;
115
+ memset(result, 0, count * size);
116
+ return result;
117
+ }
118
+
119
+ void *realloc(void *ptr, size_t new_size) {
120
+ if (ptr == NULL) {
121
+ return malloc(new_size);
122
+ }
123
+ if (new_size == 0) {
124
+ free(ptr);
125
+ return NULL;
126
+ }
127
+
128
+ Region *region = region_for_ptr(ptr);
129
+ Region *region_end = region_after(region, region->size);
130
+
131
+ // When reallocating the last allocated region, return
132
+ // the same pointer, and skip copying the data.
133
+ if (region_end == next) {
134
+ // Resize in place: bypass the free list to ensure
135
+ // we keep the same pointer and adjust the bump allocator.
136
+ Region *new_end = region_after(region, new_size);
137
+ if (new_end > heap_end) {
138
+ if ((char *)new_end - (char *)heap_start > MAX_HEAP_SIZE) {
139
+ return NULL;
140
+ }
141
+ if (!grow_heap(new_size))
142
+ return NULL;
143
+ heap_end = get_heap_end();
144
+ }
145
+ region->size = new_size;
146
+ next = new_end;
147
+ return &region->data;
148
+ }
149
+
150
+ void *result = malloc(new_size);
151
+ if (!result)
152
+ return NULL;
153
+
154
+ size_t copy_size = region->size < new_size ? region->size : new_size;
155
+ memcpy(result, &region->data, copy_size);
156
+
157
+ free(ptr);
158
+ return result;
159
+ }
160
+
161
+ __attribute__((noreturn)) void abort(void) { __builtin_trap(); }
@@ -0,0 +1,66 @@
1
+ #include <string.h>
2
+
3
+ int memcmp(const void *lhs, const void *rhs, size_t count) {
4
+ const unsigned char *l = lhs;
5
+ const unsigned char *r = rhs;
6
+ while (count--) {
7
+ if (*l != *r) {
8
+ return *l - *r;
9
+ }
10
+ l++;
11
+ r++;
12
+ }
13
+ return 0;
14
+ }
15
+
16
+ void *memcpy(void *restrict dst, const void *restrict src, size_t size) {
17
+ unsigned char *d = dst;
18
+ const unsigned char *s = src;
19
+ while (size--) {
20
+ *d++ = *s++;
21
+ }
22
+ return dst;
23
+ }
24
+
25
+ void *memmove(void *dst, const void *src, size_t count) {
26
+ unsigned char *d = dst;
27
+ const unsigned char *s = src;
28
+ if (d < s) {
29
+ while (count--) {
30
+ *d++ = *s++;
31
+ }
32
+ } else if (d > s) {
33
+ d += count;
34
+ s += count;
35
+ while (count--) {
36
+ *(--d) = *(--s);
37
+ }
38
+ }
39
+ return dst;
40
+ }
41
+
42
+ void *memset(void *dst, int value, size_t count) {
43
+ unsigned char *p = dst;
44
+ while (count--) {
45
+ *p++ = (unsigned char)value;
46
+ }
47
+ return dst;
48
+ }
49
+
50
+ int strncmp(const char *left, const char *right, size_t n) {
51
+ while (n-- > 0) {
52
+ if (*left != *right) {
53
+ return *(unsigned char *)left - *(unsigned char *)right;
54
+ }
55
+ if (*left == '\0') break;
56
+ left++;
57
+ right++;
58
+ }
59
+ return 0;
60
+ }
61
+
62
+ size_t strlen(const char *str) {
63
+ const char *s = str;
64
+ while (*s) s++;
65
+ return s - str;
66
+ }
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "beancount-format"
7
- version = "0.1.17"
7
+ version = "0.1.18"
8
8
  description = "Beancount formatter powered by dprint-plugin-beancount"
9
9
  authors = [{ name = "trim21", email = "trim21.me@gmail.com" }]
10
10
  license = { file = "LICENSE" }
@@ -29,6 +29,7 @@ manifest-path = "crates/beancount-formatter-py/Cargo.toml"
29
29
  module-name = "beancount_format"
30
30
  strip = true
31
31
  python-source = "python/src"
32
+ include = [{ path = "patches/**/*", format = "sdist" }]
32
33
 
33
34
  [tool.uv]
34
35
  package = false