-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add a 'lines' text writer format #415
Conversation
I've already patched ion-cli to support |
} | ||
} else { | ||
// Otherwise, this is not the first value in this container. Emit the container's | ||
// delimiter (for example: in a list, write a `,`) before we write the value itself. | ||
self.write_value_delimiter()?; | ||
write!(&mut self.output, "{}", self.space_between_values)?; |
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.
Did you consider hooking into the write_value_delimiter
fn that's already switching on ContainerType
or otherwise combining this with that logic?
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 did look at it, but I didn't see a satisfactory way. If I had to put this in write_value_delimiter
then I'd still have to switch there on whether or not to add the whitespace_config.space_between_values
. It also looks to me like write_value_delimiter
is focused on the syntactic delimiters, not the presentation/whitespace additions.
I'd rather leave all the "spacing" concerns in one place, I think.
This also makes me wonder whether the builder ought to validate that all the supplied whitespace values are semantically whitespace.
Per your note, I don't love the 'newline' name either. I don't have a great suggestion, but would suggest something like 'distinct' or '(per|each)(Item|datum)' something something... |
Oof, this didn't show up in I'll have to go to back to the drawing board a bit. |
dabd570
to
2aa1b4b
Compare
Codecov Report
@@ Coverage Diff @@
## main #415 +/- ##
=======================================
Coverage 83.40% 83.41%
=======================================
Files 83 83
Lines 15813 15909 +96
=======================================
+ Hits 13189 13270 +81
- Misses 2624 2639 +15
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Nice job! Some superficial comments below.
src/text/raw_text_writer.rs
Outdated
) -> RawTextWriterBuilder { | ||
self.space_after_field_name = space_after_container_start.into(); | ||
self.whitespace_config.space_after_field_name = space_after_container_start; |
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's some dissonance here that I probably caused but can't remember why. Should space_after_container_start
and space_after_field_name
have two separate setters? Or should we unify their names somehow?
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 just a bug? Here's the relevant snippet of the compact text format configuration:
// Single space between field names and values
space_after_field_name: " ",
// The first value in a container appears next to the opening delimiter
space_after_container_start: "",
and here's the relevant snippet of the pretty text format configuration:
// Field names and values are separated by a single space
space_after_field_name: " ",
// The first value in a container appears on a line by itself
space_after_container_start: "\n",
Both of them have different values for these two fields, and those different values will be used. It's only this setter which conflates them, and no tests exercise this setter.
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 added some tests that exercise the builder setters.
src/text/raw_text_writer.rs
Outdated
// Otherwise use the compact/default layout from `DEFAULT_WS_CONFIG` | ||
..DEFAULT_WS_CONFIG |
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.
💯
indentation: String, | ||
space_after_field_name: String, | ||
space_after_container_start: String, | ||
whitespace_config: Box<WhitespaceConfig>, |
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.
Nice, this drops 96 bytes of stack space down to 8! 🙌
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.
Excellent! 🙌
There's a clippy
suggestion about using !is_empty
instead of != ""
. Could you address that before merging?
Description of changes:
I needed to generate newline-centric Ion data from binary and didn't have an easy way to do it, so I ended up doing something more involved with regular expressions, a small perl script, and reasoning about indentation. This is the capability that I wish I had then.
I've also added a
space_between_top_values
parameter to theRawTextWriterBuilder
so that top-level values can be handled differently, and extracted a heap-allocatedWhitespaceConfig
struct as suggested in the comment around raw text writer whitespace configuration.Please let me know wherever this can be improved, my Rust is as of yet very unoxidized.
Representatives of each format, from the documentation:
default
lines
pretty
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.