Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add harper-cli forms and just getforms #615

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions harper-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.19
harper-core = { path = "../harper-core", version = "0.19.0" }
harper-comments = { path = "../harper-comments", version = "0.19.0" }
harper-typst = { path = "../harper-typst", version = "0.19.0" }
hashbrown = "0.15.2"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.138"

Expand Down
29 changes: 26 additions & 3 deletions harper-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc = include_str!("../README.md")]

use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

use anyhow::format_err;
Expand All @@ -9,8 +9,13 @@ use clap::Parser;
use harper_comments::CommentParser;
use harper_core::linting::{LintGroup, LintGroupConfig, Linter};
use harper_core::parsers::{Markdown, MarkdownOptions};
use harper_core::{remove_overlaps, Dictionary, Document, FstDictionary, TokenKind};
use harper_core::spell::hunspell::parse_default_attribute_list;
use harper_core::spell::hunspell::word_list::parse_word_list;
use harper_core::{
remove_overlaps, CharString, Dictionary, Document, FstDictionary, TokenKind, WordMetadata,
};
use harper_literate_haskell::LiterateHaskellParser;
use hashbrown::HashMap;
use serde::Serialize;

/// A debugging tool for the Harper grammar checker.
Expand Down Expand Up @@ -41,6 +46,8 @@ enum Args {
},
/// Get the metadata associated with a particular word.
Metadata { word: String },
/// Get all the forms of a word using the affixes.
Forms { word: String },
/// Emit a decompressed, line-separated list of the words in Harper's dictionary.
Words,
/// Print the default config with descriptions.
Expand Down Expand Up @@ -156,7 +163,7 @@ fn main() -> anyhow::Result<()> {
word_str.clear();
word_str.extend(word);

println!("{}", word_str);
println!("{:?}", word_str);
}

Ok(())
Expand All @@ -169,6 +176,22 @@ fn main() -> anyhow::Result<()> {

Ok(())
}
Args::Forms { word } => {
let hunspell_word_list = format!("1\n{word}");
let words = parse_word_list(&hunspell_word_list.to_string()).unwrap();

let attributes = parse_default_attribute_list();

let mut expanded: HashMap<CharString, WordMetadata> = HashMap::new();

attributes.expand_marked_words(words, &mut expanded);

expanded.keys().for_each(|form| {
let string_form: String = form.iter().collect();
println!("{}", string_form);
});
Ok(())
}
Args::Config => {
#[derive(Serialize)]
struct Config {
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod parsers;
pub mod patterns;
mod punctuation;
mod span;
mod spell;
pub mod spell;
mod sync;
mod title_case;
mod token;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/spell/hunspell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod attribute_list;
mod error;
mod expansion;
mod matcher;
mod word_list;
pub mod word_list;

pub use attribute_list::AttributeList;
use attribute_list::HumanReadableAttributeList;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/spell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use self::merged_dictionary::MergedDictionary;
mod dictionary;
mod fst_dictionary;
mod full_dictionary;
mod hunspell;
pub mod hunspell;
mod merged_dictionary;

#[derive(PartialEq, Debug)]
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ userdictoverlap:
# Get the metadata associated with a particular word in Harper's dictionary as JSON.
getmetadata word:
cargo run --bin harper-cli -- metadata {{word}}
# Get all the forms of a word using the affixes.
getforms word:
cargo run --bin harper-cli -- forms {{word}}

bump-versions: update-vscode-linters
#! /bin/bash
Expand Down