Git Product home page Git Product logo

glsl-man's Introduction

GLSL manipulator

GLSL parser and code generator based on Google's glsl-unit grammar.

NPM

Install

npm install glsl-man

Usage

Parsing

var glsl = require('glsl-man');
var ast = glsl.parse(source);

Deparsing

var glsl = require('glsl-man');
var ast = glsl.parse(source);
var generated = glsl.string(ast);

Querying

var glsl = require('glsl-man');
var ast = glsl.parse(source);
var uniforms = glsl.query.all(
	ast,
	glsl.query.selector('declarator[typeAttribute] > type[qualifier=uniform]'));

API

Parsing

  • glsl.parse(string) - Generates AST from GLSL
    • string - GLSL source code

Deparsing

  • glsl.string(ASTNode, options) - Generates GLSL from AST
    • ASTNode - Any node from the tree returned by parse(string)
    • options - The default options are described below:
	{
		tab: '\t',       // Character used for tab
		space: ' ',      // Character used for space
		newline: '\n',   // Character used for newlines

		// The following should not be altered to produce valid GLSL
		terminator: ';', // Character used to terminate a statement
		comma: ','       // Character used for comma
	}
  • glsl.wrap(ASTNode) - Wraps the given node in a 'root' scope. Useful for generating valid code from arbitrary AST subnodes.
    • ASTNode - Any node from the tree returned by parse(string)

Querying

  • glsl.query.selector(string) - Returns a selector

  • glsl.query.all(node, selector, matches) - Searches the tree depth first and returns all nodes that match the selector

    • node - AST node
    • selector - The selector to test against
    • matches - Array to store matched nodes (optional)
  • glsl.query.first(node, selector) - Searches the tree depth first and returns the first node that matches the selector

    • node - AST node
    • selector - The selector to test against
  • glsl.query.children(node, selector, matches) - Searches only the immediate subnodes of the given node and returns all children that match the selector

    • node - AST node
    • selector - The selector to test against
    • matches - Array to store matched nodes (optional)
  • glsl.query.firstChild(node, selector) - Searches only the immediate subnodes of the given node and returns the first node that matches the selector

    • node - AST node
    • selector - The selector to test against
  • glsl.query.subnodes(node) - Returns a list of all subnodes of the given node that can be further traversed

    • node - AST node

Modifying

  • glsl.mod.find(node) - Returns an object with index and statements keys.

    • node - AST node
  • glsl.mod.remove(node) - Removes the given node from it's AST.

    • node - AST node
  • glsl.mod.replace(node, newNode) - Replaces the given node with newNode.

    • node - AST node
    • newNode - AST node or Array of AST nodes
  • glsl.mod.add(node, newNode, after) - Inserts newNode before or after node.

    • node - AST node
    • newNode - AST node or Array of AST nodes
    • after - (optional) Boolean
  • glsl.mod.addBefore(node, newNode) - Shortcut to glsl.mod.add.

  • glsl.mod.addAfter(node, newNode) - Shortcut to glsl.mod.add.

glsl-man's People

Contributors

lammas avatar yofreke avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.