12 releases

0.5.2 Nov 13, 2023
0.5.1 Apr 27, 2023
0.4.1 Sep 5, 2022
0.3.1 Jul 3, 2022
0.1.3 Apr 16, 2021

#364 in Parser implementations

Download history 12/week @ 2023-12-23 9/week @ 2024-01-13 6/week @ 2024-01-20 6/week @ 2024-01-27 4/week @ 2024-02-10 46/week @ 2024-02-17 74/week @ 2024-02-24 13/week @ 2024-03-02 33/week @ 2024-03-09 48/week @ 2024-03-16 14/week @ 2024-03-23

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

BSD-3-Clause

690KB
17K 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

Vincent Tavernier vince.tavernier@gmail.com

License

BSD-3-Clause

Dependencies

~3–11MB
~92K SLoC