-
Notifications
You must be signed in to change notification settings - Fork 503
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
Implement format/interpolation strings #822
Conversation
Some of the code diffs were accidentally caused by my editor auto-running |
Nice! Today's a little busy, but I should definitely be able to check this out tomorrow. |
UnterminatedBacktick => { | ||
writeln!(f, "Unterminated backtick")?; | ||
}, | ||
UnterminatedFormatString => { |
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.
There should probably be an UnterminatedFormatBacktick
variant as well.
// TODO: | ||
// - what token should format backticks be? | ||
// - how are format strings dedented? | ||
// - brag about recursive format strings | ||
// - test empty format string interpolation error | ||
// - handle backticks | ||
// - test format string evaluation | ||
// - format strings with text immediatle before and after inteprolation | ||
// start/end | ||
// - test format strings inside of recipe bodies | ||
// - test multi-line format strings inside of recipe bodies | ||
// - test open delimiters with multiple lines inside of recipe bodies | ||
// - test multi-line strings inside of recipe bodies | ||
// - combine backticks and string literals | ||
// - must avoid parsing format string or backtick in shell setting | ||
|
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.
// TODO: | |
// - what token should format backticks be? | |
// - how are format strings dedented? | |
// - brag about recursive format strings | |
// - test empty format string interpolation error | |
// - handle backticks | |
// - test format string evaluation | |
// - format strings with text immediatle before and after inteprolation | |
// start/end | |
// - test format strings inside of recipe bodies | |
// - test multi-line format strings inside of recipe bodies | |
// - test open delimiters with multiple lines inside of recipe bodies | |
// - test multi-line strings inside of recipe bodies | |
// - combine backticks and string literals | |
// - must avoid parsing format string or backtick in shell setting |
I'll comment with the ones in this list that are still to do.
This looks great so far.
|
Just pushed a couple more commits removing the old unindent functions. I promise I'm done pushing to this branch for now. |
Thanks for the tips! I'll take a look & work on this in the next couple days. |
Running into a few uncertainties trying to implement
|
Good points! I think that the issue with slicing being O(n) isn't something we should worry about. As you mentioned, N is likely to be small enough that even if our algorithm is terrible, it will still be fast enough that nobody will notice. Also, in general, I think it's a good idea to worry about being correct before worrying about being fast. After we have a correct and slow implementation with a bunch of tests, we can replace the correct and slow implementation with a correct and fast implementation. You propose some good optimizations, but optimizations should always be led by profiling that shows that an operation is slow, needs to be optimized, and that the optimizations actually improve things. That being said, if there's a cleaner or simpler implementation, then that is worth considering up front. I think that I'm kind of ambivalent as to whether an Regarding join ownership, adding |
Sorry I've left this to stagnate for a bit-- a bunch of other obligations have popped up in my life, leaving me with little leisure to work on this. I'm not abandoning this PR, but it might be another month or so until I'll be able to come back to it--if anyone else comes across this and wants to pick up the work, feel free! Otherwise, see you in a month. |
No worries at all, life happens! And the original issue for this feature was opened in 2016, so what's another month or few. |
This has gone pretty stale. Feel free to reopen! |
Resolves #11.
This PR builds off of @casey's existing work on parsing interpolation strings:
While it appears to work correctly, the code I've written to do so is pretty patchy, and a few more things are needed for reliability & maintainability:
Add some evaluation tests?
Possibly refactor the un-indenting code.
Because of the way interpolated strings are structured (
Vec<Fragment>
), it's not really possible to re-use the existing logic inunindent.rs
, which acts on individual&str
s. (It's not sufficient to rununindent
on each one of theText
fragments individually, because the common indentation needs to be calculated across the entire string, i.e. all fragments, not simply all lines for a given fragment.)As such, a lot of the logic of
unindent
had to be reimplemented, but with a lot more consideration for edge-cases, etc. The resulting code is pretty messy and hard to read, and I have an idea about how to re-architect theFormatString
type to be able to re-use the existingunindent
code cleanly, but it requires some heavier refactoring, so I've held off on it for now to see if other contributors have any better thoughts/comments on this challenge.@casey if it's not too much trouble, perhaps you can take a look at this & offer some suggestions on how to tidy up the code? Thanks!