glsl-tokenizer ![Build Status](https://camo.githubusercontent.com/5de7d732e936cd98c85c9b5906abdc936e7eafdd80427647fe133d8711b747e9/68747470733a2f2f7472617669732d63692e6f72672f676c736c6966792f676c736c2d746f6b656e697a65722e7376673f6272616e63683d6d6173746572)
Maps GLSL string data into GLSL tokens, either synchronously or using a streaming API.
var tokenString = require('glsl-tokenizer/string')
var tokenStream = require('glsl-tokenizer/stream')
var fs = require('fs')
// Synchronously:
var tokens = 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)
})
API
tokens = require('glsl-tokenizer/string')(src, [opt])
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).
var tokens = tokenizer(src, {
version: '300 es'
})
stream = require('glsl-tokenizer/stream')([opt])
Emits 'data' events whenever a token is parsed with a token object as output.
As above, you can specify opt.version
.
Tokens
{ 'type': TOKEN_TYPE
, 'data': "string of constituent data"
, 'position': integer position within the GLSL source
, 'line': line number within the GLSL source
, 'column': column number within the GLSL source }
The available token types are:
block-comment
:/* ... */
line-comment
:// ... \n
preprocessor
:# ... \n
operator
: Any operator. If it looks like punctuation, it's an operator.float
: Optionally suffixed withf
ident
: User defined identifier.builtin
: Builtin function.eof
: Emitted onend
; data will ==='(eof)'
.integer
whitespace
keyword
License
MIT, see LICENSE.md for further information.