louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | import std/html.{type Element, type Html} |
| 2 | import std/list |
| 3 | import std/template.{type Hole, type Template, Template, Text, html, pug, xml} |
| 4 | |
| 5 | // std's `html` compiles the template to the tree (ADR 0057): an |
| 6 | // `Element`, its holes typed by position. |
| 7 | fn para :: name: String |
| 8 | { |
| 9 | html`<p>{name}</p>` |
| 10 | } |
| 11 | //~ TYPE para: fn(String) -> Element<a> |
| 12 | |
| 13 | fn shown :: n: Int -> Html |
| 14 | { |
| 15 | html`<p>{n}</p>` |
| 16 | } |
| 17 | |
| 18 | fn debugged :: n: Int -> Html |
| 19 | { |
| 20 | html`<pre>{n:?}</pre>` |
| 21 | } |
| 22 | |
| 23 | fn embed :: body: Html -> Html |
| 24 | { |
| 25 | html`<div>{body}</div>` |
| 26 | } |
| 27 | |
| 28 | fn embed_list :: items: List<Html> -> Html |
| 29 | { |
| 30 | html`<ul>{items}</ul>` |
| 31 | } |
| 32 | |
| 33 | fn xml_doc :: name: String |
| 34 | { |
| 35 | xml`<item>{name}</item>` |
| 36 | } |
| 37 | //~ TYPE xml_doc: fn(String) -> Xml |
| 38 | |
| 39 | fn pug_card :: title: String |
| 40 | { |
| 41 | pug`.card h2 {title}` |
| 42 | } |
| 43 | //~ TYPE pug_card: fn(String) -> Element<a> |
| 44 | |
| 45 | pub fn no_show :: f: fn(Int) -> Int -> Html |
| 46 | { |
| 47 | html`<p>{f}</p>` //~ ERROR E0401 does not implement `Show` |
| 48 | } |
| 49 | |
| 50 | pub fn unknown_tag :: -> Html |
| 51 | { |
| 52 | puug`.card` //~ ERROR E0101 no value named `puug` |
| 53 | } |
| 54 | |
| 55 | pub fn tag_not_a_function :: -> () |
| 56 | { |
| 57 | let x = 42 |
| 58 | x`nope` //~ ERROR E0207 this is not a function |
| 59 | } |
| 60 | |
| 61 | // std's templaters are syntax, not values (ADR 0057): outside a |
| 62 | // template's tag position they do not exist as values. |
| 63 | pub fn pug_as_value :: -> () |
| 64 | { |
| 65 | let t = pug //~ ERROR E0605 syntax, not values |
| 66 | } |
| 67 | |
| 68 | pub fn html_as_value :: templates: List<Template<Never>> -> List<Html> |
| 69 | { |
| 70 | list.map templates html //~ ERROR E0605 syntax, not values |
| 71 | } |
| 72 | |
| 73 | pub fn xml_qualified_as_value :: -> () |
| 74 | { |
| 75 | let x = template.xml //~ ERROR E0605 syntax, not values |
| 76 | } |
| 77 | |
| 78 | // A local shadowing a templater is an ordinary value. |
| 79 | pub fn shadowed :: -> Int |
| 80 | { |
| 81 | let pug = 42 |
| 82 | pug |
| 83 | } |
| 84 | |
| 85 | // A custom templater is any function from a `Template`. |
| 86 | pub fn shout :: |
| 87 | template: Template<msg> //~ WARN W0101 shadows the imported module |
| 88 | -> String |
| 89 | { |
| 90 | let Template(_, holes) = template |
| 91 | match holes { [Text(s), ..] -> s, _ -> "!" } |
| 92 | } |
| 93 | |
| 94 | pub fn custom :: -> String |
| 95 | { |
| 96 | shout`a {"bee"} c` |
| 97 | } |