alixinne / glsl-lang

LALR parser for GLSL
https://alixinne.github.io/glsl-lang/glsl_lang/
BSD 3-Clause "New" or "Revised" License
24 stars 4 forks source link

literal scalar swizzling #58

Open hhirtz opened 3 days ago

hhirtz commented 3 days ago

Using lexer-v2-full on 0.5.2 and 0.7.1 glsl-lang throws an InvalidFloatLitteral error on float litteral followed by a swizzle:

use glsl_lang::ast;
use glsl_lang::parse::DefaultParse;
use std::error::Error;

const GLSL: &str = "
void main() {
    FragColor = 1.0.xxxx; // same as vec4(1.0)
}
";

fn main() -> Result<(), Box<dyn Error>> {
    let frag = ast::TranslationUnit::parse(GLSL)?;
    Ok(())
}

https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling

Code in the wild i wanted to parse: https://github.com/libretro/slang-shaders/blob/cc84cf9ac3c6004ad248216f47906fd33bf087d8/crt/shaders/guest/advanced/pre-shaders-afterglow.slang#L226

Not sure if it's because i'm using the wrong crate features or i need a subparser, but it only throws an error when the scalar is a literal.

alixinne commented 2 days ago

This is an interesting way of constructing a vec4 for sure. It's definitely a bug, this should parse correctly. Thanks for bringing this up and providing an example of it in the wild, I'll look into it!