tree_sitter_objectscript_routine/
lib.rs1use tree_sitter_language::LanguageFn;
6
7extern "C" {
8 fn tree_sitter_objectscript_routine() -> *const ();
9}
10
11pub const LANGUAGE_OBJECTSCRIPT_ROUTINE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_objectscript_routine) };
15
16pub const NODE_TYPES: &str = include_str!("objectscript_routine/src/node-types.json");
20
21pub const HIGHLIGHTS_QUERY: &str = include_str!("objectscript_routine/queries/highlights.scm");
23
24pub const STUDIO_HIGHLIGHTS_QUERY: &str = include_str!("objectscript_routine/queries/studio-highlights.scm");
26
27pub const INJECTIONS_QUERY: &str = include_str!("objectscript_routine/queries/injections.scm");
29
30pub const INDENTS_QUERY: &str = include_str!("objectscript_routine/queries/indents.scm");
32
33#[cfg(test)]
34mod tests {
35 use tree_sitter::{Parser, Point, Node};
36 pub fn dump(node: Node, depth: usize) {
37 let indent = " ".repeat(depth);
38 let start = node.start_position();
39 let end = node.end_position();
40
41 println!(
42 "{}{} [{}, {}] - [{}, {}]",
43 indent,
44 node.kind(),
45 start.row,
46 start.column,
47 end.row,
48 end.column
49 );
50
51 let mut cursor = node.walk();
52 for child in node.named_children(&mut cursor) {
53 dump(child, depth + 1);
54 }
55}
56 fn parse_cls(code: &str) -> tree_sitter::Tree {
57 let mut parser = Parser::new();
58 parser
59 .set_language(&super::LANGUAGE_OBJECTSCRIPT_ROUTINE.into())
60 .expect("failed to load objectscript routine grammar");
61 parser.parse(code, None).expect("parse returned None")
62 }
63
64 #[test]
65 fn test_can_load_objectscript_routine_grammar() {
66
67 let source = r#"ROUTINE x
72heyyy() methodimpl {
73 w "hi"
74 set x = 2
75 if x {
76 w "bye"
77 q
78 }
79}
80"#;
81 let tree = parse_cls(source);
82 dump(tree.root_node(), 0);
83 }
86
87 #[test]
88 fn test_indents_query_is_loaded() {
89 assert!(super::INDENTS_QUERY.contains("indent"));
90 }
91
92 #[test]
93 fn test_injections_query_is_loaded() {
94 assert!(super::INJECTIONS_QUERY.contains("injection"));
95 }
96
97 #[test]
98 fn test_highlights_query_is_loaded() {
99 assert!(super::HIGHLIGHTS_QUERY.contains("@keyword"));
100 }
101}