pub fn parse(
filename: &str,
resolver: &dyn FileRefResolver,
source_map: &mut SourceMap,
) -> Result<SourceFileRef, Error>Expand description
Parse a single file and its sub-file references recursively.
Attempt to load the content of filename via the given resolver, and parse it.
Then recursiverly look for sub-file commands inside that root file, and try to resolve
the content of those sub-files and parse them too. All the loaded and parsed files end
up populating the given source_map, which can be pre-populated manually or from a
previous call with already loaded and parsed files.
use weldr::{ FileRefResolver, parse, ResolveError, SourceMap };
struct MyCustomResolver {};
impl FileRefResolver for MyCustomResolver {
fn resolve(&self, filename: &str) -> Result<Vec<u8>, ResolveError> {
Ok(vec![]) // replace with custom impl
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resolver = MyCustomResolver{};
let mut source_map = SourceMap::new();
let root_file_ref = parse("root.ldr", &resolver, &mut source_map)?;
let root_file = root_file_ref.get(&source_map);
assert_eq!(root_file.filename, "root.ldr");
Ok(())
}