[Don't merge] TypedIdentifier, Box<str> and other tweaks - #5
Open
maciejhirsz wants to merge 1 commit into
Open
Conversation
Owner
|
Thank you, this looks great! Would it be possible to split up the changes into multiple PRs? If so, can we start with one, get it merged and so forth? |
Author
|
@axic sure, I'll break down the PR tomorrow. |
Owner
|
Nice! Lets just start with a single change first and then we can keep coming back to this PR to pick the other changes from. |
Open
chriseth
pushed a commit
to chriseth/yultsur
that referenced
this pull request
Aug 5, 2022
Fix switch parsing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Will be crossing out things in this PR as they are moved to their own smaller PRs:
AddedTypedIdentifier, following the grammar spec, that must have a type. Function definitions and variable declarations now useVec<TypedIdentifier>instead ofVec<Identifier>.Identifieris now a newtype wrapping aBox<str>, following the grammar spec it does not allow a type to be attached.Box<str>instead ofStringto reduce the size of the AST in memory. PreviouslyIdentifierused to take 7 words (56 bytes on 64bit arch), nowIdentifiertakes 2 words whileTypedIdentifiertakes 5.AddedFromimpls to easily create instances ofIdentifierfrom string literals ("foo".into()orIdentifier::from("foo")).Literalnow usesBox<str>instead ofString(same reason as above) and must have a type as per grammar definition.Fromimps forLiteralthat allows to quickly create them from Rust literals (eg.Literal::from(42u8) == Literal { literal: "42".into(), yultype: Type::Uint8 }).Validatorimpl forIdentifierchecks that the identifier is in accordance with the grammar.Changed the error type fromStringto&'static strin the validator, although customenumor using theerror_chaincrate would be better here I reckon.Displayimpls got their list printing reworked with a helper function that is much more efficient. I'm not sure if usingDisplayis the best choice here, a custom trait could be way more efficient and would allow for different formatting options, if needed.