Crates.io | glsl-lang |
lib.rs | glsl-lang |
version | 0.7.2 |
source | src |
created_at | 2021-04-04 23:12:25.951418 |
updated_at | 2024-11-22 12:05:44.605251 |
description | GLSL 4.6 language LALR parser and AST |
homepage | https://github.com/alixinne/glsl-lang |
repository | https://github.com/alixinne/glsl-lang |
max_upload_size | |
id | 379047 |
size | 370,394 |
glsl-lang
is a crate implementing a LALR parser for the GLSL 4.x language,
with partial support for preprocessor directives. Its AST and features are
modeled after Dimitri Sabadie's glsl
crate.
See the homepage for more detailed comparison elements.
use glsl_lang::{ast, parse::DefaultParse};
// Some GLSL source to parse
let source = r#"void main() {
gl_FragColor = vec4(1., 0.5, 0.25, 1.);
}"#;
// Try parsing the source
let ast = ast::TranslationUnit::parse(source);
assert!(ast.is_ok());
This crate has the following features:
parser-expr
: generate parser code for parsing GLSL expressionsparser-statement
: generate parser code for parsing GLSL statementsNone of these features are enabled by default, as they significantly increase the compile
times. As an alternative, you may use the Parsable
trait, which
wraps grammar rules in suitable source and matches the result to extract the part of the AST
we're interested in.
// parse::Parse is not implemented for ast::Expr with the default features
use glsl_lang::{ast, parse::Parsable};
let source = "a = b ? 1.0 : 0.0";
// Parse with Parsable::parse
let ast = ast::Expr::parse(source);
assert!(ast.is_ok());
Alixinne alixinne@pm.me
BSD-3-Clause