hadronized / glsl

GLSL parser for Rust
190 stars 28 forks source link

Parsing comments? #116

Open mitchmindtree opened 4 years ago

mitchmindtree commented 4 years ago

Thanks so much for this crate @phaazon :)

I was planning on using this along with a json crate to create a small lib for parsing ISF aka Interactive Shader Format files and generating the GLSL they require. Unfortunately, they declare their JSON blob in a top-level comment! Would you have any interest in seeing a Comment variant added to the syntax tree somehow? If so, how would one go about doing this?

hadronized commented 4 years ago

Comments are currently already supported. Can you explain more about your problem? :)

mitchmindtree commented 4 years ago

Oh my mistake! Then I guess my question should be - how do I go about using glsl to find a comment block (e.g. /* */) and then retrieve the contents of a comment block as a string?

hadronized commented 4 years ago

Hm. Which form your input string has?

mitchmindtree commented 4 years ago

Here's a single example of the kind of file I'm trying to parse:

/*{
    "DESCRIPTION": "demonstrates the use of multiple image-type inputs",
    "CREDIT": "by zoidberg",
    "ISFVSN": "2.0",
    "CATEGORIES": [
        "TEST-GLSL FX"
    ],
    "INPUTS": [
        {
            "NAME": "inputImage",
            "TYPE": "image"
        }
    ],
    "IMPORTED": {
        "blendImage": {
            "PATH": "Hexagon.tiff"
        }
    }
}*/

void main()
{
    vec4        srcPixel = IMG_NORM_PIXEL(inputImage, isf_FragNormCoord);
    vec4        blendPixel = IMG_NORM_PIXEL(blendImage, isf_FragNormCoord);

    gl_FragColor = (srcPixel + blendPixel)/2.0;
}

I'd like to be able to retrieve the contents of the top comment as a str so that I can then decode it with serde_json.

At the moment I'm manually searching for /* and then the accompanying */, and then I grab the str in the middle. It seems to be working for the 100 test files they have so I'm OK with it for now, but it would be nice to use glsl for a more "robust" approach :)

hadronized commented 4 years ago

Hm. Currently, it’s a bit hard because comments are simply discarded by the space parser. However, I have a pretty similar problem with preprocessor directives.

I’ll try to come up with a solution to this as soon as possible.

mitchmindtree commented 4 years ago

No rush/pressure at all, and thanks so much for your prompt response and all your work! :heart:

pema99 commented 3 years ago

I'm having this issue as well, any news?