tobogganSe connecter

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.

97 lignes · 1923 octetsBrut · Historique
1import std/html.{type Element, type Html}
2import std/list
3import 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.
7fn para :: name: String
8{
9 html`<p>{name}</p>`
10}
11//~ TYPE para: fn(String) -> Element<a>
12
13fn shown :: n: Int -> Html
14{
15 html`<p>{n}</p>`
16}
17
18fn debugged :: n: Int -> Html
19{
20 html`<pre>{n:?}</pre>`
21}
22
23fn embed :: body: Html -> Html
24{
25 html`<div>{body}</div>`
26}
27
28fn embed_list :: items: List<Html> -> Html
29{
30 html`<ul>{items}</ul>`
31}
32
33fn xml_doc :: name: String
34{
35 xml`<item>{name}</item>`
36}
37//~ TYPE xml_doc: fn(String) -> Xml
38
39fn pug_card :: title: String
40{
41 pug`.card h2 {title}`
42}
43//~ TYPE pug_card: fn(String) -> Element<a>
44
45pub fn no_show :: f: fn(Int) -> Int -> Html
46{
47 html`<p>{f}</p>` //~ ERROR E0401 does not implement `Show`
48}
49
50pub fn unknown_tag :: -> Html
51{
52 puug`.card` //~ ERROR E0101 no value named `puug`
53}
54
55pub 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.
63pub fn pug_as_value :: -> ()
64{
65 let t = pug //~ ERROR E0605 syntax, not values
66}
67
68pub fn html_as_value :: templates: List<Template<Never>> -> List<Html>
69{
70 list.map templates html //~ ERROR E0605 syntax, not values
71}
72
73pub 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.
79pub fn shadowed :: -> Int
80{
81 let pug = 42
82 pug
83}
84
85// A custom templater is any function from a `Template`.
86pub 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
94pub fn custom :: -> String
95{
96 shout`a {"bee"} c`
97}