[wgsl] support simple block statements

This commit is contained in:
Dzmitry Malyshau authored and Timo de Kort committed 2021-01-27 21:31:04 +01:00
1 parent 61fd868a22
commit 3e4cb21b90
2 files changed
+25

No files matched your search

+11
View File
@@ -1557,6 +1557,17 @@ impl Parser {
) -> Result<Option<crate::Statement>, Error<'a>> {
let word = match lexer.next() {
Token::Separator(';') => return Ok(None),
Token::Paren('{') => {
self.scopes.push(Scope::Block);
let mut statements = Vec::new();
while !lexer.skip(Token::Paren('}')) {
let s = self.parse_statement(lexer, context.reborrow())?;
statements.extend(s);
}
self.scopes.pop();
let block = crate::Statement::Block(statements);
return Ok(Some(block));
}
Token::Word(word) => word,
other => return other.unexpected("statement"),
};
+14
View File
@@ -73,6 +73,20 @@ fn parse_standard_fun() {
.unwrap();
}
#[test]
fn parse_statement() {
parse_str(
"
fn main() {
;
{}
{;}
}
",
)
.unwrap();
}
#[test]
fn parse_if() {
parse_str(