Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing comments? #116

Open
mitchmindtree opened this issue Mar 22, 2020 · 7 comments
Open

Parsing comments? #116

mitchmindtree opened this issue Mar 22, 2020 · 7 comments
Labels
question & discussion A question or a discussion about a topic

Comments

@mitchmindtree
Copy link

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
Copy link
Owner

hadronized commented Mar 22, 2020

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

@mitchmindtree
Copy link
Author

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
Copy link
Owner

Hm. Which form your input string has?

@hadronized hadronized added the question & discussion A question or a discussion about a topic label Mar 22, 2020
@mitchmindtree
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@pema99
Copy link

pema99 commented Jun 10, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question & discussion A question or a discussion about a topic
Projects
None yet
Development

No branches or pull requests

3 participants