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: Typst Language Support #302

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bed51f7
feat(#230): map basic typst expressions to tokens
grantlemons Nov 25, 2024
7201575
feat(#230): change recursive shorthand from macro to function
grantlemons Nov 25, 2024
d880613
feat(#230): flesh out more complicated typst syntax parsing
grantlemons Nov 26, 2024
9376e71
feat(#230): delegate typst files to parser in harper-cli and harper-ls
grantlemons Nov 26, 2024
749e6dd
fix(#230): fix offset update after delegating parser
grantlemons Nov 26, 2024
ba3c307
fix(#230): ParBreak to ParBreak, not two Newlines
grantlemons Nov 26, 2024
c6a4d05
feat(#230): remove offset variable, and just use the start of an
grantlemons Nov 26, 2024
0425110
feat(#230): parse numbers properly and add test for numbers
grantlemons Nov 27, 2024
1f43b27
feat(#230): consolidate words separated by apostrophes into possessiv…
grantlemons Nov 27, 2024
835c396
fix(clippy): satisfy clippy
grantlemons Nov 27, 2024
4dbc264
feat(#230): simplify possessive-conjunction logic and add respective …
grantlemons Nov 27, 2024
f3eda92
feat(#230): create additional parsers for complex dictionary parsing
grantlemons Nov 29, 2024
24e0551
feat(#230): add some tests for dictionary parsing, and improve dict p…
grantlemons Nov 29, 2024
c63d41a
fix(#230): fix dict parsing by manually getting document content in s…
grantlemons Dec 4, 2024
f57d6c2
fix(#230): remove debug print of typst ast in test
grantlemons Dec 4, 2024
550cf20
style(#230): expand explainer on str parsing
grantlemons Dec 4, 2024
7cd135f
feat(#230): remove quotes from Str parsing
grantlemons Dec 20, 2024
54418ff
fix(#230): remove improper test case
grantlemons Dec 20, 2024
935c85d
Merge remote-tracking branch 'upstream/master' into typst-support
grantlemons Dec 27, 2024
5336778
tests(#230): add test using unicode apostrophe
grantlemons Dec 27, 2024
60bb986
refactor(#230): simplify parsing by moving some helper functions insi…
grantlemons Dec 27, 2024
299d810
feat(#230): support unicode characters
grantlemons Dec 27, 2024
58b3fb0
fix(#230): use offset struct for constant tokens
grantlemons Dec 27, 2024
1776346
feat(#230): mark labels unlintable and add some tests
grantlemons Dec 27, 2024
fe4979e
refactor(#230): simplify matching macros
grantlemons Dec 29, 2024
17585f3
refactor(#230): create helper struct and make parser trait non-mut
grantlemons Dec 29, 2024
90d5074
refactor(#230): simplify dict and pattern parsing and correctly handl…
grantlemons Dec 29, 2024
3f9ecb5
feat(spans-visual): mark unlintable spans as red
grantlemons Dec 29, 2024
4ec7f71
tests(#230): add complex typst document test
grantlemons Dec 29, 2024
81eb91b
feat(#230): parsing of arguments and parameters
grantlemons Dec 29, 2024
4457bff
tests(#230): comment out et al. in typst test
grantlemons Dec 29, 2024
1d0b972
fix: only condense adjacent spaces
grantlemons Dec 29, 2024
b61c78c
fix: better handling of spaces and newlines
grantlemons Dec 29, 2024
a29b879
fix: testing rig takes a parser instead of assuming markdown
grantlemons Dec 29, 2024
00623b0
fix(#230): mark numbers outside text as unlintable
grantlemons Dec 29, 2024
122436f
tests(#230): add document with spelling mistakes in different contexts
grantlemons Dec 30, 2024
5f83275
tests(#230): edit test macros to parse the extension
grantlemons Dec 30, 2024
2e97afe
Revert "feat(spans-visual): mark unlintable spans as red"
grantlemons Dec 30, 2024
83789eb
Revert portions of "fix: better handling of spaces and newlines"
grantlemons Dec 30, 2024
e66ec68
Merge remote-tracking branch 'upstream/master' into typst-support
grantlemons Dec 30, 2024
2c8bf13
Merge branch 'master' into typst-support
grantlemons Dec 31, 2024
ee1080d
feat(#230): make typst into a feature
grantlemons Dec 31, 2024
6373988
fix(#230): improve feature interconnectedness in other project crates
grantlemons Dec 31, 2024
f5881c3
fix(#230): use dep: syntax in harper-core
grantlemons Dec 31, 2024
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
190 changes: 190 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions harper-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ clap = { version = "4.5.23", features = ["derive"] }
harper-core = { path = "../harper-core", version = "0.14.0" }
harper-comments = { path = "../harper-comments", version = "0.14.0" }
serde_json = "1.0.133"

[features]
default = ["typst"]
typst = ["harper-core/typst"]
15 changes: 8 additions & 7 deletions harper-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ fn main() -> anyhow::Result<()> {
fn load_file(file: &Path) -> anyhow::Result<(Document, String)> {
let source = std::fs::read_to_string(file)?;

let mut parser: Box<dyn harper_core::parsers::Parser> =
if let Some("md") = file.extension().map(|v| v.to_str().unwrap()) {
Box::new(Markdown)
} else {
Box::new(
let parser: Box<dyn harper_core::parsers::Parser> =
match file.extension().map(|v| v.to_str().unwrap()) {
Some("md") => Box::new(Markdown),
#[cfg(feature = "typst")]
Some("typ") => Box::new(harper_core::parsers::Typst),
_ => Box::new(
CommentParser::new_from_filename(file)
.map(Box::new)
.ok_or(format_err!("Could not detect language ID."))?,
)
),
};

Ok((Document::new_curated(&source, &mut parser), source))
Ok((Document::new_curated(&source, &parser), source))
}
3 changes: 3 additions & 0 deletions harper-comments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ tree-sitter-haskell = "0.15.0"

[dev-dependencies]
paste = "1.0.15"

[features]
typst = ["harper-core/typst"]
2 changes: 1 addition & 1 deletion harper-comments/src/comment_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl CommentParser {
}

impl Parser for CommentParser {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
fn parse(&self, source: &[char]) -> Vec<Token> {
self.inner.parse(source)
}
}
6 changes: 2 additions & 4 deletions harper-comments/src/comment_parsers/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::without_initiators;
pub struct Go;

impl Parser for Go {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
fn parse(&self, source: &[char]) -> Vec<Token> {
let mut actual = without_initiators(source);
let mut actual_source = actual.get_content(source);

Expand All @@ -25,9 +25,7 @@ impl Parser for Go {
actual_source = new_source
}

let mut markdown_parser = Markdown;

let mut new_tokens = markdown_parser.parse(actual_source);
let mut new_tokens = Markdown.parse(actual_source);

new_tokens
.iter_mut()
Expand Down
2 changes: 1 addition & 1 deletion harper-comments/src/comment_parsers/javadoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct JavaDoc {
}

impl Parser for JavaDoc {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
fn parse(&self, source: &[char]) -> Vec<Token> {
let actual = without_initiators(source);
let actual_source = actual.get_content(source);

Expand Down
2 changes: 1 addition & 1 deletion harper-comments/src/comment_parsers/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::without_initiators;
pub struct JsDoc;

impl Parser for JsDoc {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
fn parse(&self, source: &[char]) -> Vec<Token> {
let mut tokens = Vec::new();

let mut chars_traversed = 0;
Expand Down
7 changes: 2 additions & 5 deletions harper-comments/src/comment_parsers/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::without_initiators;
pub struct Unit;

impl Parser for Unit {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
fn parse(&self, source: &[char]) -> Vec<Token> {
let mut tokens = Vec::new();

let mut chars_traversed = 0;
Expand Down Expand Up @@ -57,10 +57,7 @@ fn parse_line(source: &[char]) -> Vec<Token> {
}

let source = actual.get_content(source);

let mut markdown_parser = Markdown;

let mut new_tokens = markdown_parser.parse(source);
let mut new_tokens = Markdown.parse(source);

new_tokens
.iter_mut()
Expand Down
Loading
Loading