An Elm package that implements a GLSL (OpenGL Shading Language) parser, inspired by the Haskell GLSL parser. This library allows you to parse GLSL shader code into Elm data structures, enabling further manipulation, analysis, or code generation.
To install the package, run the following:
elm install guida-lang/glsl
Here’s an example of how to use the GLSL parser in Elm:
import Language.GLSL.Parser as Parser
import Language.GLSL.Syntax as Syntax
shaderSource : String
shaderSource =
"""
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
"""
parseResult : Result String Syntax.TranslationUnit
parseResult =
Parser.parse shaderSource
The parse
function attempts to parse a GLSL shader string and returns a Result
:
Ok Syntax.TranslationUnit
: If the shader was parsed successfully, it returns an abstract syntax tree (AST) representing the GLSL code.Err { position : Int, messages : List String }
: If parsing failed, it returns an error object describing the position where the error occurs, and a list of error messages.
case parseResult of
Ok shader ->
-- Do something with the parsed shader
Debug.log "Parsed successfully!" shader
Err error ->
Debug.log "Failed to parse shader:" error
For full API documentation and more examples, please visit the Elm package documentation.
Contributions are welcome! If you have ideas for improvements or find bugs, feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new feature branch.
- Commit your changes.
- Submit a pull request.