glsl icon indicating copy to clipboard operation
glsl copied to clipboard

Parsing comments?

Open mitchmindtree opened this issue 5 years ago • 7 comments

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?

mitchmindtree avatar Mar 22 '20 14:03 mitchmindtree

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

hadronized avatar Mar 22 '20 15:03 hadronized

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?

mitchmindtree avatar Mar 22 '20 16:03 mitchmindtree

Hm. Which form your input string has?

hadronized avatar Mar 22 '20 16:03 hadronized

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 :)

mitchmindtree avatar Mar 22 '20 16:03 mitchmindtree

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.

hadronized avatar Mar 22 '20 18:03 hadronized

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

mitchmindtree avatar Mar 22 '20 18:03 mitchmindtree

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

pema99 avatar Jun 10 '21 23:06 pema99