19 releases

0.7.2 Nov 22, 2024
0.6.1 Oct 1, 2024
0.5.3 Jul 23, 2024
0.5.2 Nov 13, 2023
0.1.3 Apr 16, 2021

#331 in Rendering

Download history 323/week @ 2024-08-17 79/week @ 2024-08-24 14/week @ 2024-08-31 20/week @ 2024-09-07 72/week @ 2024-09-14 50/week @ 2024-09-21 250/week @ 2024-09-28 43/week @ 2024-10-05 36/week @ 2024-10-12 9/week @ 2024-10-19 21/week @ 2024-10-26 44/week @ 2024-11-02 267/week @ 2024-11-09 128/week @ 2024-11-16 78/week @ 2024-11-23 37/week @ 2024-11-30

516 downloads per month
Used in 5 crates (4 directly)

BSD-3-Clause

750KB
18K SLoC

glsl-lang

Crates.io docs.rs

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.

Examples

Parsing GLSL

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());

Crate features

This crate has the following features:

  • parser-expr: generate parser code for parsing GLSL expressions
  • parser-statement: generate parser code for parsing GLSL statements

None 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());

Author

Alixinne alixinne@pm.me

License

BSD-3-Clause

Dependencies

~2.3–9MB
~82K SLoC