use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ScopeId(pub usize);
impl ScopeId {
#[must_use]
pub fn new(id: usize) -> Self {
Self(id)
}
}
impl From<usize> for ScopeId {
fn from(id: usize) -> Self {
Self(id)
}
}
impl From<ScopeId> for usize {
fn from(id: ScopeId) -> Self {
id.0
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Scope {
pub id: ScopeId,
pub scope_type: String,
pub name: String,
pub file_path: PathBuf,
pub start_line: usize,
pub start_column: usize,
pub end_line: usize,
pub end_column: usize,
pub parent_id: Option<ScopeId>,
}
impl Scope {
#[must_use]
pub fn new(scope_type: String, name: String, file_path: PathBuf) -> Self {
Self {
id: ScopeId::new(0),
scope_type,
name,
file_path,
start_line: 0,
start_column: 0,
end_line: 0,
end_column: 0,
parent_id: None,
}
}
#[must_use]
pub fn with_location(
mut self,
start_line: usize,
start_column: usize,
end_line: usize,
end_column: usize,
) -> Self {
self.start_line = start_line;
self.start_column = start_column;
self.end_line = end_line;
self.end_column = end_column;
self
}
#[must_use]
pub fn with_parent(mut self, parent_id: ScopeId) -> Self {
self.parent_id = Some(parent_id);
self
}
}