Repository navigation
String interpolation - #7620
String interpolation#7620tingerrr wants to merge 7 commits into
Conversation
e8e6ef1 to
28e384d
Compare
28e384d to
6c1e968
Compare
6c1e968 to
f9a39be
Compare
136cdea to
11aba8a
Compare
|
@tingerrr I didn't leave any reviews thus far since this is still marked as draft. Do you still have plans to work on this? If yes, we can keep it open, but I'm going through older PRs trying to establish which ones may actually still move forward. |
|
Yeah, I do plan to finish this, but if somebody else wants to base their work of this and finish it, I wouldn't mind either. |
a6eadca to
5383bc9
Compare
|
I think this can be reviewed now. As always, I suggest going commit by commit, note that some of the commits in this branch are actually part of #7800, so you may want to look at this first. If any of the commit messages are unclear let me know, but I hope they explain my reasoning behind the structure of this patch. |
|
Looks like this needs some conflicts resolved, I'll hopefully get to this during the next weekend. Not sure if you want to set this to |
|
No, it's not really waiting on you after all since the conflicts grew out of review not happening for so long. |
|
I noticed a few issues while resolving those, so there was an upside to it. |
e047f18 to
665cd03
Compare
|
Ok, I've updated this and the PR it depends on. I noticed during the conflict resolution that the dependencies reported for |
a92cf2b to
0281518
Compare
|
I ran into a linker failure on Windows, which I can't really test locally. So I forced a rebuild (hopefully with a fresh cargo cache) by updating the workspace manifest and reverting it again. If that persists, then I'm not sure how to approach this. The failure seems to indicate that the Windows runner can't find the libfuzzer symbol in the fuzzer library itself. EDIT: Turns out it seems to have been a problem before too, but just not triggered until you import something in the |
0281518 to
299a496
Compare
4cd8e28 to
7a1dde5
Compare
| /// Currently, you'll have to do this manually (e.g. by resetting counters, | ||
| /// adjusting selectors, etc.) We | ||
| /// #link("https://github.com/typst/typst/issues/7735#issuecomment-3908841853")[plan | ||
| /// #link("https://github.com/typst/typst/issues/7735\#issuecomment-3908841853")[plan |
There was a problem hiding this comment.
I can't wait for this string interpolation feature (really nice work!) but this is rather unfortunate 🫤 did the team/community discuss other designs like enforcing #{something} and disallowing #something not to break the current links? Or maybe allowing raw wherever str is expected (which would also be a nice quality-of-life feature for asset/html.script/etc) to use #link(`url#fragment`) instead of #link("url\#fragment")?
There was a problem hiding this comment.
Right now I went with the same rules as # in markdown and math for consistency. There was definitely some discussion about it being a breaking change, which is why I also drafted the compatibility mechanism proposed in https://laurmaedje.github.io/posts/evolving-typst/ and based this one on it as a proof of concept.
I also thought about the idea of allowing raw wherever string is allowed, but I haven't thought much about what this could mean otherwise. For example, I always thought that raw syntax would be cool as an alternative to bytes for things that take either a file path or content like bibliography does. Allowing raw in place of strings would prevent that, but perhaps that's not so bad since we got bytes for this.
There was a problem hiding this comment.
I also thought about the idea of allowing raw wherever string is allowed, but I haven't thought much about what this could mean otherwise. For example, I always thought that
rawsyntax would be cool as an alternative tobytesfor things that take either a file path or content likebibliographydoes. Allowingrawin place of strings would prevent that, but perhaps that's not so bad since we gotbytesfor this.
Maybe we can use raw as str only in link which expects a URL (possibly with a URL fragment) and raw as bytes wherever we can pass bytes (bibliography, asset...), as str in those cases would be a path which shouldn't contain #? I guess it would be too "smart" of a feature, but still very convenient:
link("url\#fragment")link(`url#fragment`)bibliography("bib.yaml")bibliography(```yaml ...```)asset("styles.css")asset(```css ...```)
7a1dde5 to
e9c11a1
Compare
e9c11a1 to
3868633
Compare
The preferred compiler version set within a `typst.toml` manifest file applies to every file in the root this manifest is contained in. This preferred version can then be used to opt into limited backwards compatiblity guarantees. For example, a future version of typst may introduce custom types, which require dedicated syntax like a `type` keyword. To avoid making every old version of a package break instantly and forcing the whole ecosystem to migrate effectively at once, the compatibilty feature could retain the old parsing behavior in packages. This allows projects and packages to target new typst version without requiring updates to their dependencies immedately.
By adding a string parsing mode before implementing string interpolation we already gain better highlighting for string escapes and a base line from which we can make it conditional without disturbing the AST structure too much. This subtly changes the structure for tests which directly depend on raw highlighting of typst code itself, as the strings are emitted in parts instead of a while. However, the overall positioning is left intact. I deliberately kept this patch from introducing visible changes in the output to keep the structural change sound before actually adding string interpolation.
Escape sequences in string such as `\n` or `\u{1b}` now get highlighted
the same as markup escape sequences.
By making hashes no longer optional and removing them from the representation we remove the most common usage of `#` in strings in prepration for string interpolation.
The binaries likely already have the test and doc targets disabled to fix this exact issue. Although it doesn't explicitly state this, there's strong evidence at: https://rust-fuzz.github.io/book/cargo-fuzz/windows/dll-fuzzing.html#msvc-and-libfuzzers-main-function This seems to be triggered for the library only once you actually import symbols from `libfuzzer_sys`.
3868633 to
729d5a6
Compare
String interpolation is a syntax feature with which values can be conveniently embedded into strings. It works similar to placing values in document markup. It can also be though of as syntax sugar for concatenating the string representation of values into pure string literals, but the string representation follows slightly different conversion rules than just `str` or `repr`. For example, the string representation chosen for an array `a` may be the same as `repr(a)`, but the string representation of a string `s` is just `s`.
729d5a6 to
e6c5c19
Compare
|
Here's extra context from the discord server:
This question about how to handle reparsing is still open. In general, reparsing with a different version than before shouldn't regularly happen, but it can happen. Either a user edits a package manifest or a third party tool allows configuring the preferred project version or we later allow something else that invalidates this assumption. Right now we don't encode this assumption, we don't force rewriting the source when the version changes and the reparse function has no idea what the original version was so it can't do it either. I dont' remember adding anything about this sort of invalidation so this would still be a bug in the current implementation that has to be resolved. Storing the version in there somehow seems sensible, but it would also be a sort of temporary field for the compatibility behavior. That feels like a stop gap, but I don't think it really is. I'm open to suggestions on how to handle this. |
This is a draft, I only opened this because it's easier to check out this way. The exact syntax and semantics for non-string values will be discussed in the syntax forge.
Resolves #2267.