mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-12-01 03:03:26 +00:00
[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:
parent
a3bac5ee0f
commit
43bad8ee50
@ -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 => {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user