mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-16 17:45:11 +01:00
add file resolver
This commit is contained in:
parent
cfb6ef500a
commit
a0e33835ed
1 changed files with 24 additions and 1 deletions
|
|
@ -1,12 +1,32 @@
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
|
||||||
|
use std::{io, path::Path};
|
||||||
|
|
||||||
use lexer::PLexer;
|
use lexer::PLexer;
|
||||||
pub use lexer::{PToken, Punctuator};
|
pub use lexer::{PToken, Punctuator};
|
||||||
|
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
|
|
||||||
|
enum IncludeKind {
|
||||||
|
AngleBracketed,
|
||||||
|
Quoted,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait FileResolver {
|
||||||
|
fn resolve_file(&self, file_name: &Path, kind: IncludeKind) -> io::Result<Vec<u8>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Todo;
|
||||||
|
|
||||||
|
impl FileResolver for Todo {
|
||||||
|
fn resolve_file(&self, file_name: &Path, kind: IncludeKind) -> io::Result<Vec<u8>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Preprocessor<L> {
|
pub struct Preprocessor<L> {
|
||||||
lexer: L,
|
lexer: L,
|
||||||
|
resolver: Box<dyn FileResolver>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'src, L> Iterator for Preprocessor<L>
|
impl<'src, L> Iterator for Preprocessor<L>
|
||||||
|
|
@ -23,7 +43,10 @@ where
|
||||||
pub fn preprocess_tokens(src: &str) -> impl Iterator<Item = (PToken<'_>, Span)> {
|
pub fn preprocess_tokens(src: &str) -> impl Iterator<Item = (PToken<'_>, Span)> {
|
||||||
let lexer = PLexer::new(src);
|
let lexer = PLexer::new(src);
|
||||||
|
|
||||||
let preprocessor = Preprocessor { lexer };
|
let preprocessor = Preprocessor {
|
||||||
|
lexer,
|
||||||
|
resolver: Box::new(Todo),
|
||||||
|
};
|
||||||
|
|
||||||
preprocessor
|
preprocessor
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue