Maps GLSL string data into GLSL tokens, either synchronously or using a streaming API.
vartokenString=require('glsl-tokenizer/string')vartokenStream=require('glsl-tokenizer/stream')varfs=require('fs')// Synchronously:vartokens=tokenString(fs.readFileSync('some.glsl'))// Streaming API:fs.createReadStream('some.glsl').pipe(tokenStream()).on('data',function(token){console.log(token.data,token.position,token.type)})Returns an array of tokens given the GLSL source string src
You can specify opt.version string to use different keywords/builtins, such as '300 es' for WebGL2. Otherwise, will assume GLSL 100 (WebGL1).
vartokens=tokenizer(src,{version: '300 es'})Emits 'data' events whenever a token is parsed with a token object as output.
As above, you can specify opt.version.
{'type': TOKEN_TYPE,'data': "string of constituent data",'position': integerpositionwithintheGLSLsource,'line': linenumberwithintheGLSLsource,'column': columnnumberwithintheGLSLsource}The available token types are:
block-comment:/* ... */line-comment:// ... \npreprocessor:# ... \noperator: Any operator. If it looks like punctuation, it's an operator.float: Optionally suffixed withfident: User defined identifier.builtin: Builtin function.eof: Emitted onend; data will ==='(eof)'.integerwhitespacekeyword
MIT, see LICENSE.md for further information.