mirror of
https://github.com/storytold/wgpu.git
synced 2026-12-01 10:34:57 +01:00
[wgsl] support simple block statements
This commit is contained in:
1 parent
61fd868a22
commit
3e4cb21b90
2 files changed
+25
No files matched your search
@@ -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"),
|
||||
};
|
||||
|
||||
@@ -73,6 +73,20 @@ fn parse_standard_fun() {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_statement() {
|
||||
parse_str(
|
||||
"
|
||||
fn main() {
|
||||
;
|
||||
{}
|
||||
{;}
|
||||
}
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_if() {
|
||||
parse_str(
|
||||
|
||||
Reference in new issue
Block a user