Skip to content

Commit

Permalink
Fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ncthbrt committed Aug 12, 2024
1 parent e315342 commit 5a25580
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl Default for Composer {
)
.unwrap(),
virtual_fn_regex: Regex::new(
r"(?P<lead>[\s]*virtual\s+fn\s+)(?P<function>[^\s]+)(?P<trail>\s*)\(",
r"(?P<lead>[\s]*)(?P<virtual_keyword>virtual\s+)(?<fn_keyword>fn\s+)(?P<function_name>[^\s]+)(?P<trail>\s*)\(",
)
.unwrap(),
override_fn_regex: Regex::new(
Expand Down Expand Up @@ -858,17 +858,13 @@ impl Composer {
let source = self
.virtual_fn_regex
.replace_all(source, |cap: &regex::Captures| {
let target_function = cap.get(2).unwrap().as_str().to_owned();

let replacement_str = format!(
"{}fn {}{}(",
" ".repeat(cap.get(1).unwrap().range().len() - 3),
target_function,
" ".repeat(cap.get(3).unwrap().range().len()),
);

virtual_functions.insert(target_function);
let function_name = cap.name("function_name").unwrap().as_str();
let lead = cap.name("lead").unwrap().as_str();
let trail = cap.name("trail").unwrap().as_str();
let fn_keyword = cap.name("fn_keyword").unwrap().as_str();

let replacement_str = format!("{lead}{fn_keyword}{function_name}{trail}(");
virtual_functions.insert(function_name.to_string());
replacement_str
});

Expand Down
4 changes: 3 additions & 1 deletion src/compose/tests/overrides/mod.wgsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define_import_path mod

// This is a comment

virtual fn inner(arg: f32) -> f32 {
return arg * 2.0;
}

fn outer() -> f32 {
return inner(1.0);
}
}
3 changes: 2 additions & 1 deletion src/compose/tests/overrides/top.wgsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#import mod

// This is a comment
override fn mod::inner(arg: f32) -> f32 {
return arg * 3.0;
}

fn top() -> f32 {
return mod::outer();
}
}

0 comments on commit 5a25580

Please sign in to comment.