- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Codify and Resolve modifiers #46
base: main
Are you sure you want to change the base?
Conversation
Like with #27, we can wait until Typst 0.13.0 is released to open the discussion and decide whether this should be part of Codex. |
Related: #51. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a lot of comments and suggestions. Of course, feel free to disagree.
I really like the ModifierSet
abstraction. If feels very clean. I'm not a fan of the include!
trick and the macro, but it's probably fine.
Regarding the ModifierSet::iter
and ModifierSet::<&'a str>::to_iter
methods, I feel like this could be achieved more idiomatically with two separate impl<'a, S: Deref<Target = str>> IntoIterator for &'a ModifierSet<S>
and impl<'a> IntoIterator for ModifierSet<&'a str>
.
Thanks for the review!
The same effect could also be achieved by writing #[path = ...]
mod shared;
use shared::*; but that's three lines instead of one, which was the deciding factor. |
I feel like this would be more idiomatic, but it doesn't matter that much. Also, it may be useful for later to have something like |
For that, there's the issue of an empty iterator. Should it just require Edit: While the implementation might be easy, the API is totally full of caveats, since individual iterator items could contain the character I think I'll leave this out for now, it requires too much additional design work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@laurmaedje you may want to review this PR |
@laurmaedje I'm taking the liberty to ping you again as you are more active in PR reviews now. |
Yes, I'll try to get to this in the next few days. (If I still haven't done it in a week or so, please feel free to ping me again and then I'll do it right away.) |
I'm not a fan of macros, so I'm not sure I like this change, but in any case, I think it would be best to discuss this separately from this PR. The fact that I was unsure whether I liked that is part of why it took me so long to respond here. If I see things correctly, the |
Not yet, but I'd need it for #27...
I'll see what I can do, but I'm not happy about this. |
I've removed the macro, but kept Having done this change directly, I'm now actually unsure myself whether the macro was worth it, in a "both sides are bad" kind of way, so I probably won't make another PR for that, at least for now. |
Also, minor stylistic question, but should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think keeping it as shared.rs
is fine and more future proof. Assuming all the Typst functionality can be implemented with this, the API looks fine to me!
// note: the visibility needs to be `pub(crate)`, | ||
// since build.rs outputs `ModifierSet(...)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is outdated since it uses new_unchecked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the point where it gets output is
Line 217 in 34edb09
Symbol::Multi(list) => write!(buf, "Multi(&{list:?})").unwrap(), |
which uses the debug-formatting, which outputs
ModifierSet(<string>)
.Changing that would of course be possible, but it'd require constructing the slice manually instead of just using
{:?}
there.
Cool, I'll get working on a PR to typst then. |
Before we merge: While writing the typst PR, I just ran into the issue of What should I do about those? Edit: For now, I opted to just derive them too for the sake of efficiency and to add a note to the documentation. This has to be fine, since the equality-checks and hashes resulting from this are in principle identical to the string-based ones originally used in typst. |
Scratch that, I found a better way. |
This reverts commit ff6b56a.
This reverts commit 039f401.
|
Now I'm getting a panic for some reason. Please wait with merging this until I've dealt with all issues in typst/typst#6159. |
Okay, bug fixed. This issue has brought up the need for some unit tests for |
Should be ready to merge now. (And sorry for the inbox spam) |
Closes #30.
The most important idea of this PR is that it codifies what a "modifier" is.
In that aspect, it stands on its own and makes sense even without considering the context of usage in typst.
For this, there is a new
ModifierSet
type that contains all the logic for comparing and composing modifiers.This new type is designed to be generic, so that typst can reuse it with
EcoString
.(In particular, typst's
symbol::Repr::Modified
would change toModified(Arc<(List, ModifierSet<EcoString>)>)
)Some private functions from
typst-library/src/foundations/symbol.rs
are lifted to public methods onModifierSet
:parts
becomesModifierSet::iter
contained
becomesModifierSet::contains
find
becomesModifierSet::best_match_in
(with reversed argument order), which is generic since it was really easy to make it so and this prepares it for when we let symbols have more than onechar
per variant (cf. Emoji Variation selectors #25)I've also taken the liberty of consolidating the types from
lib.rs
andbuild.rs
. It bugged me that they were duplicated and this change didn't really do anything in terms of code size while arguably improving maintainability (unless you don't like macros, but even among macros this one is very tame).There are some new functions (
get
,variants
andmodifiers
) oncodex::Symbol
that somewhat mirror the ones on typst'sSymbol
, but aren't intended to replace them right now (for why, see the next paragraph). They just made sense to add anyway.The only changes made to typst would be to start using
ModifierSet
, which would basically have the effect of having moved the relevant code from typst to codex.Actually integrating typst's
symbol::Repr::Modified
into codex proved too complicated, so I left that for later (if we even need it). Further considerations regarding the integrating of this into typst is left to a future PR at typst/typst (only if this one is accepted, of course).