Skip to content

[DESIGN] Effect of selectors on placeholders #755

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

Merged
merged 15 commits into from
May 6, 2024

Conversation

aphillips
Copy link
Member

@aphillips aphillips commented Mar 27, 2024

Fixes #736, Works on #747

This design document describes the effect of selectors on subsequent pattern placeholders of the same operand. It presents several alternatives.

This is still in "DRAFT" form and not yet ready for the WG as a whole.

Addresses #736, #747 

DO NOT REVIEW YET == WORK IN PROGRESS
@aphillips aphillips added design Design document or issues related to design formatting Issue pertains to the formatting section of the spec LDML46 LDML46 Release (Tech Preview - October 2024) Action-Item Action item assigned by the WG labels Mar 27, 2024
@eemeli eemeli marked this pull request as draft March 27, 2024 21:53
@aphillips
Copy link
Member Author

Adding some review requests... looking for early feedback and suggestions.

@aphillips aphillips marked this pull request as ready for review April 11, 2024 18:29
Copy link
Collaborator

@catamorphism catamorphism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does a good job of laying out the alternatives. The use of "side effect" or "mutable" should be avoided, since the only thing being talked about is name binding, and likewise, since we're talking about name binding, it should be clarified when "operands" really means "variables". On the whole, I was able to follow it and I can't think of any missing alternatives (except for doing nothing.)


In this alternative, selectors are treated as declaration-selectors.
That is, an annotation in a selector works like a `.input`.
However, it is an error for the selector to try to modify a previous declaration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
However, it is an error for the selector to try to modify a previous declaration
However, it is an error for the selector to shadow a previous declaration

(just as it is an error for a declaration to try to modify a previous declaration).
This permits `.match` selectors to be a shorthand when no declarations exist.

It is also an error for a selector to modify a previous selector.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is also an error for a selector to modify a previous selector.
It is also an error for a selector to shadow a previous selector.

(Again, this needs some qualifiers... writing .match {-1 :integer} {-1 :number} shouldn't be an error.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example you gave doesn't modify a previous selector: the literal -1 in the first is a separate literal from that in the second. "Shadow" doesn't really say what is going on?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a selector implicitly introduces a name, then what you're referring to as "modifying" is actually "shadowing". If you write, in this scenario:

.match {$x :integer} {$x :number} 

then the second $x doesn't modify the first one. Rather, it introduces a new name $x, so that in the patterns in the variants, $x now has a different meaning. That's what I mean by name shadowing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$x (a variable by the name of x in the formatting context) is different from the literal -1 (which is just a string--in your example, the second one is a different string that contains the same characters as the first).

I'm steering clear of "shadowing" because the thing that is or is not affected is the (ill-defined) "resolved value" in the formatting context (which I tend to think of as a Map<String,ResolvedValue>). I think it is clearer to say that the second $x in your example is "trying to modify" the resolved value of $x in the formatting context.

- Enables representation of many messages without any declarations

**Cons**
- Confusing that the operand name can't be used in the pattern?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the operand name have to be disallowed from appearing in the pattern?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not worded correctly. You can use the operand name in the pattern, but it's annotation won't/might not be applied.

.match {$count :integer}
* {{You have {$count} apples might print 2 or 2.0 with input count=|2.0|}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so maybe something like: "The meaning of the operand name in the context of the pattern might not be what the user expects"?

aphillips and others added 6 commits April 21, 2024 07:39
Co-authored-by: Eemeli Aro <eemeli@mozilla.com>
Co-authored-by: Tim Chevalier <tjc@igalia.com>
Co-authored-by: Tim Chevalier <tjc@igalia.com>
Co-authored-by: Tim Chevalier <tjc@igalia.com>
Co-authored-by: Tim Chevalier <tjc@igalia.com>
aphillips and others added 2 commits April 24, 2024 10:40
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
@aphillips
Copy link
Member Author

Are we waiting on something to merge this design document? The meeting notes for 2024-04-29 (which I missed and was chaired by @eemeli) seem to indicate that @mihnita has a comment, but no other objections.

Copy link
Collaborator

@eemeli eemeli left a 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 fine to land as "proposed". We should also make our in-flight design docs more prominent and separate from the accepted ones, as I tried to do in #616.

@aphillips aphillips merged commit ebb8dae into main May 6, 2024
1 check passed
@aphillips aphillips deleted the aphillips-selection-declaration branch May 6, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Action-Item Action item assigned by the WG design Design document or issues related to design formatting Issue pertains to the formatting section of the spec LDML46 LDML46 Release (Tech Preview - October 2024)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Match expressions should be re-usable in placeholders
4 participants