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

Incorrect parsing behavior with --preprocess option enabled #310

Open
Lutymane opened this issue May 11, 2023 · 5 comments
Open

Incorrect parsing behavior with --preprocess option enabled #310

Lutymane opened this issue May 11, 2023 · 5 comments

Comments

@Lutymane
Copy link

For some reason if shader doesn't end with an empty line it throws:

System.Exception: Parse error: Error in ./test/s.glsl: Ln: 3 Col: 2
}
 ^
Note: The error occurred at the end of the input stream.
Expecting: any char

   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message)
   at Parse.ParseImpl.runParser(String streamName, String content)
   at ShaderMinifier.minify(Tuple`2[] files)
   at ShaderMinifier.run(String[] files)

Test code:

void main()  {
    gl_FragColor = vec4(1);
}

Notice there's no whitespace after last }

Test command:

./bin/shader_minifier-135.exe ./test/s.glsl -o - --format js --preprocess

Current workaround is just to add a new line at the end of the file

@laurentlb
Copy link
Owner

Thanks for the report!
The flag is very experimental (read: half implemented), so expect other issues. The bug reports will be useful whenever someone works on the feature again (it might take a few months).

@Lutymane
Copy link
Author

@laurentlb I could work on it, but I don't know F# at all 🥲

@laurentlb
Copy link
Owner

If you want, you can write a few more input test files (similar to https://github.com/laurentlb/Shader_Minifier/blob/master/tests/unit/preprocess.frag and https://github.com/laurentlb/Shader_Minifier/blob/master/tests/unit/preprocess_if.frag), without the .expected files.

@Lutymane
Copy link
Author

@laurentlb Yeah, I could perhaps formulate multiple levels of support for preprocessor and case coverage by supplying test shader codes.

Also, I got a question. Does the preprocessor run during the parsing? Because I tried to minify this code:

#define BBB 1

void main() {

  vec4 frag = vec4(1);

  frag.rgb = 
#if BBB
    vec3(1)
#else
    vec3(0)
#endif
  ;

  gl_FragColor = frag;
}

And if failed with:

System.Exception: Parse error: Error in ./test/s.glsl: Ln: 8 Col: 1
#if BBB
^
Expecting: cast, expression or prefix operator

   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message)
   at ShaderMinifier.minify(Tuple`2[] files)
   at ShaderMinifier.run(String[] files)

@laurentlb
Copy link
Owner

It works with #ifdef, not with #if.

At the moment, the condition after #if is not evaluated (except if it's a literal 0 or 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants