From fec67ced8e2b8737f71893669854c5b58160e7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 14 May 2021 13:19:35 +0100 Subject: [PATCH] [glsl-in] Add support for declaration statements --- src/front/glsl/parser.rs | 14 ++++++++++++-- src/front/glsl/parser_tests.rs | 8 +++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/front/glsl/parser.rs b/src/front/glsl/parser.rs index 4c06dbfb95..18c9bfcb85 100644 --- a/src/front/glsl/parser.rs +++ b/src/front/glsl/parser.rs @@ -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(()) diff --git a/src/front/glsl/parser_tests.rs b/src/front/glsl/parser_tests.rs index b0b6a18b20..b3b1f32e63 100644 --- a/src/front/glsl/parser_tests.rs +++ b/src/front/glsl/parser_tests.rs @@ -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; }