aboutsummaryrefslogtreecommitdiff
path: root/vendor/tree-sitter/lib/src/length.h
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2023-11-07 16:38:48 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2023-11-07 16:38:48 +0100
commitc0377818aa198a5b5d0d3c7697373c5b6828d5fa (patch)
tree8deb7109e9c996884a6a86ab46ec6190e793c532 /vendor/tree-sitter/lib/src/length.h
parentf9dcd08833afdfb3b4446cb842d3ecd4469c5638 (diff)
downloadcrep-c0377818aa198a5b5d0d3c7697373c5b6828d5fa.tar.gz
Added tree-sitter vendor library
Diffstat (limited to 'vendor/tree-sitter/lib/src/length.h')
-rw-r--r--vendor/tree-sitter/lib/src/length.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/tree-sitter/lib/src/length.h b/vendor/tree-sitter/lib/src/length.h
new file mode 100644
index 0000000..42d61ef
--- /dev/null
+++ b/vendor/tree-sitter/lib/src/length.h
@@ -0,0 +1,52 @@
1#ifndef TREE_SITTER_LENGTH_H_
2#define TREE_SITTER_LENGTH_H_
3
4#include <stdlib.h>
5#include <stdbool.h>
6#include "./point.h"
7#include "tree_sitter/api.h"
8
9typedef struct {
10 uint32_t bytes;
11 TSPoint extent;
12} Length;
13
14static const Length LENGTH_UNDEFINED = {0, {0, 1}};
15static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
16
17static inline bool length_is_undefined(Length length) {
18 return length.bytes == 0 && length.extent.column != 0;
19}
20
21static inline Length length_min(Length len1, Length len2) {
22 return (len1.bytes < len2.bytes) ? len1 : len2;
23}
24
25static inline Length length_add(Length len1, Length len2) {
26 Length result;
27 result.bytes = len1.bytes + len2.bytes;
28 result.extent = point_add(len1.extent, len2.extent);
29 return result;
30}
31
32static inline Length length_sub(Length len1, Length len2) {
33 Length result;
34 result.bytes = len1.bytes - len2.bytes;
35 result.extent = point_sub(len1.extent, len2.extent);
36 return result;
37}
38
39static inline Length length_zero(void) {
40 Length result = {0, {0, 0}};
41 return result;
42}
43
44static inline Length length_saturating_sub(Length len1, Length len2) {
45 if (len1.bytes > len2.bytes) {
46 return length_sub(len1, len2);
47 } else {
48 return length_zero();
49 }
50}
51
52#endif