tree_sitter_reinhardt_head/
lib.rs1#![warn(missing_docs)]
4
5use tree_sitter_language::LanguageFn;
6
7unsafe extern "C" {
8 fn tree_sitter_reinhardt_head() -> *const ();
9}
10
11pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_reinhardt_head) };
13
14pub const NODE_TYPES: &str = include_str!("node-types.json");
16
17#[cfg(test)]
18mod tests {
19 #[test]
20 fn parser_loads() {
21 let mut parser = tree_sitter::Parser::new();
22 parser
23 .set_language(&super::LANGUAGE.into())
24 .expect("load head DSL grammar");
25 }
26
27 #[test]
30 fn block_comment_simple() {
31 let mut parser = tree_sitter::Parser::new();
33 parser.set_language(&super::LANGUAGE.into()).unwrap();
34 let source = "/* hello */";
35
36 let tree = parser.parse(source, None).unwrap();
38
39 assert!(
41 !tree.root_node().has_error(),
42 "parse tree: {}",
43 tree.root_node().to_sexp()
44 );
45 }
46
47 #[test]
48 fn block_comment_empty() {
49 let mut parser = tree_sitter::Parser::new();
51 parser.set_language(&super::LANGUAGE.into()).unwrap();
52 let source = "/**/";
53
54 let tree = parser.parse(source, None).unwrap();
56
57 assert!(
59 !tree.root_node().has_error(),
60 "parse tree: {}",
61 tree.root_node().to_sexp()
62 );
63 }
64
65 #[test]
66 fn block_comment_slash_star_slash_is_not_complete() {
67 let mut parser = tree_sitter::Parser::new();
69 parser.set_language(&super::LANGUAGE.into()).unwrap();
70 let source = "/*/ div { \"text\" }";
71
72 let tree = parser.parse(source, None).unwrap();
74
75 let sexp = tree.root_node().to_sexp();
78 assert!(
81 tree.root_node().has_error() || !sexp.contains("block_comment"),
82 "/*/ should not be a valid block comment: {sexp}"
83 );
84 }
85
86 #[test]
87 fn block_comment_nested_stars() {
88 let mut parser = tree_sitter::Parser::new();
90 parser.set_language(&super::LANGUAGE.into()).unwrap();
91 let source = "/* nested ** stars */";
92
93 let tree = parser.parse(source, None).unwrap();
95
96 assert!(
98 !tree.root_node().has_error(),
99 "parse tree: {}",
100 tree.root_node().to_sexp()
101 );
102 }
103
104 #[test]
105 fn block_comment_unterminated_is_not_accepted() {
106 let mut parser = tree_sitter::Parser::new();
108 parser.set_language(&super::LANGUAGE.into()).unwrap();
109 let source = "/* unterminated comment";
110
111 let tree = parser.parse(source, None).unwrap();
113
114 let sexp = tree.root_node().to_sexp();
118 assert!(
119 !sexp.contains("block_comment"),
120 "unterminated input should not produce a block_comment node: {sexp}"
121 );
122 }
123
124 #[test]
127 fn line_comment_simple() {
128 let mut parser = tree_sitter::Parser::new();
130 parser.set_language(&super::LANGUAGE.into()).unwrap();
131 let source = "// this is a comment";
132
133 let tree = parser.parse(source, None).unwrap();
135
136 assert!(
138 !tree.root_node().has_error(),
139 "parse tree: {}",
140 tree.root_node().to_sexp()
141 );
142 }
143
144 #[test]
145 fn line_comment_only_captures_first_line() {
146 let mut parser = tree_sitter::Parser::new();
148 parser.set_language(&super::LANGUAGE.into()).unwrap();
149 let source = "// comment\ntitle { \"Page\" }";
150
151 let tree = parser.parse(source, None).unwrap();
153
154 let sexp = tree.root_node().to_sexp();
156 assert!(
157 sexp.contains("line_comment"),
158 "expected a line_comment node: {sexp}"
159 );
160 let root = tree.root_node();
162 assert!(
163 root.child_count() > 1,
164 "second line should produce separate nodes after the comment: {sexp}"
165 );
166 }
167
168 #[test]
171 fn head_dsl_basic_structure() {
172 let mut parser = tree_sitter::Parser::new();
174 parser.set_language(&super::LANGUAGE.into()).unwrap();
175 let source = r#"|| { title { "Page" } }"#;
176
177 let tree = parser.parse(source, None).unwrap();
179
180 assert!(
182 !tree.root_node().has_error(),
183 "parse tree: {}",
184 tree.root_node().to_sexp()
185 );
186 }
187
188 #[test]
191 fn head_dsl_with_block_comment() {
192 let mut parser = tree_sitter::Parser::new();
194 parser.set_language(&super::LANGUAGE.into()).unwrap();
195 let source = r#"|| { /* comment */ title { "Page" } }"#;
196
197 let tree = parser.parse(source, None).unwrap();
199
200 let sexp = tree.root_node().to_sexp();
202 assert!(!tree.root_node().has_error(), "parse tree: {sexp}");
203 assert!(
204 sexp.contains("block_comment"),
205 "expected a block_comment node in the tree: {sexp}"
206 );
207 }
208}