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

Merged
merged 58 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 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
32da8f8
Merge branch 'master' into typst-support
grantlemons Jan 4, 2025
df7652b
fix: add newline to eof
grantlemons Jan 4, 2025
6dcf841
refactor: change harper_ls language_id if chain to match statement
grantlemons Jan 4, 2025
1672de3
refactor: move typst parsing to a new crate
grantlemons Jan 4, 2025
ada56a0
refactor: add many comments to typst parser
grantlemons Jan 4, 2025
d638a28
refactor: undo changes to test runner so it is all markdown
grantlemons Jan 6, 2025
cfb468c
fix: add crate info to Cargo.toml
grantlemons Jan 6, 2025
0f55ab1
Merge remote-tracking branch 'upstream/master' into typst-support
grantlemons Jan 7, 2025
fcd965b
Merge remote-tracking branch 'upstream/master' into typst-support
grantlemons Jan 10, 2025
911bcdb
fix(#230): remove feature flags
grantlemons Jan 10, 2025
79e743e
fix(#230): use document in tests to handle contractions
grantlemons Jan 10, 2025
290a08a
Merge remote-tracking branch 'upstream/master' into typst-support
grantlemons Jan 12, 2025
ec307ab
fix(#230): remove pattern previously used for contractions
grantlemons Jan 12, 2025
6a16626
fix(core): delete erroneous file that was breaking the build
elijah-potter Jan 13, 2025
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

74 changes: 57 additions & 17 deletions harper-core/src/parsers/typst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,18 @@ fn map_token(
}
Expr::Numeric(a) => constant_token!(doc, a, TokenKind::Unlintable),
Expr::Str(text) => {
// Using `text.get()` doesn't work here, because it escapes quotes which throws off
// the span
parse_english(doc.get(doc.range(text.span())?)?, doc, parser, &text.span())
let offset = doc.range(text.span()).unwrap().start + 1;
let text = text.to_untyped().text();
Some(
parser
.parse_str(&text[1..text.len() - 1])
.into_iter()
.map(|mut t| {
t.span.push_by(offset);
t
})
.collect_vec(),
)
}
Expr::Code(a) => constant_token!(doc, a, TokenKind::Unlintable),
Expr::Content(content_block) => {
Expand Down Expand Up @@ -378,7 +387,7 @@ mod tests {
let source = "doesn't";

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

assert_eq!(token_kinds.len(), 1);
Expand All @@ -390,7 +399,7 @@ mod tests {
let source = "person's";

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

assert_eq!(token_kinds.len(), 1);
Expand All @@ -413,7 +422,7 @@ mod tests {
let source = "12 is larger than 11, but much less than 11!";

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

assert!(matches!(
Expand Down Expand Up @@ -449,7 +458,7 @@ mod tests {
let source = "$12 > 11$, $12 << 11!$";

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

assert!(matches!(
Expand All @@ -471,21 +480,52 @@ mod tests {
)"#;

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

let charslice = source.chars().collect_vec();
assert_eq!(tokens[3].span.get_content_string(&charslice), "Typst");
assert_eq!(tokens[2].span.get_content_string(&charslice), "Typst");

assert!(matches!(
token_kinds.as_slice(),
&[
TokenKind::Word(_),
TokenKind::Word(_),
TokenKind::Punctuation(Punctuation::Quote { .. }),
TokenKind::Word(_),
TokenKind::Punctuation(Punctuation::Quote { .. }),
TokenKind::Word(_),
TokenKind::Number(OrderedFloat(2019.0), None),
TokenKind::Word(_), // identifier
TokenKind::Word(_), // key 1
TokenKind::Word(_), // value 1
TokenKind::Word(_), // key 2
TokenKind::Number(OrderedFloat(2019.0), None), // value 2
]
))
}

#[test]
fn str_parsing() {
let source_with_quotes = r#"#let ident = "This is a string""#;
let source_no_quotes = r#"#let ident = This is a string"#;
grantlemons marked this conversation as resolved.
Show resolved Hide resolved

let with_quotes_token_kinds = Typst
.parse_str(source_with_quotes)
.iter()
.map(|t| t.kind)
.collect_vec();
let no_quotes_token_kinds = Typst
.parse_str(source_no_quotes)
.iter()
.map(|t| t.kind)
.collect_vec();

assert_eq!(with_quotes_token_kinds, no_quotes_token_kinds);
assert!(matches!(
&with_quotes_token_kinds.as_slice(),
&[
TokenKind::Word(_), // identifier
TokenKind::Word(_), // This
TokenKind::Space(1),
TokenKind::Word(_), // is
TokenKind::Space(1),
TokenKind::Word(_), // a
TokenKind::Space(1),
TokenKind::Word(_), // string
]
))
}
Expand All @@ -495,7 +535,7 @@ mod tests {
let source = "This is a sentence, it does not have any particularly interesting elements of the typst syntax.";

let tokens = Typst.parse_str(source);
let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();
let token_kinds = tokens.iter().map(|t| t.kind).collect_vec();
dbg!(&token_kinds);

assert!(matches!(
Expand Down
Loading