diff options
Diffstat (limited to 'vendor/tree-sitter/lib/src/point.h')
| -rw-r--r-- | vendor/tree-sitter/lib/src/point.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/tree-sitter/lib/src/point.h b/vendor/tree-sitter/lib/src/point.h new file mode 100644 index 0000000..37346c8 --- /dev/null +++ b/vendor/tree-sitter/lib/src/point.h | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #ifndef TREE_SITTER_POINT_H_ | ||
| 2 | #define TREE_SITTER_POINT_H_ | ||
| 3 | |||
| 4 | #include "tree_sitter/api.h" | ||
| 5 | |||
| 6 | #define POINT_ZERO ((TSPoint) {0, 0}) | ||
| 7 | #define POINT_MAX ((TSPoint) {UINT32_MAX, UINT32_MAX}) | ||
| 8 | |||
| 9 | static inline TSPoint point__new(unsigned row, unsigned column) { | ||
| 10 | TSPoint result = {row, column}; | ||
| 11 | return result; | ||
| 12 | } | ||
| 13 | |||
| 14 | static inline TSPoint point_add(TSPoint a, TSPoint b) { | ||
| 15 | if (b.row > 0) | ||
| 16 | return point__new(a.row + b.row, b.column); | ||
| 17 | else | ||
| 18 | return point__new(a.row, a.column + b.column); | ||
| 19 | } | ||
| 20 | |||
| 21 | static inline TSPoint point_sub(TSPoint a, TSPoint b) { | ||
| 22 | if (a.row > b.row) | ||
| 23 | return point__new(a.row - b.row, a.column); | ||
| 24 | else | ||
| 25 | return point__new(0, a.column - b.column); | ||
| 26 | } | ||
| 27 | |||
| 28 | static inline bool point_lte(TSPoint a, TSPoint b) { | ||
| 29 | return (a.row < b.row) || (a.row == b.row && a.column <= b.column); | ||
| 30 | } | ||
| 31 | |||
| 32 | static inline bool point_lt(TSPoint a, TSPoint b) { | ||
| 33 | return (a.row < b.row) || (a.row == b.row && a.column < b.column); | ||
| 34 | } | ||
| 35 | |||
| 36 | static inline bool point_gt(TSPoint a, TSPoint b) { | ||
| 37 | return (a.row > b.row) || (a.row == b.row && a.column > b.column); | ||
| 38 | } | ||
| 39 | |||
| 40 | static inline bool point_gte(TSPoint a, TSPoint b) { | ||
| 41 | return (a.row > b.row) || (a.row == b.row && a.column >= b.column); | ||
| 42 | } | ||
| 43 | |||
| 44 | static inline bool point_eq(TSPoint a, TSPoint b) { | ||
| 45 | return a.row == b.row && a.column == b.column; | ||
| 46 | } | ||
| 47 | |||
| 48 | static inline TSPoint point_min(TSPoint a, TSPoint b) { | ||
| 49 | if (a.row < b.row || (a.row == b.row && a.column < b.column)) | ||
| 50 | return a; | ||
| 51 | else | ||
| 52 | return b; | ||
| 53 | } | ||
| 54 | |||
| 55 | static inline TSPoint point_max(TSPoint a, TSPoint b) { | ||
| 56 | if (a.row > b.row || (a.row == b.row && a.column > b.column)) | ||
| 57 | return a; | ||
| 58 | else | ||
| 59 | return b; | ||
| 60 | } | ||
| 61 | |||
| 62 | #endif | ||
