#GLSL #OpenGL #SPIR-V #parser #proc-macro

nightly macro glsl-quasiquote

The glsl! procedural macro, providing quasiquoting of the glsl crate

7 releases

0.3.1 Dec 8, 2018
0.3.0 Nov 21, 2018
0.2.2 Nov 11, 2018
0.2.0 Oct 21, 2018
0.1.1 Oct 10, 2018

#98 in Parsing tools

Download history 38/week @ 2018-11-07 29/week @ 2018-11-14 54/week @ 2018-11-21 18/week @ 2018-11-28 27/week @ 2018-12-05 19/week @ 2018-12-12 11/week @ 2018-12-19 57/week @ 2018-12-26 1/week @ 2019-01-02 13/week @ 2019-01-09 6/week @ 2019-01-16 11/week @ 2019-01-23 5/week @ 2019-01-30

110 downloads per month

BSD-3-Clause

296KB
6.5K SLoC

GLSL 450 quasiquoting.

crates.io

This crate exports a procedural macro: glsl!. It enables quasiquoting by allowing you to embed GLSL source code directly into Rust. Feel free to head over the official documentation for further details and examples.


lib.rs:

GLSL quasiquoting.

This crate exports a procedural macro: glsl!. It enables quasiquoting by allowing you to embed GLSL source code directly into rust via the syntax:

glsl!{
  // your GLSL code here
  void main() {
  }
}

The glsl! macro accepts the GLSL code directly. You can then write plain GLSL. Especially, since version 0.2, the macro accepts plain GLSL pragmas (both #version and #extension).

The glsl! procedural macro resolves at compile-time to glsl::syntax::TranslationUnit, allowing you to manipulate the GLSL AST directly. Feel free to have a look at the glsl crate for further information.

Getting started

Add the following to your dependencies in your Cargo.toml:

glsl = "0.11"
glsl-quasiquote = "0.2"

Then, you currently need to have a nightly compiler and the following feature enabled:

#![feature(proc_macro_hygiene)]

Then, depending on which you’re using the 2018 edition or not:

Non-2018 edition

extern crate glsl;
#[macro_use] extern crate glsl_quasiquote;

2018 edition

extern crate glsl;
use glsl_quasiquote::glsl;

Special warnings and considerations

Because of the nature of the Rust tokenizer, dots (.) at the beginning of a token is not part of the token. For instance, .3 is reinterpreted as . and 3 (two tokens). This will lead to incorrect parsing if you try to represent the number 0.3 with .3. While accepted by glsl, this is not accepted by this crate. This limitation is due to how Rust tokenizes input in procedural macro and is very unlikely to change.

Dependencies