use tree_sitter_language::LanguageFn;
extern "C" {
fn tree_sitter_objectscript_routine() -> *const ();
}
pub const LANGUAGE_OBJECTSCRIPT_ROUTINE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_objectscript_routine) };
pub const NODE_TYPES: &str = include_str!("objectscript_routine/src/node-types.json");
pub const HIGHLIGHTS_QUERY: &str = include_str!("objectscript_routine/queries/highlights.scm");
pub const STUDIO_HIGHLIGHTS_QUERY: &str = include_str!("objectscript_routine/queries/studio-highlights.scm");
pub const INJECTIONS_QUERY: &str = include_str!("objectscript_routine/queries/injections.scm");
pub const INDENTS_QUERY: &str = include_str!("objectscript_routine/queries/indents.scm");
#[cfg(test)]
mod tests {
use tree_sitter::{Parser, Point, Node};
pub fn dump(node: Node, depth: usize) {
let indent = " ".repeat(depth);
let start = node.start_position();
let end = node.end_position();
println!(
"{}{} [{}, {}] - [{}, {}]",
indent,
node.kind(),
start.row,
start.column,
end.row,
end.column
);
let mut cursor = node.walk();
for child in node.named_children(&mut cursor) {
dump(child, depth + 1);
}
}
fn parse_cls(code: &str) -> tree_sitter::Tree {
let mut parser = Parser::new();
parser
.set_language(&super::LANGUAGE_OBJECTSCRIPT_ROUTINE.into())
.expect("failed to load objectscript routine grammar");
parser.parse(code, None).expect("parse returned None")
}
#[test]
fn test_can_load_objectscript_routine_grammar() {
let source = r#"ROUTINE x
heyyy() methodimpl {
w "hi"
set x = 2
if x {
w "bye"
q
}
}
"#;
let tree = parse_cls(source);
dump(tree.root_node(), 0);
}
#[test]
fn test_indents_query_is_loaded() {
assert!(super::INDENTS_QUERY.contains("indent"));
}
#[test]
fn test_injections_query_is_loaded() {
assert!(super::INJECTIONS_QUERY.contains("injection"));
}
#[test]
fn test_highlights_query_is_loaded() {
assert!(super::HIGHLIGHTS_QUERY.contains("@keyword"));
}
}