Skip to main content

tree_house_bindings/
lib.rs

1mod grammar;
2mod node;
3mod parser;
4pub mod query;
5mod query_cursor;
6mod tree;
7mod tree_cursor;
8
9#[cfg(feature = "ropey")]
10mod ropey;
11#[cfg(feature = "ropey")]
12pub use ropey::RopeInput;
13
14use std::ops;
15
16pub use grammar::{Grammar, IncompatibleGrammarError};
17pub use node::Node;
18pub use parser::{ParseOptions, ParseState, Parser, ParserInputRaw};
19pub use query::{Capture, Pattern, Query, QueryStr};
20pub use query_cursor::{InactiveQueryCursor, MatchedNode, MatchedNodeIdx, QueryCursor, QueryMatch};
21pub use tree::{InputEdit, Tree};
22pub use tree_cursor::TreeCursor;
23
24#[repr(C)]
25#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
26pub struct Point {
27    pub row: u32,
28    pub col: u32,
29}
30
31impl Point {
32    pub const ZERO: Self = Self { row: 0, col: 0 };
33    pub const MAX: Self = Self {
34        row: u32::MAX,
35        col: u32::MAX,
36    };
37}
38
39#[repr(C)]
40#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
41pub struct Range {
42    pub start_point: Point,
43    pub end_point: Point,
44    pub start_byte: u32,
45    pub end_byte: u32,
46}
47
48impl Range {
49    pub fn new(start_point: Point, end_point: Point, start_byte: u32, end_byte: u32) -> Range {
50        debug_assert!(start_point <= end_point);
51        debug_assert!(start_byte <= end_byte);
52        Range {
53            start_point,
54            end_point,
55            start_byte,
56            end_byte,
57        }
58    }
59}
60
61pub trait Input {
62    type Cursor: regex_cursor::Cursor;
63    fn cursor_at(&mut self, offset: u32) -> &mut Self::Cursor;
64    fn eq(&mut self, range1: ops::Range<u32>, range2: ops::Range<u32>) -> bool;
65}
66
67pub trait IntoInput {
68    type Input: Input;
69    fn into_input(self) -> Self::Input;
70}
71
72impl<T: Input> IntoInput for T {
73    type Input = T;
74
75    fn into_input(self) -> T {
76        self
77    }
78}