Skip to content

Commit

Permalink
feat(WIP): file imports
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Sep 28, 2023
1 parent e8fe453 commit df75f3a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/import.whi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./add.whi"

import "@std/math/mod.whi"
export fn helloWorld(): i32 {
return add(1, 2)
}
4 changes: 3 additions & 1 deletion preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ whistle_lexer = { path = "../lexer" }
whistle_common ={ path = "../common"}
reqwest = { version = "0.11.20", features = ["blocking"] }
url = "2.4.1"
resolve-path = "0.1.0"
resolve-path = "0.1.0"
async-recursion = "1.0.5"
lazy_static = "1.4.0"
3 changes: 2 additions & 1 deletion preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl Preprocessor {
pub fn process(&mut self, src: &str, path: &path::Path) {
let mut lexer = Lexer::new(src);
let mut tokens: Vec<TokenItem> = Vec::new();

let mut imports: Vec<String> = Vec::new();
loop {
let item = match lexer.next() {
Expand Down Expand Up @@ -64,6 +63,7 @@ impl Preprocessor {
tokens.push(item);
}
}

for mut file_name in imports {
if file_name.starts_with("@") {

Check warning on line 68 in preprocessor/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

single-character string constant used as pattern

warning: single-character string constant used as pattern --> preprocessor/src/lib.rs:68:32 | 68 | if file_name.starts_with("@") { | ^^^ help: try using a `char` instead: `'@'` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern = note: `#[warn(clippy::single_char_pattern)]` on by default
file_name.remove(0);
Expand All @@ -72,6 +72,7 @@ impl Preprocessor {
}

let new_file_name = if url::Url::parse(&file_name).is_err() {
println!("{}", file_name);
match file_name.resolve_in(&path.canonicalize().unwrap()) {
std::borrow::Cow::Owned(v) => v,
std::borrow::Cow::Borrowed(v) => v.to_owned(),
Expand Down

0 comments on commit df75f3a

Please sign in to comment.