mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Fix parsing of function calls
This commit is contained in:
committed by
Dzmitry Malyshau
parent
4e40a75843
commit
d310cff591
@@ -828,23 +828,40 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_function_call_args(
|
||||
&mut self,
|
||||
ctx: &mut Context,
|
||||
meta: &mut TokenMetadata,
|
||||
) -> Result<Vec<Expr>> {
|
||||
let mut args = Vec::new();
|
||||
if let Some(token) = self.bump_if(TokenValue::RightParen) {
|
||||
*meta = meta.union(&token.meta);
|
||||
} else {
|
||||
loop {
|
||||
args.push(self.parse_assignment(ctx)?);
|
||||
|
||||
let token = self.bump()?;
|
||||
match token.value {
|
||||
TokenValue::Comma => {}
|
||||
TokenValue::RightParen => {
|
||||
*meta = meta.union(&token.meta);
|
||||
break;
|
||||
}
|
||||
_ => return Err(ErrorKind::InvalidToken(token)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(args)
|
||||
}
|
||||
|
||||
fn parse_postfix(&mut self, ctx: &mut Context) -> Result<Expr> {
|
||||
let mut expr = match self.expect_peek()?.value {
|
||||
TokenValue::Identifier(_) => {
|
||||
let (name, mut meta) = self.expect_ident()?;
|
||||
|
||||
if self.bump_if(TokenValue::LeftParen).is_some() {
|
||||
let mut args = Vec::new();
|
||||
loop {
|
||||
let token = self.bump()?;
|
||||
|
||||
if let TokenValue::RightParen = token.value {
|
||||
meta = meta.union(&token.meta);
|
||||
break;
|
||||
}
|
||||
|
||||
args.push(self.parse_expression(ctx)?)
|
||||
}
|
||||
let args = self.parse_function_call_args(ctx, &mut meta)?;
|
||||
|
||||
Expr {
|
||||
kind: ExprKind::Call(FunctionCall {
|
||||
@@ -875,18 +892,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
};
|
||||
|
||||
self.expect(TokenValue::LeftParen)?;
|
||||
|
||||
let mut args = Vec::new();
|
||||
loop {
|
||||
let token = self.bump()?;
|
||||
|
||||
if let TokenValue::RightParen = token.value {
|
||||
meta = meta.union(&token.meta);
|
||||
break;
|
||||
}
|
||||
|
||||
args.push(self.parse_expression(ctx)?)
|
||||
}
|
||||
let args = self.parse_function_call_args(ctx, &mut meta)?;
|
||||
|
||||
Expr {
|
||||
kind: ExprKind::Call(FunctionCall {
|
||||
|
||||
@@ -218,6 +218,15 @@ fn declarations() {
|
||||
&entry_points,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let _program = parse_program(
|
||||
r#"
|
||||
#version 450
|
||||
float vector = vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0);
|
||||
"#,
|
||||
&entry_points,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -338,6 +347,23 @@ fn functions() {
|
||||
),
|
||||
"SemanticError(\"Function already defined\")"
|
||||
);
|
||||
|
||||
println!();
|
||||
|
||||
// Nested function call
|
||||
let _program = parse_program(
|
||||
r#"
|
||||
# version 450
|
||||
layout(set = 0, binding = 1) uniform texture2D t_noise;
|
||||
layout(set = 0, binding = 2) uniform sampler s_noise;
|
||||
|
||||
void main() {
|
||||
textureLod(sampler2D(t_noise, s_noise), vec2(1.0), 0);
|
||||
}
|
||||
"#,
|
||||
&entry_points,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user