Skip to content

Commit

Permalink
Revert "Implement rust-style #import"
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeoc2001 authored Jul 19, 2024
1 parent b57dd20 commit cd69e5d
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ use crate::{
};

lazy_static::lazy_static! {
static ref IMPORT_CUSTOM_PATH_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+\.wgsl)").unwrap();
static ref IMPORT_CUSTOM_PATH_AS_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+\.wgsl)\s+as\s+([^\s]+)").unwrap();
static ref IMPORT_ITEMS_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+\.wgsl)\s+([^\s]+(?:\s*,\s*[^\s]+)*)").unwrap();
static ref IMPORT_SINGLE_ITEM_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+\.wgsl)\s*::\s*([^\s]+)").unwrap();
static ref IMPORT_ITEMS_BRACKETS_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+\.wgsl)\s*::\s*\{\s*([^\s]+(?:\s*,\s*[^\s]+)*)\s*\}").unwrap();
static ref IMPORT_CUSTOM_PATH_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+)").unwrap();
static ref IMPORT_CUSTOM_PATH_AS_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+)\s+as\s+([^\s]+)").unwrap();
static ref IMPORT_ITEMS_REGEX: Regex = Regex::new(r"(?:^|\n)\s*#\s*import\s+([^\s]+)\s+((?:[\w|\d|_]+)(?:\s*,\s*[\w|\d|_]+)*)").unwrap();
}

/// Finds an arbitrary path between two nodes in a dag.
Expand All @@ -43,12 +41,6 @@ fn all_imports_in_source<'a>(source: &'a str) -> HashSet<&'a str> {
for import in IMPORT_ITEMS_REGEX.captures_iter(&source) {
requirements.insert(import.get(1).unwrap().as_str());
}
for import in IMPORT_SINGLE_ITEM_REGEX.captures_iter(&source) {
requirements.insert(import.get(1).unwrap().as_str());
}
for import in IMPORT_ITEMS_BRACKETS_REGEX.captures_iter(&source) {
requirements.insert(import.get(1).unwrap().as_str());
}
return requirements;
}

Expand All @@ -66,10 +58,7 @@ fn replace_import_names_in_source<'a>(
None => return full.to_owned(),
};

// Right alignment is needed for naga_oil to correctly parse rust-style imports:
// `#import foo.wgsl::bar` will become `#import foo::bar`
// naga_oil does not support spaces between import items
let sub = format!("{:>len$}", sub, len = name.len());
let sub = format!("{:^len$}", sub, len = name.len());

capture.get(0).unwrap().as_str().replace(name, &sub)
});
Expand Down

0 comments on commit cd69e5d

Please sign in to comment.