Skip to content

Commit

Permalink
fix(fst-dict): remove duplication by importing types from parsing crate
Browse files Browse the repository at this point in the history
Types include:
- Span
- CharString
- WordMetadata
  • Loading branch information
grantlemons committed Nov 2, 2024
1 parent 9ab4cb0 commit 78ce5a5
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 176 deletions.
23 changes: 0 additions & 23 deletions harper-core/src/char_string.rs

This file was deleted.

2 changes: 1 addition & 1 deletion harper-core/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use paste::paste;
use crate::parsers::{Markdown, Parser, PlainEnglish};
use crate::patterns::{PatternExt, RepeatingPattern, SequencePattern};
use crate::punctuation::Punctuation;
use crate::span::Span;
use crate::token::NumberSuffix;
use crate::vec_ext::VecExt;
use crate::Span;
use crate::{Dictionary, FatToken, FstDictionary, Lrc, Token, TokenKind, TokenStringExt};

/// A document containing some amount of lexed and parsed English text.
Expand Down
6 changes: 2 additions & 4 deletions harper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(dead_code)]

mod char_ext;
mod char_string;
mod document;
pub mod language_detection;
mod lexing;
Expand All @@ -11,21 +10,20 @@ mod mask;
pub mod parsers;
pub mod patterns;
mod punctuation;
mod span;
mod spell;
mod sync;
mod token;
mod vec_ext;

use std::collections::VecDeque;

pub use char_string::{CharString, CharStringExt};
pub use document::Document;
pub use harper_dictionary_parsing::char_string::{CharString, CharStringExt};
pub use harper_dictionary_parsing::span::Span;
pub use harper_dictionary_parsing::{word_metadata::Tense, WordMetadata};
use linting::Lint;
pub use mask::{Mask, Masker};
pub use punctuation::{Punctuation, Quote};
pub use span::Span;
pub use spell::{Dictionary, FstDictionary, FullDictionary, MergedDictionary};
pub use sync::Lrc;
pub use token::{FatToken, Token, TokenKind, TokenStringExt};
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use is_macro::Is;
use serde::{Deserialize, Serialize};

use crate::span::Span;
use crate::Span;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Lint {
Expand Down
138 changes: 0 additions & 138 deletions harper-core/src/span.rs

This file was deleted.

3 changes: 1 addition & 2 deletions harper-core/src/spell/fst_dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::{edit_distance_min_alloc, seq_to_normalized, FullDictionary};
use fst::Map as FstMap;
use fst::{automaton::Levenshtein, IntoStreamer};
use harper_dictionary_parsing::CharString;
use hashbrown::HashMap;
use itertools::Itertools;
use std::sync::Arc;

use crate::{CharStringExt, WordMetadata};
use crate::{CharString, CharStringExt, WordMetadata};

use super::Dictionary;

Expand Down
3 changes: 1 addition & 2 deletions harper-core/src/spell/merged_dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use harper_dictionary_parsing::CharString;
use itertools::Itertools;
use std::sync::Arc;

use super::dictionary::Dictionary;
use crate::WordMetadata;
use crate::{CharString, WordMetadata};

/// A simple wrapper over [`Dictionary`] that allows
/// one to merge multiple dictionaries without copying.
Expand Down
3 changes: 1 addition & 2 deletions harper-core/src/spell/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;

use harper_dictionary_parsing::WordMetadata;
use itertools::{Itertools, MinMaxResult};

use crate::{CharString, CharStringExt};
use crate::{CharString, CharStringExt, WordMetadata};

pub use self::dictionary::Dictionary;
pub use self::fst_dictionary::FstDictionary;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use paste::paste;
use serde::{Deserialize, Serialize};

use crate::punctuation::Punctuation;
use crate::span::Span;
use crate::Span;
use crate::{Quote, WordMetadata};
use harper_dictionary_parsing::word_metadata::{ConjunctionData, NounData};

Expand Down
18 changes: 18 additions & 0 deletions harper-dictionary-parsing/src/char_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ use smallvec::SmallVec;
/// A char sequence that improves cache locality.
/// Most English words are fewer than 12 characters.
pub type CharString = SmallVec<[char; 12]>;

pub trait CharStringExt {
fn to_lower(&self) -> CharString;
fn to_string(&self) -> String;
}

impl CharStringExt for [char] {
fn to_lower(&self) -> CharString {
let mut out = CharString::with_capacity(self.len());

out.extend(self.iter().flat_map(|v| v.to_lowercase()));

out
}
fn to_string(&self) -> String {
self.iter().collect()
}
}
4 changes: 2 additions & 2 deletions harper-dictionary-parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pub mod char_string;
mod error;
mod expansion;
mod matcher;
mod span;
pub mod span;
pub mod word_list;
pub mod word_metadata;

pub use attribute_list::AttributeList;
use attribute_list::HumanReadableAttributeList;
pub use char_string::CharString;
pub use char_string::{CharString, CharStringExt};
pub use error::Error;
pub use span::Span;
pub use word_metadata::WordMetadata;
Expand Down

0 comments on commit 78ce5a5

Please sign in to comment.