Improve clarity of ast.rs for newcomers to the codebase#5784
Improve clarity of ast.rs for newcomers to the codebase#5784laurmaedje merged 8 commits intotypst:mainfrom
ast.rs for newcomers to the codebase#5784Conversation
T0mstone
left a comment
There was a problem hiding this comment.
The second commit also has a typo ("macth" instead of "match")
PgBiel
left a comment
There was a problem hiding this comment.
Great job, thank you! Here are some of my thoughts.
f8bd422 to
9046fef
Compare
|
I pushed the rewrites and also 4 small changes:
|
Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com> Co-authored-by: T0mstone <39707032+T0mstone@users.noreply.github.com>
|
Alright, rebased off main and tried to update to match the new feedback, I also reorganized the commits again so they should be more atomic. There are still a few unresolved comments I'd like responses to, but I'm otherwise happy with this. Thanks everyone for the feedback! I appreciate the help :) |
|
Looks good to merge for me.
Which? I see only this one, but I think the wording is fine tbh. |
|
That quote was mainly for the other comment that we already resolved. (#5784 (comment)) |
|
Okay. Then, thank you! |
Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com> Co-authored-by: T0mstone <39707032+T0mstone@users.noreply.github.com>
* build: use nightly typst, typst-ansi-hl, typstyle, reflexo; update ttf-parser, fontdb * refactor: new eval_string api * refactor: typst::html -> typst_html fixup * refactor: new Source lines api in typst/typst/6308 * refactor: new ast::Expr enum names in typst/typst#5784 * refactor: new color api in typst/typst#6479 * refactor: new element api in typst/typst#6547 * refactor: new html frame api in typst/typst#6505 * refactor: new label constructing api in typst/typst#6332 * refactor: new symbol api in typst/typst#6441 * fix: catch_unwind when printing Ty's debug format * styl: fmt * refactor: use new LibraryExt mod fixup 2 * fix: increase recursion limit for tinymist-query * tests: update test snaps * ci: continue on error * build: bump world crates to 0.13.15-rc1 * build: pin reflexo, typstyle fixup 3 * build: bump to 0.13.15-rc1 * docs: changelog * ci: update windows version
* build: use nightly typst, typst-ansi-hl, typstyle, reflexo; update ttf-parser,fontdb * refactor: new eval_string api * refactor: typst::html -> typst_html * refactor: new Source lines api in typst/typst/6308 * refactor: new ast::Expr enum names in typst/typst#5784 * refactor: new color api in typst/typst#6479 * refactor: new element api in typst/typst#6547 * refactor: new html frame api in typst/typst#6505 * refactor: new label constructing api in typst/typst#6332 * refactor: new symbol api in typst/typst#6441 * fix: catch_unwind when printing Ty's debug format * styl: fmt * refactor: use new LibraryExt mod * fix: increase recursion limit for tinymist-query * tests: update test snaps * ci: continue on error * deps: update rustc * tests: update test snaps * deps: patch reflexo * refactor(typlite): replace manual highlight and strike with official impl * tests: update test snaps for shortened empty attributes syntax * tests(typlite): update test snaps to ignore outline temporarily * fix(typlite): convert link * feat: auto release nightly * feat: auto tag stable release
This is a set of small changes to the
typst-syntax/src/ast.rsfile designed to improve clarity of the code for newcomers. I personally had a lot of trouble understanding this file the first time I encountered it (many months ago), and wanted to document its behavior and make some improvements while it's still top-of-mind.Add big comment and require the
structkeyword in thenode!macro (e.g.node! {Raw}vs.node! {struct Raw}). I think my original confusion withast.rswas with where all of the data-types were declared. The way enums were laid out combined withnode!using only the SyntaxKind name was unhelpful. Addingstructmakes it feel much clearer to me thatnode!is generating new types. And the added comment onnode!should also be a nice improvement.Removed comments on the enum variants of
Expr(the structs they contain are already commented) and renamed the variants that didn't match their SyntaxKind names.Changed the calls to
node.cast().map()infrom_untypedfor the various implementations to construct the node structs more directly. The currentnode.cast().map()requires type inference that may be obvious to the compiler, but is not obvious to humans on first reading. It does reduce the dependency on the name of each node kind, but I think the current syntax obscures the real operation more than is worth avoiding one extra repeated name in each line. There are still calls tonode.cast().map()in thefrom_untypedimpl, but only in wildcard matches, where it should be easier to figure out what the desired effect is.I'm very open to nitpicks or rewordings of the main long doc comment in commit 1. But I think it does roughly what it needs to atm.
Also fine with backing out any of these changes or maybe putting the module comment somewhere else. But my main goal is to improve clarity for newcomers to the codebase, and I think these changes should help with that.