[glsl-in] Add support for declaration statements

This commit is contained in:
João Capucho
2021-05-14 13:19:35 +01:00
committed by Dzmitry Malyshau
parent 168a55396c
commit fec67ced8e
2 changed files with 15 additions and 7 deletions

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(())

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;
}