[glsl-new] Add jump statements (#179)

* [glsl-new] Add jump statements

- continue
- break
- return
- discard

* [glsl-new] Fix clippy error for return statement
This commit is contained in:
Pelle Johnsen 2020-09-07 07:28:13 +02:00 committed by GitHub
parent a3bac5ee0f
commit 43bad8ee50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -139,6 +139,11 @@ pub fn consume_token(mut input: &str) -> (Option<Token>, &str) {
// values
"true" => (Some(Token::BoolConstant((meta, true))), rest),
"false" => (Some(Token::BoolConstant((meta, false))), rest),
// jump statements
"continue" => (Some(Token::Continue(meta)), rest),
"break" => (Some(Token::Break(meta)), rest),
"return" => (Some(Token::Return(meta)), rest),
"discard" => (Some(Token::Discard(meta)), rest),
// types
"void" => (Some(Token::Void(meta)), rest),
word => {

View File

@ -53,6 +53,7 @@ pomelo! {
%type simple_statement Statement;
%type expression_statement Statement;
%type declaration_statement Statement;
%type jump_statement Statement;
// expressions
%type unary_expression ExpressionRule;
@ -600,7 +601,7 @@ pomelo! {
//simple_statement ::= switch_statement;
//simple_statement ::= case_label;
//simple_statement ::= iteration_statement;
//simple_statement ::= jump_statement;
simple_statement ::= jump_statement;
compound_statement ::= LeftBrace RightBrace {vec![]}
compound_statement ::= left_brace_scope statement_list(sl) RightBrace {
@ -671,6 +672,21 @@ pomelo! {
type_specifier_nonarray ::= Void { None }
type_specifier_nonarray ::= TypeName(t) {Some(t.1)};
jump_statement ::= Continue Semicolon { Statement::Continue }
jump_statement ::= Break Semicolon { Statement::Break }
jump_statement ::= Return Semicolon { Statement::Return{ value: None } }
jump_statement ::= Return expression(mut e) Semicolon {
let ret = Statement::Return{ value: Some(e.expression) };
if !e.statements.is_empty() {
e.statements.push(ret);
Statement::Block(e.statements)
} else {
ret
}
}
jump_statement ::= Discard Semicolon { Statement::Kill } // Fragment shader only
// Grammar Note: No 'goto'. Gotos are not supported.
// misc
translation_unit ::= external_declaration;
translation_unit ::= translation_unit external_declaration;