Add tokenizer

This commit is contained in:
Andras Schmelczer 2024-11-24 22:32:06 +00:00
parent e910d9c5f4
commit 331e264399
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 119 additions and 33 deletions

View file

@ -4,8 +4,9 @@ mod operation;
pub use edited_text::EditedText;
pub use operation::Operation;
use std::hash::Hash;
use crate::errors::SyncLibError;
use crate::{errors::SyncLibError, tokenizer::token::Token};
pub fn reconcile(original: &str, left: &str, right: &str) -> Result<String, SyncLibError> {
let left_operations = EditedText::from_strings(original, left);
@ -15,6 +16,23 @@ pub fn reconcile(original: &str, left: &str, right: &str) -> Result<String, Sync
merged_operations.apply()
}
pub fn reconcile_with_tokenizer<F, T>(
original: &str,
left: &str,
right: &str,
tokenizer: &F,
) -> Result<String, SyncLibError>
where
F: Fn(&str) -> Vec<Token<T>>,
T: PartialEq + Hash + Clone,
{
let left_operations = EditedText::from_strings_with_tokenizer(original, left, tokenizer);
let right_operations = EditedText::from_strings_with_tokenizer(original, right, tokenizer);
let merged_operations = left_operations.merge(right_operations);
merged_operations.apply()
}
#[cfg(test)]
mod test {
use std::{fs, ops::Range, path::Path};