Skip to content
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

(third) Implement formatToParts #189

Merged
merged 5 commits into from
Aug 18, 2021
Merged

(third) Implement formatToParts #189

merged 5 commits into from
Aug 18, 2021

Conversation

stasm
Copy link
Collaborator

@stasm stasm commented Aug 18, 2021

This is a prototype implementation of the formatToParts iterator discussed in #41. The approach taken is the one from #41 (comment) by @eemeli with one modification:

  • the iterator yields a flat sequence of parts,
  • a part can either be a FormattedPart {type: string, value: string} or an OpaquePart,
  • FormattedPart doesn't have the source field carrying the original raw value; it was easier to do it that way but also it's consistent with existing formatToParts specifications,
  • patterns coming from message references are flattened into the final sequence.

Examples:

let payloadSize = 1.23;
"Transferred {NUMBER $payloadSize STYLE unit UNIT megabyte}."

{ type: 'literal', value: 'Transferred ' },
{ type: 'integer', value: '1' },
{ type: 'decimal', value: '.' },
{ type: 'fraction', value: '23' },
{ type: 'literal', value: ' ' },
{ type: 'unit', value: 'MB' },
{ type: 'literal', value: '.' }
let submitButton = new SomeUnstringifiableClass();
"Ready? Then {$submitButton}!"

{ type: 'literal', value: 'Ready? Then  ' },
{ type: 'opaque', value: SomeUnstringifiableClass {} },
{ type: 'literal', value: '!' }

@stasm stasm changed the base branch from master to experiments August 18, 2021 06:15
@stasm
Copy link
Collaborator Author

stasm commented Aug 18, 2021

(Sorry for the notification noise for everyone whom GitHub autoflagged for a review. I accidentally opened this PR against master which triggered the code owners reviews.)

@stasm stasm changed the base branch from experiments to notes-2020-04-18 August 18, 2021 07:13
@stasm stasm changed the base branch from notes-2020-04-18 to experiments August 18, 2021 07:13
@stasm stasm force-pushed the third-formatToParts branch from 43e0a14 to fc963f6 Compare August 18, 2021 08:02
@stasm stasm merged commit 661ecc6 into experiments Aug 18, 2021
@stasm stasm deleted the third-formatToParts branch August 18, 2021 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant