Compare commits
No commits in common. "main" and "v0.2.0" have entirely different histories.
|
@ -1,7 +1,6 @@
|
||||||
use std::{collections::VecDeque, env, path::Path};
|
use std::{collections::VecDeque, path::Path};
|
||||||
|
|
||||||
use crate::{token::{Token, MessageType}, builtin::modules::Module};
|
use crate::{token::{Token, MessageType}, builtin::modules::Module};
|
||||||
use crate::builtin::modules::io::print;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LangSpecs {
|
pub struct LangSpecs {
|
||||||
|
@ -59,6 +58,8 @@ pub fn from_list(text: &str) -> Vec<String> {
|
||||||
|
|
||||||
fn parse_directive(text: &str, token_idx: usize, specs: &mut LangSpecs, origin: &String) {
|
fn parse_directive(text: &str, token_idx: usize, specs: &mut LangSpecs, origin: &String) {
|
||||||
|
|
||||||
|
std::env::set_current_dir(Path::new(origin).parent().unwrap()).expect("unable to change cwd");
|
||||||
|
|
||||||
for cap in DIRECTIVE_REGEX.captures_iter(text) {
|
for cap in DIRECTIVE_REGEX.captures_iter(text) {
|
||||||
let mut enumerator = cap.iter().enumerate();
|
let mut enumerator = cap.iter().enumerate();
|
||||||
loop {
|
loop {
|
||||||
|
@ -90,19 +91,11 @@ fn parse_directive(text: &str, token_idx: usize, specs: &mut LangSpecs, origin:
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
4 => {
|
4 => {
|
||||||
let cwd = Path::new(origin).parent().unwrap().canonicalize().unwrap();
|
|
||||||
for path in from_list(mat.as_str()).iter() {
|
for path in from_list(mat.as_str()).iter() {
|
||||||
let mut include_path = cwd.clone();
|
if let Ok(str) = std::fs::read_to_string(path) {
|
||||||
include_path.push(path);
|
specs.embedded_files.push((token_idx, str, path.to_owned()));
|
||||||
|
} else {
|
||||||
if let Ok(path) = include_path.canonicalize() {
|
crate::message(MessageType::Warning, format!("Unable to read embedded file: {path}"));
|
||||||
let include_file = path.to_str().unwrap().to_string();
|
|
||||||
|
|
||||||
if let Ok(str) = std::fs::read_to_string(&include_file) {
|
|
||||||
specs.embedded_files.push((token_idx, str, include_file));
|
|
||||||
} else {
|
|
||||||
crate::message(MessageType::Warning, format!("Unable to read embedded file: {include_file}"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue