Skip to content

Commit

Permalink
Added matching rules + improved demo + fixed layout issue in web client
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 28, 2024
1 parent 3359b78 commit 69fefb2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
8 changes: 6 additions & 2 deletions demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Harper is a language checker for artists. it can detect
improper capitalization and misspelled words. There are some cases,
where the the standard grammar checkers don't cut it.

That's where Harper comes in handy.
That s where Harper comes in handy.

kid regards, Elijah
Harper works everywhere, even offline. Since you r data never leaves your device,
you don't ned to worry aout us selling it or using it to train LLMs.

The best part: Harper can give you feedback instantly.
For most documents, Harper can serve up suggestions in under 10 ms.
35 changes: 34 additions & 1 deletion harper-core/src/linting/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ macro_rules! pt {
content: Some($str.chars().collect()),
}
};
(Period) => {
PatternToken {
kind: TokenKind::Punctuation(Punctuation::Period),
content: None,
}
};
(Hyphen) => {
PatternToken {
kind: TokenKind::Punctuation(Punctuation::Hyphen),
Expand Down Expand Up @@ -122,20 +128,47 @@ impl Matcher {
"more","then" => "more than",
"gong","to" => "going to",
"then","others" => "than others",
"Then","others" => "than others",
"then","before" => "than before",
"Then","before" => "than before",
"then","last","week" => "than last week",
"then","her" => "than her",
"then","hers" => "than hers",
"then","him" => "than him",
"then","his" => "than his",
"simply","grammatical" => "simple grammatical"
"simply","grammatical" => "simple grammatical",
"you","r" => "your",
"that","s" => "that's",
"That","s" => "that's",
"that","s" => "that is",
"That","s" => "that is",
"ms" => "milliseconds",
"LLM" => "large language model",
"LLMs" => "large language models"
};

triggers.push(Rule {
pattern: vec![pt!("break"), pt!(Hyphen), pt!("up")],
replace_with: vecword!("break-up"),
});

triggers.push(Rule {
pattern: vec![pt!("L"), pt!(Period), pt!("L"), pt!(Period), pt!("M")],
replace_with: vecword!("large language model"),
});

triggers.push(Rule {
pattern: vec![
pt!("L"),
pt!(Period),
pt!("L"),
pt!(Period),
pt!("M"),
pt!(Period),
],
replace_with: vecword!("large language model"),
});

Self { triggers }
}
}
Expand Down
2 changes: 1 addition & 1 deletion harper-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = "s"
opt-level = 3
strip = true

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
>
<textarea
bind:this={editor}
class="w-full m-0 rounded-none p-0 z-0 bg-transparent border-none text-lg resize-none focus:border-0"
class="w-full text-nowrap m-0 rounded-none p-0 z-0 bg-transparent overflow-hidden border-none text-lg resize-none focus:border-0"
spellcheck="false"
style={`grid-row: 1; grid-column: 1; height: ${boxHeight}px`}
on:keydown={() => (focused = undefined)}
Expand Down
Empty file added web/src/lib/Graph.svelte
Empty file.
2 changes: 1 addition & 1 deletion web/src/lib/Underlines.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</script>

<div class="grid">
<div class="p-0 m-0 indent-0 text-transparent" style="grid-row: 1; grid-column: 1">
<div class="p-0 m-0 text-nowrap indent-0 text-transparent" style="grid-row: 1; grid-column: 1">
{#each modified as chunk}
{#if chunk == null}
<br />
Expand Down
2 changes: 0 additions & 2 deletions web/src/lib/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export function spanContent(span: Span, source: string): string {
}

export async function lintText(text: string, useWasm = defaultUseWasm): Promise<Lint[]> {
console.time('lint');
let lints;

if (useWasm) {
Expand All @@ -107,7 +106,6 @@ export async function lintText(text: string, useWasm = defaultUseWasm): Promise<
// The `Underlines` component assumes the lints do not overlap.
lints = removeOverlaps(lints);

console.timeEnd('lint');
return lints;
}

Expand Down
1 change: 1 addition & 0 deletions web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import Editor from '$lib/Editor.svelte';
import Graph from '$lib/Graph.svelte';
let width = window.innerWidth;
Expand Down

0 comments on commit 69fefb2

Please sign in to comment.