Skip to content

Commit 9a294d1

Browse files
authored
Add 3 more beauty contestants (#494)
* Beauty contest: add the hybrid variant * Beauty contest: add the templating language variant * Beauty contest: add the double sigils for code mode variant * 3b. Switch from |[] to #[] for keys * Extend the comparison table * Rename 0a to 2a
1 parent 5147589 commit 9a294d1

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

exploration/beauty-contest.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ Please dispute factual errors in this. The table uses multiple `-` when an optio
1212
| 0 | Current syntax, starts in code mode | - | + | -- | + | - | + |
1313
| 1 | Invert for text mode | - | + | + | - | + | + |
1414
| 1a | Invert for text mode, distinguish statements from placeholders | - | + | + | + | + | - |
15+
| 1b | Invert for text mode, leverage existing templating languages | - | + | + | + | + | - |
1516
| 2 | Text first, but always code mode after code | - | + | - | - | + | + |
17+
| 2a | Text first, current syntax for complex messages | - | + | - | + | - | + |
1618
| 3 | Use sigils for code mode | + | - | + | + | + | -- |
1719
| 3a | Use sigils for code mode, use {/} for keys | + | - | + | + | + | - |
20+
| 3b | Use `#[` for code mode, use `#[]` for keys | + | - | + | + | + | - |
1821
| 4 | Reducing keywords | + | --- | + | + | + | --- |
1922
| 5 | Use blocks for declarations and body | -- | - | + | - | - | - |
2023
| 5a | Use blocks for declarations but sigils for selectors | + | -- | + | - | - | - |
@@ -121,6 +124,40 @@ Hello {$var}, you have a {$foo}
121124
{#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}{| |}
122125
```
123126

127+
## 1b. Templating Language
128+
129+
Same as 1, but directly inspired by existing templating languages.
130+
Leverages the familiarity with established templating solutions,
131+
such as [Jinja](https://jinja.palletsprojects.com/en/3.1.x/), [Twig](https://twig.symfony.com), and [Liquid](https://shopify.github.io/liquid/).
132+
133+
```
134+
Hello world!
135+
136+
Hello {{ $user }}
137+
138+
{% input $var :function option=value %}
139+
Hello {{ $var }}
140+
141+
{% input $var :function option=value %}
142+
{% local $foo = $bar :function option=value %}
143+
Hello {{ $var }}, you have a {{ $foo }}
144+
145+
{% match {$foo} {$bar} %}
146+
{% when foo bar %} Hello {{ $foo }} you have a {{ $var }}
147+
{% when * * %} {{ $foo }} hello you have a {{ $var }}
148+
149+
{% match {$foo :function option=value} {$bar :function option=value} %}
150+
{% when a b %} {| {{$foo}} is {{$bar}} |}
151+
{% when x y %} {| {{$foo}} is {{$bar}} |}
152+
{% when * * %} {{ | | }}{{ $foo }} is {{ $bar }}{{ | | }}
153+
154+
{% input $var :function option=value %}{% local $foo = $bar :function option=value %}Hello {{ $var }}, you have a {{ $foo }}
155+
156+
{% match {$foo} {$bar} %}{% when foo bar %} Hello {{ $foo }} you have a {{ $var }}{% when * * %} {{ $foo }} hello you have a {{ $var }}
157+
158+
{% 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 }}{{ | | }}
159+
```
160+
124161
## 2. Text First, but Always Code After Code-Mode
125162

126163
This is @mihnita's proposal, mentioned in the 2023-10-02 call.
@@ -156,6 +193,44 @@ Hello {$user}
156193
{match {$foo :function option=value}{$bar :function option=value}}{when a b} { {$foo} is {$bar} }{when x y} { {$foo} is {$bar} }
157194
```
158195

196+
## 2a. Text First, Current Syntax for Complex Messages
197+
198+
Starts in text mode,
199+
but switches to the current code-mode syntax
200+
when the message is wrapped in `{{ }}`.
201+
202+
```
203+
Hello world!
204+
205+
Hello {$user}
206+
207+
{{ input {$var :function option=value}
208+
{Hello {$var}}
209+
}}
210+
211+
{{ input {$var :function option=value}
212+
local $foo = {$bar :function option=value}
213+
{Hello {$var}, you have a {$foo}}
214+
}}
215+
216+
{{ match {$foo} {$bar}
217+
when foo bar {Hello {$foo} you have a {$var}}
218+
when * * {{$foo} hello you have a {$var}}
219+
}}
220+
221+
{{ match {$foo :function option=value} {$bar :function option=value}
222+
when a b { {$foo} is {$bar} }
223+
when x y { {$foo} is {$bar} }
224+
when * * { {$foo} is {$bar} }
225+
}}
226+
227+
{{input {$var :function option=value} local $foo = {$bar :function option=value}{Hello {$var}, you have a {$foo}}}}
228+
229+
{{match {$foo} {$bar} when foo bar {Hello {$foo} you have a {$var}} when * * {{$foo} hello you have a {$var}}}}
230+
231+
{{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} }}}
232+
```
233+
159234
## 3. Use sigils for code mode
160235

161236
Try to redues the use of `{`/`}` to just expressions and placeholders instead of the three
@@ -224,6 +299,39 @@ Hello {$var}, you have a {$foo}
224299
#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}{| |}
225300
```
226301

302+
## 3b. Double sigils for code mode
303+
304+
Same as 3, but the `#` sign is only special when followed by `[`,
305+
hopefully making escaping rarely needed.
306+
307+
Requires `#[` to be escaped in unquoted patterns.
308+
309+
This variant also experiments with dropping the `when` key.
310+
311+
```
312+
#[input $var :function option=value]
313+
Hello {$var}
314+
315+
#[input $var :function option=value]
316+
#[local $foo = $bar :function option=value]
317+
Hello {$var}, you have a {$foo}
318+
319+
#[match {$foo} {$bar}]
320+
#[foo bar] Hello {$foo} you have a {$var}
321+
#[ * *] {$foo} hello you have a {$var}
322+
323+
#[match {$foo :function option=value} {$bar :function option=value}]
324+
#[a b] {{ {$foo} is {$bar} }}
325+
#[x y] {||} {$foo} is {$bar} {||}
326+
#[* *] {| |}{$foo} is {$bar}{| |}
327+
328+
#[input $var :function option=value]#[local $foo = $bar :function option=value]Hello {$var}, you have a {$foo}
329+
330+
#[match {$foo} {$bar}]#[foo bar] Hello {$foo} you have a {$var}#[* *] {$foo} hello you have a {$var}
331+
332+
#[match {$foo :function option=value} {$bar :function option=value}]#[a b] {{ {$foo} is {$bar} }} #[x y] {||} {$foo} is {$bar} {||}#[* *] {| |}{$foo} is {$bar}{| |}
333+
```
334+
227335
## 4. Reducing keywords
228336

229337
Avoids keywords in favor of sigil based parsing.

0 commit comments

Comments
 (0)