Skip to content

Commit

Permalink
style(#160): rename Cases parser to CollapseIdentifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Oct 4, 2024
1 parent ef33e85 commit 3e322c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::{Dictionary, FullDictionary, MergedDictionary, Span, Token, VecExt, W

/// A parser that wraps any other parser to collapse token strings that match
/// the pattern word_word or word-word.
pub struct Cases {
pub struct CollapseIdentifiers {
inner: Box<dyn Parser>,
dict: Lrc<MergedDictionary<FullDictionary>>,
}

impl Cases {
impl CollapseIdentifiers {
pub fn new(inner: Box<dyn Parser>, dict: &Lrc<MergedDictionary<FullDictionary>>) -> Self {
Self {
inner,
Expand All @@ -31,7 +31,7 @@ thread_local! {
.then_any_word())));
}

impl Parser for Cases {
impl Parser for CollapseIdentifiers {
/// This implementation is quite gross to look at, but it works.
/// If any issues arise, it would likely help to refactor this out first.
fn parse(&mut self, source: &[char]) -> Vec<Token> {
Expand Down Expand Up @@ -83,7 +83,8 @@ mod tests {
let dict = FullDictionary::curated();
let source = "This is a test.";

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(dict.into())).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(dict.into()))
.parse_str(source);
assert_eq!(tokens.len(), 8);
}

Expand All @@ -92,7 +93,7 @@ mod tests {
let source = "This is a separated_identifier, wow!";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -108,7 +109,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 10);
}

Expand All @@ -117,7 +119,7 @@ mod tests {
let source = "This is a separated-identifier, wow!";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -133,7 +135,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 10);
}

Expand All @@ -142,7 +145,7 @@ mod tests {
let source = "This is a separated_identifier_token, wow!";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -158,7 +161,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 10);
}

Expand All @@ -167,7 +171,7 @@ mod tests {
let source = "This is a separated_identifier, wow! separated_identifier";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -183,7 +187,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 12);
}

Expand All @@ -192,7 +197,7 @@ mod tests {
let source = "This is a separated_identifier_token, wow!";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -212,7 +217,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 15);
}

Expand All @@ -221,7 +227,7 @@ mod tests {
let source = "This is a separated_identifier_token, wow!";
let default_dict = FullDictionary::curated();

let tokens = Cases::new(
let tokens = CollapseIdentifiers::new(
Box::new(PlainEnglish),
&Lrc::new(default_dict.clone().into()),
)
Expand All @@ -241,7 +247,8 @@ mod tests {
let mut merged_dict = MergedDictionary::from(default_dict);
merged_dict.add_dictionary(Lrc::new(dict));

let tokens = Cases::new(Box::new(PlainEnglish), &Lrc::new(merged_dict)).parse_str(source);
let tokens = CollapseIdentifiers::new(Box::new(PlainEnglish), &Lrc::new(merged_dict))
.parse_str(source);
assert_eq!(tokens.len(), 10);
}
}
4 changes: 2 additions & 2 deletions harper-core/src/parsers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod cases;
mod collapse_identifiers;
mod markdown;
mod mask;
mod plain_english;

use blanket::blanket;
pub use cases::Cases;
pub use collapse_identifiers::CollapseIdentifiers;
pub use markdown::Markdown;
pub use mask::Mask;
pub use plain_english::PlainEnglish;
Expand Down
4 changes: 2 additions & 2 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use anyhow::anyhow;
use harper_comments::CommentParser;
use harper_core::linting::{LintGroup, Linter};
use harper_core::parsers::{Cases, Markdown, PlainEnglish};
use harper_core::parsers::{CollapseIdentifiers, Markdown, PlainEnglish};
use harper_core::{
Dictionary, Document, FullDictionary, MergedDictionary, Token, TokenKind, WordMetadata,
};
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Backend {
}
Document::new_from_vec(
source,
&mut Cases::new(Box::new(ts_parser), &doc_state.dict),
&mut CollapseIdentifiers::new(Box::new(ts_parser), &doc_state.dict),
&doc_state.dict,
)
} else {
Expand Down

0 comments on commit 3e322c9

Please sign in to comment.