glsl-token-macros
Extract macro preprocessor statements from an array of GLSL tokens from glsl-tokenizer.
Parses out the macro name, arguments (if present) and contents.
Usage
macros = tokenMacros(tokens)
Given an array of tokens
produced by glsl-tokenizer, return an array of macro data in the following format:
name: 'MACRO_NAME'args: 'a' 'b'value: '(a * 0.5 + 0.5)'index: 2token:type: 'preprocessor'data: '#define MACRO_NAME(a, b) (a * 0.5 + 0.5)'
macro.name
The macro name. For example, #define HELLO_WORLD
would result in HELLO_WORLD
.
macro.args
The arguments supplied to the macro. If the macro has no arguments, this will be false. Note that 0 arguments will result in an empty array. For example:
const tokenMacros =const toString =const tokenize =const src = `#define HELLO_WORLD a#define LOREM_IPSUM() a#define BOGAN_IPSUM(a) (a * 0.5 + 0.5)#define SOME_OTHERS(a, b) (a * 0.5 + b)`const tokens =const macros =console // falseconsole // []console // ["a"]console // ["a", "b"]
macro.value
The macro value. If no value is supplied, this will be an empty string. For example:
const tokenMacros =const toString =const tokenize =const src = `#define HELLO_WORLD#define LOREM_IPSUM() a#define BOGAN_IPSUM(a) (a * 0.5 + 0.5)#define SOME_OTHERS(a, b) (a * 0.5 + b)`const tokens =const macros =console // ""console // "a"console // "(a * 0.5 + 0.5)"console // "(a * 0.5 + b)"
macro.token
The original preprocessor token object from the token list.
macro.index
The index of the original preprocessor token object within the token list.
Contributing
See stackgl/contributing for details.
License
MIT. See LICENSE.md for details.