forked from M-Labs/nac3
1
0
Fork 0
nac3/nac3core/src/location.rs

29 lines
565 B
Rust
Raw Normal View History

2021-11-03 17:11:00 +08:00
use nac3parser::ast;
2021-06-28 14:48:04 +08:00
use std::vec::Vec;
#[derive(Clone, Copy, PartialEq)]
pub struct FileID(u32);
#[derive(Clone, Copy, PartialEq)]
pub enum Location {
CodeRange(FileID, ast::Location),
2021-08-05 14:55:09 +08:00
Builtin,
2021-06-28 14:48:04 +08:00
}
2021-09-22 17:56:48 +08:00
#[derive(Default)]
2021-06-28 14:48:04 +08:00
pub struct FileRegistry {
files: Vec<String>,
}
impl FileRegistry {
pub fn add_file(&mut self, path: &str) -> FileID {
let index = self.files.len() as u32;
self.files.push(path.to_owned());
FileID(index)
}
pub fn query_file(&self, id: FileID) -> &str {
&self.files[id.0 as usize]
}
}