[glsl-in] Add support for declaration statements

This commit is contained in:
João Capucho authored and Dzmitry Malyshau committed 2021-05-19 16:24:26 -04:00
1 parent 168a55396c
commit fec67ced8e
2 files changed
+15 -7

No files matched your search

+12 -2
View File
@@ -1130,20 +1130,30 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
ctx.remove_current_scope();
body.push(Statement::Block(block));
}
// TODO: We should also add TypeName here because this is valid
// ```glsl
// vec4(1.0);
// ```
// But this would require us to add lookahead to also support
// declarations and since this statement is very unlikely and most
// likely an error, for now we don't support it
TokenValue::Plus
| TokenValue::Dash
| TokenValue::Bang
| TokenValue::Tilde
| TokenValue::LeftParen
| TokenValue::Identifier(_)
| TokenValue::TypeName(_)
| TokenValue::IntConstant(_)
| TokenValue::BoolConstant(_)
| TokenValue::FloatConstant(_) => {
self.parse_expression(ctx)?;
self.expect(TokenValue::Semicolon)?;
}
_ => {}
_ => {
if self.peek_type_name() || self.peek_type_qualifier() {
self.parse_declaration(ctx, body, false)?;
}
}
}
Ok(())
+3 -5
View File
@@ -116,10 +116,9 @@ fn control_flow() {
let _program = parse_program(
r#"
# version 450
int x;
int y;
void main() {
int x;
int y = 3;
switch (5) {
case 2:
x = 2;
@@ -138,9 +137,8 @@ fn control_flow() {
let _program = parse_program(
r#"
# version 450
int x;
void main() {
int x = 0;
while(x < 5) {
x = x + 1;
}