use {
crate::{
core::{Ident, Symbol, SymbolPath, Value, Visibility},
partitions::{records::SymbolEntry, symbols::Symbols},
},
laburnum::database::{
HasPartition, Partition, PartitionKey, PartitionWriteContextRef, RecordHandle,
storage::Partitions,
},
};
pub(super) fn write_shape_and_index<P, V, I, Path, S, Idx>(
writer: &mut PartitionWriteContextRef<'_, P>,
path: Path,
span: laburnum::Span,
shape: Symbol<V, I, Path, S>,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
P: Partitions,
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
Idx: Partition<IndexEntry = SymbolEntry<V, I, Path, S>, SortKey = Path>
+ PartitionKey
+ laburnum::database::partitions::SortKeyOf<P>
+ 'static,
P::Stores: HasPartition<Symbols<V, I, Path, S>> + HasPartition<Idx>,
{
let handle = writer.store::<Symbols<V, I, Path, S>>(shape);
let entry = SymbolEntry::new(path.clone(), span, handle);
writer.index_entry::<Idx>(path.clone(), entry);
writer.index_span::<Idx>(path.clone(), span, handle.content_hash());
handle
}
macro_rules! define_symbol_writer {
(
trait_name: $trait_name:ident,
index_partition: $idx:ident,
clear_method: $clear:ident,
method_prefix: $prefix:ident,
) => {
paste::paste! {
pub trait $trait_name<P: Partitions> {
fn $clear<V, I, Path, S>(
&mut self,
file_prefix: &Path,
) where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores: HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
fn [<$prefix definition>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: I,
value: Option<V>,
visibility: S,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
#[allow(clippy::too_many_arguments)]
fn [<$prefix reference>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: Option<I>,
target_path: Path,
is_absolute: bool,
nameable: bool,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
fn [<$prefix scope>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
value: Option<V>,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
fn [<$prefix keyword>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: I,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
fn [<$prefix value>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
value: V,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
fn [<$prefix import>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
import_path: Path,
alias: Option<I>,
value: Option<V>,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>;
}
impl<P: Partitions> $trait_name<P> for PartitionWriteContextRef<'_, P> {
fn $clear<V, I, Path, S>(
&mut self,
file_prefix: &Path,
) where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores: HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
self.clear_prefix::<$idx<V, I, Path, S>>(
file_prefix.clone(),
);
}
fn [<$prefix definition>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: I,
value: Option<V>,
visibility: S,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Definition { name, value, visibility };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
fn [<$prefix reference>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: Option<I>,
target_path: Path,
is_absolute: bool,
nameable: bool,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Reference { path: path.clone(), name, target_path, is_absolute, nameable };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
fn [<$prefix scope>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
value: Option<V>,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Scope { value };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
fn [<$prefix keyword>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
name: I,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Keyword { name };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
fn [<$prefix value>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
value: V,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Value { value };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
fn [<$prefix import>]<V, I, Path, S>(
&mut self,
path: Path,
span: laburnum::Span,
import_path: Path,
alias: Option<I>,
value: Option<V>,
) -> RecordHandle<Symbols<V, I, Path, S>>
where
V: Value<I> + 'static,
I: Ident,
Path: SymbolPath + 'static,
S: Visibility,
P::Stores:
HasPartition<Symbols<V, I, Path, S>> + HasPartition<$idx<V, I, Path, S>>,
$idx<V, I, Path, S>: laburnum::database::partitions::SortKeyOf<P>
+ laburnum::database::Partition<
SortKey = Path,
IndexEntry = crate::partitions::records::SymbolEntry<V, I, Path, S>,
>,
{
let shape = Symbol::Import { path: import_path, alias, value };
super::symbol_writer_macro::write_shape_and_index::<P, V, I, Path, S, $idx<V, I, Path, S>>(
self, path, span, shape,
)
}
}
} };
}
pub(super) use define_symbol_writer;