{"id":20778078,"url":"https://github.com/stackgl/glsl-parser","last_synced_at":"2025-04-07T09:22:28.841Z","repository":{"id":5569529,"uuid":"6775022","full_name":"stackgl/glsl-parser","owner":"stackgl","description":"transform streamed glsl tokens into an ast","archived":false,"fork":false,"pushed_at":"2024-04-03T20:56:17.000Z","size":47,"stargazers_count":98,"open_issues_count":12,"forks_count":14,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-31T07:09:00.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-11-20T09:08:06.000Z","updated_at":"2024-07-10T20:59:32.000Z","dependencies_parsed_at":"2024-06-18T15:15:29.300Z","dependency_job_id":"dc8ef08c-18bb-41a1-9848-6aedfb806687","html_url":"https://github.com/stackgl/glsl-parser","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fglsl-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fglsl-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fglsl-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fglsl-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackgl","download_url":"https://codeload.github.com/stackgl/glsl-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623100,"owners_count":20968600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T13:19:01.275Z","updated_at":"2025-04-07T09:22:28.808Z","avatar_url":"https://github.com/stackgl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# glsl-parser\n\n![](http://img.shields.io/badge/stability-stable-green.svg?style=flat)\n![](http://img.shields.io/npm/v/glsl-parser.svg?style=flat)\n![](http://img.shields.io/npm/dm/glsl-parser.svg?style=flat)\n![](http://img.shields.io/npm/l/glsl-parser.svg?style=flat)\n\nA GLSL parser that takes tokens from\n[glsl-tokenizer](http://github.com/stackgl/glsl-tokenizer) and turns them into\nan AST.\n\nMay either be used synchronously or as a stream.\n\n## API\n\n### `stream = require('glsl-parser/stream')`\n\nCreates a GLSL parser stream, which emits nodes as they're parsed.\n\n``` javascript\nvar TokenStream = require('glsl-tokenizer/stream')\nvar ParseStream = require('glsl-parser/stream')\nvar fs = require('fs')\n\nfs.createReadStream('test.glsl')\n  .pipe(TokenStream())\n  .pipe(ParseStream())\n  .on('data', function(x) {\n    console.log('ast of', x.type)\n  })\n```\n\n### `ast = stream.program`\n\nThe full program's AST, which will be updated with each incoming token.\n\n### `ast = require('glsl-parser/direct')(tokens)`\n\nSynchronously parses an array of tokens from `glsl-tokenizer`.\n\n``` javascript\nvar TokenString = require('glsl-tokenizer/string')\nvar ParseTokens = require('glsl-parser/direct')\nvar fs = require('fs')\n\nvar src = fs.readFileSync('test.glsl', 'utf8')\nvar tokens = TokenString(src)\nvar ast = ParseTokens(tokens)\n\nconsole.log(ast)\n```\n\n## Nodes\n\n* `stmtlist`\n* `stmt`\n* `struct`\n* `function`\n* `functionargs`\n* `decl`\n* `decllist`\n* `forloop`\n* `whileloop`\n* `if`\n* `expr`\n* `precision`\n* `comment`\n* `preprocessor`\n* `keyword`\n* `ident`\n* `return`\n* `continue`\n* `break`\n* `discard`\n* `do-while`\n* `binary`\n* `ternary`\n* `unary`\n\n## Known Issues\n\n* because i am not smart enough to write a fully streaming parser, the current parser \"cheats\" a bit when it encounters a `expr` node! it actually waits until it has all the tokens it needs to build a tree for a given expression, then builds it and emits the constituent child nodes in the expected order. the `expr` parsing is heavily influenced by [crockford's tdop article](http://javascript.crockford.com/tdop/tdop.html). the rest of the parser is heavily influenced by fever dreams.\n\n* the parser might hit a state where it's looking at what *could be* an expression, or it could be a declaration --\nthat is, the statement starts with a previously declared `struct`. it'll opt to pretend it's a declaration, but that\nmight not be the case -- it might be a user-defined constructor starting a statement!\n\n* \"unhygenic\" `#if` / `#endif` macros are completely unhandled at the moment, since they're a bit of a pain.\nif you've got unhygenic macros in your code, move the #if / #endifs to statement level, and have them surround\nwholly parseable code. this sucks, and i am sorry.\n\n## License\n\nMIT, see [LICENSE.md](LICENSE.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fglsl-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackgl%2Fglsl-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fglsl-parser/lists"}