Expand description
This crate provides GLSL language support for the [tree-sitter] parsing library.
Typically, you will use the LANGUAGE constant to add this language to a
tree-sitter Parser, and then use the parser to parse some code:
let code = r#"
void fragment_shader() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
"#;
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_glsl_spec::LANGUAGE;
parser
.set_language(&language.into())
.expect("Error loading GLSL parser");
let tree = parser.parse(code, None).unwrap();
assert!(!tree.root_node().has_error());Constants§
- CONSTRUCTOR_
HEURISTICS_ QUERY - Constructor heuristic query. Identifies function calls where the callee is a user-defined type name (capitalized identifier), which are likely struct constructors. Opt-in — not included in default highlighting.
- HIGHLIGHTS_
QUERY - Syntax highlighting query. Maps GLSL nodes to highlight capture names
(
@keyword,@function,@type,@operator,@variable, etc.). Includes built-in function/variable/constant recognition. - INJECTIONS_
QUERY - Language injection query. Identifies
#ifdef __cplusplus/#ifdef __STDC__guard blocks and marks their foreign-language content for injection (cpporc). - LANGUAGE
- The tree-sitter
LanguageFnfor this grammar. - LOCALS_
QUERY - Local variable tracking query. Defines scopes (functions, blocks, loops) and tracks identifier definitions and references within them.
- NODE_
TYPES - The content of the
node-types.jsonfile for this grammar. - TAGS_
QUERY - Tags query for code navigation. Captures function definitions, type definitions, variable declarations, function calls, and type references.
- VERSION_
TAGS_ QUERY - Version tags query. Captures GLSL constructs whose availability depends
on a minimum
#version(e.g.,uintrequires 130,doublerequires 400). Intended for post-parse validation, not syntax highlighting.