Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved regex so that virtual functions don't fail in certain scenarios #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading