Skip to content

Commit 5147589

Browse files
aphillipsgithub-actions[bot]stasmeemeli
authored
Beauty Contest for Various Syntaxes (#485)
* Create 0483-beauty-contest.md * style: Apply Prettier * Update 0483-beauty-contest.md * style: Apply Prettier * tweaks to single-line * Update 0483-beauty-contest.md * Update exploration/0483-beauty-contest.md Co-authored-by: Stanisław Małolepszy <[email protected]> * More examples * style: Apply Prettier * Update 0483-beauty-contest.md * Add Mihai's example * style: Apply Prettier * Refining layout - number the options - add a mixed option - clean up some of the options * style: Apply Prettier * typo... * Rename 0483-beauty-contest.md to beauty-contest.md Removing numbering per discussion * Start implementing whitespace decision * Add option 1a, fix mistakes in option 0 * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md * style: Apply Prettier * Update exploration/beauty-contest.md * style: Apply Prettier * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Fix contestant 4 Fix the syntax to be workable. Change "inside a pattern" to "in a pattern" because "inside" implies interior to the pattern, not necessarily on the ends. * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Add 3a per slack conversation * style: Apply Prettier * Add feature description table * style: Apply Prettier * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> * Update exploration/beauty-contest.md Co-authored-by: Eemeli Aro <[email protected]> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Stanisław Małolepszy <[email protected]> Co-authored-by: Eemeli Aro <[email protected]> Co-authored-by: Eemeli Aro <[email protected]>
1 parent be4e716 commit 5147589

File tree

1 file changed

+384
-0
lines changed

1 file changed

+384
-0
lines changed

exploration/beauty-contest.md

Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,384 @@
1+
# Syntax Variation Beauty Contest
2+
3+
As discussed in the 2023-09-25 teleconference, we need to choose a syntax to proceed with.
4+
This page hosts various options for considering in the 2023-10-02 call.
5+
6+
## Shorthand description of some aspects of the options
7+
8+
Please dispute factual errors in this. The table uses multiple `-` when an option requires more than one of something. `+` is not weighted.
9+
10+
| Option | Description | Doesn’t Nest {} | Doesn’t Need More Escapes | Doesn’t Require Quoted Pattern | Allows Unquoted Literal Operands | Counted {} works | Adds no sigils |
11+
| :----- | :------------------------------------------------------------- | :-------------- | :------------------------ | :----------------------------- | :------------------------------- | :--------------- | :------------- |
12+
| 0 | Current syntax, starts in code mode | - | + | -- | + | - | + |
13+
| 1 | Invert for text mode | - | + | + | - | + | + |
14+
| 1a | Invert for text mode, distinguish statements from placeholders | - | + | + | + | + | - |
15+
| 2 | Text first, but always code mode after code | - | + | - | - | + | + |
16+
| 3 | Use sigils for code mode | + | - | + | + | + | -- |
17+
| 3a | Use sigils for code mode, use {/} for keys | + | - | + | + | + | - |
18+
| 4 | Reducing keywords | + | --- | + | + | + | --- |
19+
| 5 | Use blocks for declarations and body | -- | - | + | - | - | - |
20+
| 5a | Use blocks for declarations but sigils for selectors | + | -- | + | - | - | - |
21+
| 6 | Use statements | -- | --- | + | + | + | - |
22+
23+
## 0. Current
24+
25+
This is the current syntax,
26+
including the changes introduced in [#488](https://github.com/unicode-org/message-format-wg/pull/488).
27+
The list of messages in this section also serves as the basis for all other examples.
28+
29+
```
30+
{Hello world!}
31+
32+
{Hello {$user}}
33+
34+
input {$var :function option=value}
35+
{Hello {$var}}
36+
37+
input {$var :function option=value}
38+
local $foo = {$bar :function option=value}
39+
{Hello {$var}, you have a {$foo}}
40+
41+
match {$foo} {$bar}
42+
when foo bar {Hello {$foo} you have a {$var}}
43+
when * * {{$foo} hello you have a {$var}}
44+
45+
match {$foo :function option=value} {$bar :function option=value}
46+
when a b { {$foo} is {$bar} }
47+
when x y { {$foo} is {$bar} }
48+
when * * { {$foo} is {$bar} }
49+
50+
input {$var :function option=value} local $foo = {$bar :function option=value}{Hello {$var}, you have a {$foo}}
51+
52+
match {$foo} {$bar} when foo bar {Hello {$foo} you have a {$var}} when * * {{$foo} hello you have a {$var}}
53+
54+
match {$foo :function option=value} {$bar :function option=value}when a b { {$foo} is {$bar} }when x y { {$foo} is {$bar} }when * * { {$foo} is {$bar} }
55+
```
56+
57+
## 1. Invert for Text Mode
58+
59+
Consumes exterior whitespace.
60+
61+
Requires dropping unquoted literal operands from the syntax.
62+
63+
```
64+
Hello world!
65+
66+
Hello {$user}
67+
68+
{input $var :function option=value}
69+
Hello {$var}
70+
71+
{input $var :function option=value}
72+
{local $foo = $bar :function option=value}
73+
Hello {$var}, you have a {$foo}
74+
75+
{match {$foo} {$bar}}
76+
{when foo bar} Hello {$foo} you have a {$var}
77+
{when * *} {$foo} hello you have a {$var}
78+
79+
{match {$foo :function option=value} {$bar :function option=value}}
80+
{when a b} {{ {$foo} is {$bar} }}
81+
{when x y} {{ {$foo} is {$bar} }}
82+
{when * *} {| |}{$foo} is {$bar}{| |}
83+
84+
{input $var :function option=value}{local $foo = $bar :function option=value}Hello {$var}, you have a {$foo}
85+
86+
{match {$foo} {$bar}}{when foo bar} Hello {$foo} you have a {$var}{when * *} {$foo} hello you have a {$var}
87+
88+
{match {$foo :function option=value}{$bar :function option=value}}{when a b} {{ {$foo} is {$bar} }}{when x y} {{ {$foo} is {$bar} }}{when * *} {| |}{$foo} is {$bar}{| |}
89+
```
90+
91+
## 1a. Invert for Text Mode, distinguish statements from placeholders
92+
93+
Same as 1, but non-placeholder statements use a `#` prefix.
94+
This allows us to keep unquoted literal syntax.
95+
96+
```
97+
Hello world!
98+
99+
Hello {$user}
100+
101+
{#input $var :function option=value}
102+
Hello {$var}
103+
104+
{#input $var :function option=value}
105+
{#local $foo = $bar :function option=value}
106+
Hello {$var}, you have a {$foo}
107+
108+
{#match {$foo} {$bar}}
109+
{#when foo bar} Hello {$foo} you have a {$var}
110+
{#when * *} {$foo} hello you have a {$var}
111+
112+
{#match {$foo :function option=value} {$bar :function option=value}}
113+
{#when a b} {{ {$foo} is {$bar} }}
114+
{#when x y} {{ {$foo} is {$bar} }}
115+
{#when * *} {| |}{$foo} is {$bar}{| |}
116+
117+
{#input $var :function option=value} {#local $foo = $bar :function option=value} Hello {$var}, you have a {$foo}
118+
119+
{#match {$foo} {$bar}} {#when foo bar} Hello {$foo} you have a {$var} {#when * *} {$foo} hello you have a {$var}
120+
121+
{#match {$foo :function option=value}{$bar :function option=value}} {#when a b} {{ {$foo} is {$bar} }} {#when x y} {{ {$foo} is {$bar} }} {#when * *} {| |}{$foo} is {$bar}{| |}
122+
```
123+
124+
## 2. Text First, but Always Code After Code-Mode
125+
126+
This is @mihnita's proposal, mentioned in the 2023-10-02 call.
127+
Start in text mode, but stay in code mode once you get there.
128+
Adapted @eemeli's start-in-text-mode syntax for these examples.
129+
130+
Requires dropping unquoted literal operands from the syntax.
131+
132+
```
133+
Hello world!
134+
135+
Hello {$user}
136+
137+
{input $var :function option=value}
138+
{{Hello {$var}}}
139+
140+
{input $var :function option=value}
141+
{local $foo = $bar :function option=value}
142+
{{Hello {$var}, you have a {$foo}}}
143+
144+
{match {$foo} {$bar}}
145+
{when foo bar} {{Hello {$foo} you have a {$var}}}
146+
{when * *} {{{$foo} hello you have a {$var}}}
147+
148+
{match {$foo :function option=value} {$bar :function option=value}}
149+
{when a b} {{ {$foo} is {$bar} }}
150+
{when x y} {{ {$foo} is {$bar} }}
151+
152+
{input $var :function option=value}{local $foo = $bar :function option=value}{{Hello {$var}, you have a {$foo}}}
153+
154+
{match {$foo} {$bar}}{when foo bar} {{Hello {$foo} you have a {$var}}}{when * *}{{{$foo} hello you have a {$var}}}
155+
156+
{match {$foo :function option=value}{$bar :function option=value}}{when a b} { {$foo} is {$bar} }{when x y} { {$foo} is {$bar} }
157+
```
158+
159+
## 3. Use sigils for code mode
160+
161+
Try to redues the use of `{`/`}` to just expressions and placeholders instead of the three
162+
uses we have now (the other use is for patterns). This requires escaping whitespace or using
163+
a placeholder for it.
164+
See [#487](https://github.com/unicode-org/message-format-wg/pull/487) for a discussion of whitespace options.
165+
166+
The sigil `#` was chosen because `#define` type constructs are fairly common.
167+
Introduces `[`/`]` for keys.
168+
169+
Requires escaping `#` when used as a pattern character.
170+
171+
```
172+
#input {$var :function option=value}
173+
Hello {$var}
174+
175+
#input {$var :function option=value}
176+
#local $foo = {$bar :function option=value}
177+
Hello {$var}, you have a {$foo}
178+
179+
#match {$foo} {$bar}
180+
#when[foo bar] Hello {$foo} you have a {$var}
181+
#when[ * *] {$foo} hello you have a {$var}
182+
183+
#match {$foo :function option=value} {$bar :function option=value}
184+
#when [a b] {{ {$foo} is {$bar} }}
185+
#when [x y] {||} {$foo} is {$bar} {||}
186+
#when [* *] {| |}{$foo} is {$bar}{| |}
187+
188+
#input {$var :function option=value}#local $foo = {$bar :function option=value}Hello {$var}, you have a {$foo}
189+
190+
#match {$foo} {$bar}#when[foo bar] Hello {$foo} you have a {$var}#when[* *] {$foo} hello you have a {$var}
191+
192+
#match {$foo :function option=value} {$bar :function option=value}#when [a b] {{ {$foo} is {$bar} }} #when [x y] {||} {$foo} is {$bar} {||}#when [* *] {| |}{$foo} is {$bar}{| |}
193+
```
194+
195+
## 3a. Use sigils for code mode, use `{`/`}` for keys
196+
197+
Similar to 3, but uses braces instead of `[`/`]` square brackets for keys, reducing variation and
198+
the need for additional pattern escapes.
199+
See Slack thread.
200+
201+
Requires `#` to be escaped in unquoted patterns.
202+
203+
```
204+
#input {$var :function option=value}
205+
Hello {$var}
206+
207+
#input {$var :function option=value}
208+
#local $foo = {$bar :function option=value}
209+
Hello {$var}, you have a {$foo}
210+
211+
#match {$foo} {$bar}
212+
#when{foo bar} Hello {$foo} you have a {$var}
213+
#when{ * *} {$foo} hello you have a {$var}
214+
215+
#match {$foo :function option=value} {$bar :function option=value}
216+
#when {a b} {{ {$foo} is {$bar} }}
217+
#when {x y} {||} {$foo} is {$bar} {||}
218+
#when {* *} {| |}{$foo} is {$bar}{| |}
219+
220+
#input {$var :function option=value}#local $foo = {$bar :function option=value}Hello {$var}, you have a {$foo}
221+
222+
#match {$foo} {$bar}#when{foo bar} Hello {$foo} you have a {$var}#when{* *} {$foo} hello you have a {$var}
223+
224+
#match {$foo :function option=value} {$bar :function option=value}#when{a b}{{ {$foo} is {$bar} }} #when{x y}{||} {$foo} is {$bar} {||}#when{* *}{| |}{$foo} is {$bar}{| |}
225+
```
226+
227+
## 4. Reducing keywords
228+
229+
Avoids keywords in favor of sigil based parsing.
230+
The theory here is that the syntactic sugar of `match` and `when` are nice the first time you use them
231+
but the benefit is lost or reduced after that.
232+
233+
Uses double or paired sigils to reduce the need for escaping common characters (such as `?`)
234+
235+
Requires escaping `#` in a pattern.
236+
Requires escaping `??` at the start of a pattern.
237+
Requires escaping `::[` in a pattern.
238+
239+
```
240+
#{$var :function option=value}
241+
Hello {$var}
242+
243+
#{$var :function option=value}
244+
#$foo = {$bar :function option=value}
245+
Hello {$var}, you have a {$foo}
246+
247+
?? {$foo} {$bar}
248+
::[ foo bar] Hello {$foo} you have a {$var}
249+
::[ * *] {$foo} hello you have a {$var}
250+
251+
?? {$foo :function option=value} {$bar :function option=value}
252+
::[a b] {{ {$foo} is {$bar} }}
253+
::[x y] {{ {$foo} is {$bar} }}
254+
::[* *] {| |}{$foo} is {$bar}{| |}
255+
256+
#{$var :function option=value}#$foo = {$bar :function option=value}Hello {$var}, you have a {$foo}
257+
258+
??{$foo}{$bar}::[foo bar] Hello {$foo} you have a {$var}::[* *] {$foo} hello you have a {$var}
259+
260+
??{$foo :function option=value}{$bar :function option=value}::[a b] { {$foo} is {$bar} }::[x y] { {$foo} is {$bar} }::[* *] {| |}{$foo} is {$bar}{| |}
261+
```
262+
263+
## 5. Use "blocks" for declarations and body
264+
265+
Use code-mode "blocks" to introduce code. _(This section has an additional example)_
266+
267+
The theory here is that a "declarations block" would be a natural add-on and it doesn't
268+
require additional typing for each declaration.
269+
270+
Note too that this syntax could be extended to allow other types of blocks,
271+
such as comments or different types of statement.
272+
273+
Requires escaping `[` when used as a pattern character in an unquoted pattern.
274+
275+
```
276+
{#
277+
input {$var :function option=value}
278+
}
279+
Hello {$var}
280+
281+
// might be more natural as:
282+
{#input {$var :function option=value}}
283+
Hello {$var}
284+
285+
{#
286+
input {$var :function option=value}
287+
local $foo = {$bar :function option=value}
288+
}
289+
Hello {$var}, you have a {$foo}
290+
291+
{#
292+
match {$foo} {$bar}
293+
[ foo bar] Hello {$foo} you have a {$var}
294+
[ * *] {$foo} hello you have a {$var}
295+
}
296+
297+
{#
298+
input $foo :function option=value
299+
}{
300+
match {$foo :function option=value} {$bar :function option=value}
301+
[a b] {{ {$foo} is {$bar} }}
302+
[x y] {{ {$foo} is {$bar} }}
303+
[* *] {| |}{$foo} is {$bar}{| |}
304+
}
305+
306+
{#input {$var :function option=value}}Hello {$var}
307+
308+
{#input {$var :function option=value} local $foo = {$bar :function option=value}}Hello {$var}, you have a {$foo}
309+
310+
{#match {$foo} {$bar}[foo bar] Hello {$foo} you have a {$var}[* *] {$foo} hello you have a {$var}}
311+
312+
{#input {$foo :function option=value}match {$foo :function option=value} {$bar :function option=value}[a b] {{ {$foo} is {$bar} }}[x y] {{ {$foo} is {$bar} }}[* *] {| |}{$foo} is {$bar}{| |}}
313+
```
314+
315+
## 5a. Declaration block but sigils for selectors
316+
317+
Start in text mode.
318+
Enclose declarations in a block.
319+
Use a sigil for `match` selector.
320+
321+
Requires escaping `[` when used as a pattern character,
322+
and the sequence `#match` when used at the start of a pattern.
323+
324+
```
325+
{# input $var :function option=value}
326+
Hello {$var}
327+
328+
{# input $var :function option=value
329+
local $foo = {$bar :function option=value}
330+
}
331+
Hello {$var}, you have a {$foo}
332+
333+
#match {$foo :function option=value} {$bar :function option=value}
334+
[a b] {$foo} is {$bar}
335+
[x y] {$foo} is {$bar}
336+
[* *] {$foo} is {$bar}
337+
338+
{#input $foo :function option=value
339+
local $baz = {|some annotation|}}
340+
#match {$foo} {$bar :function}
341+
[a b] {$foo} is {$bar}
342+
[x y] {$foo} is {$bar}
343+
[* *] {$foo} is {$bar}
344+
```
345+
346+
## 6. Use "statements"
347+
348+
Many languages delimit statements using a terminator, such as `;`.
349+
In some languages, the terminator is the newline and lines can be extended using an escape like `\`.
350+
Here we use `;` as a terminator.
351+
Note that the closing `;` on `match` might be optional.
352+
353+
Defining a statement syntax might allow us to introduce different types of selectors in future versions,
354+
such as looping constructs.
355+
356+
Requires escaping the word `when` and the character `;` in a pattern,
357+
and the character `#` when used at the start of a pattern.
358+
359+
```
360+
#input {$var :function option=value};
361+
Hello {$var}
362+
363+
#input {$var :function option=value};
364+
#local $foo = {$bar :function option=value};
365+
Hello {$var}, you have a {$foo}
366+
367+
#match {$foo} {$bar}
368+
when [ foo bar] Hello {$foo} you have a {$var}
369+
when [ * *] {$foo} hello you have a {$var}
370+
;
371+
372+
#match {$foo :function option=value} {$bar :function option=value}
373+
when [a b] { {$foo} is {$bar} }
374+
when [x y] { {$foo} is {$bar} }
375+
when [* *] {| |}{$foo} is {$bar}{| |}
376+
;
377+
378+
#input {$var :function option=value};#local $foo = {$bar :function option=value};Hello {$var}, you have a {$foo}
379+
380+
#match {$foo}{$bar}when [foo bar] Hello {$foo} you have a {$var}when [* *] {$foo} hello you have a {$var};
381+
382+
#match {$foo :function option=value}{$bar :function option=value}when [a b] { {$foo} is {$bar} }when[x y] { {$foo} is {$bar} }when[* *] {| |}{$foo} is {$bar}{| |};
383+
384+
```

0 commit comments

Comments
 (0)