stackgl / glsl-parser

transform streamed glsl tokens into an ast
MIT License
98 stars 15 forks source link

glsl-parser

A GLSL parser that takes tokens from glsl-tokenizer and turns them into an AST.

May either be used synchronously or as a stream.

API

stream = require('glsl-parser/stream')

Creates a GLSL parser stream, which emits nodes as they're parsed.

var TokenStream = require('glsl-tokenizer/stream')
var ParseStream = require('glsl-parser/stream')
var fs = require('fs')

fs.createReadStream('test.glsl')
  .pipe(TokenStream())
  .pipe(ParseStream())
  .on('data', function(x) {
    console.log('ast of', x.type)
  })

ast = stream.program

The full program's AST, which will be updated with each incoming token.

ast = require('glsl-parser/direct')(tokens)

Synchronously parses an array of tokens from glsl-tokenizer.

var TokenString = require('glsl-tokenizer/string')
var ParseTokens = require('glsl-parser/direct')
var fs = require('fs')

var src = fs.readFileSync('test.glsl', 'utf8')
var tokens = TokenString(src)
var ast = ParseTokens(tokens)

console.log(ast)

Nodes

Known Issues

License

MIT, see LICENSE.md for more details.