glsl-lang-quote
glsl-lang-quote
offers proc-macros to quote GLSL syntax in Rust, using the [glsl_lang] crate.
Usage
use glsl;
// Parse a translation unit at compile time
let ast = glsl! ;
// There is exactly one external declaration
assert_eq!;
Parsing expressions
This crate offers a set of features quote-expr
, quote-preprocessor
, and quote-statement
.
Enabling those features enable the respective parser-expr
, parser-preprocessor
and
parser-statement
in [glsl_lang], which creates dedicated parsers for those types of GLSL
fragments of the language grammar.
This is the most efficient option for parsing lots of expressions and statements at
compile-time, however this will slow down the initial compilation of glsl-lang-quote
since
the generated parser file in [glsl_lang] will be much larger.
This is why by default, this crate enables the quote-parsable
feature, which uses
[glsl_lang]'s [glsl_lang::parse::Parsable] trait, whose limitations apply. Whichever method you
chose, the following code will work:
use glsl_expr;
// Parse an expression
let ast = glsl_expr! ;
Quoting and stateful lexers
Since [glsl_lang]'s parser has a stateful lexer (to handle the fact that GLSL's grammar is not
context-free), declaring a type (a struct
for example) and using it must happen in the same
macro invocation, otherwise the parser will forget about the previously declared types. The
best is to only parse whole translation units ([glsl!] macro), or parse unambiguous fragments
(such as expressions, but not statements).
use ;
// This is ok:
let ast = glsl! ;
// This will not compile, PointLight can't be parsed as a type name without extra state
let statement = glsl_expr! ;
## Author
Vincent Tavernier <vince.tavernier@gmail.com>
## License
BSD-3-Clause