-
Notifications
You must be signed in to change notification settings - Fork 193
"Expected separator" on hex literal #866
Comments
The error could have been more clear... WGSL doesn't know what |
I don't think u8 is the issue here, I got the same error when using u32. I currently run whatever naga version that's used within wgpu 8.1. I've tested with latest naga master now and get the same issue when testing with u32 instead of u8. |
oh it doesn't expect the |
Even without the |
I also stumbled across this across this wanting a hexadecimal My code let test: u32 = 0x0u; gets me the following error
I suppose similar to the above issues, Here are some test cases for all integer and float literals that match the spec (and their current errors for those that fail): // Regexes for the literals are taken from the working draft at
// https://www.w3.org/TR/2021/WD-WGSL-20210806/#literals
// matches for /^(-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?$/
let dec_float_lit_0 : f32 = -1.;
let dec_float_lit_1 : f32 = -.1;
let dec_float_lit_2 : f32 = 42.1234;
let dec_float_lit_3 : f32 = -1.E3;
let dec_float_lit_4 : f32 = -.1e-5;
let dec_float_lit_5 : f32 = 2.3e+55; // fails "expected floating-point literal, found `2.3e`"
// matches for /^-?0x([0-9a-fA-F]*\.?[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)(p|P)(\+|-)?[0-9]+$/
let hex_float_lit_0 : f32 = -0xa.p1; // fails "the type of `hex_float_lit_0` is expected to be [1]"
let hex_float_lit_1 : f32 = -0x.fp9; // fails "the type of `hex_float_lit_1` is expected to be [1]"
let hex_float_lit_2 : f32 = 0x2a.4D2P4; // fails "the type of `hex_float_lit_2` is expected to be [1]"
let hex_float_lit_3 : f32 = -0x.1p-5; // fails "the type of `hex_float_lit_3` is expected to be [1]"
let hex_float_lit_4 : f32 = 0xC.8p+55; // fails "the type of `hex_float_lit_4` is expected to be [1]"
let hex_float_lit_5 : f32 = 0x1p1; // fails "the type of `hex_float_lit_5` is expected to be [1]"
// matches for /^-?0x[0-9a-fA-F]+|0|-?[1-9][0-9]*$/
let int_lit_0 : i32 = -0x0; // fails "expected ';', found 'x0'"
let int_lit_1 : i32 = 0;
let int_lit_2 : i32 = 0x2a4D2; // fails "expected ';', found 'x2a4D2'"
let int_lit_3 : i32 = 1092;
let int_lit_4 : i32 = -9923;
// matches for /^0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u$/
let uint_lit_0 : u32 = 0x0u; // fails "the type of `uint_lit_0` is expected to be [1]"
let uint_lit_1 : u32 = 0u;
let uint_lit_2 : u32 = 0x2a4D2u; // fails "the type of `uint_lit_2` is expected to be [1]"
let uint_lit_3 : u32 = 1092u; Also note that the current draft of the specification does not allow for the let dec_float_lit_6 : f32 = 1.337e-42f; The relevant piece of code seems to be this: Lines 16 to 58 in 07c2862
I imagine it will be rather hard to write a compliant lexer for these literals formats with the current approach. |
At present, this validates fine:
The original program, with
Naga correctly identifies the type mismatch between
So I think this is fixed. If not, feel free to re-open this bug. |
Hello again, I ran into another issue with my glsl -> wgsl conversion. Wgsl doesn't seem to accept any of the following:
let mask: u8 = 0xFFu;
let mask: u8 = 0xFF;
Both gives the following error even though the values matches the regex in the specification:
The text was updated successfully, but these errors were encountered: