include derives prant folder from main file

This commit is contained in:
Sven Vogel 2023-09-16 12:42:37 +02:00
parent a7899c15b1
commit a567fc75b9
2 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
use std::{collections::VecDeque};
use std::{collections::VecDeque, path::Path};
use crate::{token::{Token, MessageType}, builtin::modules::Module};
@ -22,12 +22,12 @@ impl LangSpecs {
}
}
pub fn resolve_directives(tokens: &mut VecDeque<Token>) -> LangSpecs {
pub fn resolve_directives(tokens: &mut VecDeque<Token>, origin: &String) -> LangSpecs {
let mut specs = LangSpecs::default();
for (idx, token) in tokens.iter().enumerate() {
match token {
Token::CompilerDirective(text, _) => parse_directive(text, idx, &mut specs),
Token::CompilerDirective(text, _) => parse_directive(text, idx, &mut specs, origin),
_ => ()
}
}
@ -56,7 +56,9 @@ pub fn from_list(text: &str) -> Vec<String> {
vec
}
fn parse_directive(text: &str, token_idx: usize, specs: &mut LangSpecs) {
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) {
let mut enumerator = cap.iter().enumerate();

View File

@ -35,7 +35,7 @@ fn compile(settings: &Settings) -> Option<(Vec<Func>, Vec<Declr>, Vec<BuiltinFun
diagnostics.add_source_origin(code, src.path());
if let Ok(mut tokens) = tokenize(code, &mut diagnostics) {
let specs = crate::direct::resolve_directives(&mut tokens);
let specs = crate::direct::resolve_directives(&mut tokens, src.path());
// read source of every embedded file and tokenize
for (idx, src, path) in specs.embedded_files() {