mod kind;
use serde::{Deserialize, Serialize};
pub use kind::{SymbolKind, UnknownSymbolKind};
use crate::text::Span;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Symbol {
pub kind: SymbolKind,
pub name: String,
pub name_span: Span,
pub span: Span,
pub extent: Span,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub visibility: Option<Modifier>,
}
impl Symbol {
pub fn plain(kind: SymbolKind, name: impl Into<String>, name_span: Span, span: Span) -> Self {
Self {
kind,
name: name.into(),
name_span,
span,
extent: span,
visibility: None,
}
}
pub fn modifier(&self) -> Option<&str> {
self.visibility.as_ref().map(|m| m.text.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Modifier {
pub span: Span,
pub text: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModifierAt {
Child(&'static str),
Parent(&'static str),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SymbolRule {
pub node: &'static str,
pub name_field: Option<&'static str>,
pub kind: SymbolKind,
pub under: Option<&'static str>,
pub within: Option<&'static str>,
pub leading: &'static [&'static str],
pub visibility: Option<ModifierAt>,
pub name_inner: Option<&'static str>,
}
impl SymbolRule {
pub const fn new(node: &'static str, name_field: &'static str, kind: SymbolKind) -> Self {
Self {
node,
name_field: Some(name_field),
kind,
under: None,
within: None,
leading: &[],
visibility: None,
name_inner: None,
}
}
pub const fn self_named(node: &'static str, kind: SymbolKind) -> Self {
Self {
node,
name_field: None,
kind,
under: None,
within: None,
leading: &[],
visibility: None,
name_inner: None,
}
}
pub const fn name_inner(mut self, field: &'static str) -> Self {
self.name_inner = Some(field);
self
}
pub const fn leading(mut self, kinds: &'static [&'static str]) -> Self {
self.leading = kinds;
self
}
pub const fn visibility(mut self, at: ModifierAt) -> Self {
self.visibility = Some(at);
self
}
pub const fn under(mut self, parent: &'static str) -> Self {
self.under = Some(parent);
self
}
pub const fn within(mut self, ancestor: &'static str) -> Self {
self.within = Some(ancestor);
self
}
}