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.

123 lignes · 2753 octetsBrut · Historique
1// Compiled pug templates (ADR 0057): what used to be `pug`'s runtime
2// panics are compile-time diagnostics (E0601), pointing at the line of
3// the template at fault.
4
5import std/html.{type Html}
6import std/template.{pug}
7
8pub fn indented_more :: -> Html
9{
10 pug`
11 div
12 p
13 oops //~ ERROR E0601 pug: line 4 is indented more than the line before
14 `
15}
16
17pub fn indented_less :: -> Html
18{
19 pug`
20 div
21 p //~ ERROR E0601 pug: line 3 is indented less than the first line
22 `
23}
24
25// The `\t` escape decodes to a tab character.
26pub fn tab_indent :: -> Html
27{
28 pug`\tdiv` //~ ERROR E0601 pug: line 1 is indented with a tab; use spaces
29}
30
31pub fn text_with_children :: -> Html
32{
33 pug`
34 | text
35 div
36 //~^ ERROR E0601 pug: line 3 follows a text line; only elements have children
37 `
38}
39
40pub fn bad_start :: -> Html
41{
42 pug`=oops`
43 //~^ ERROR E0601 `=` cannot start an element; a line of text starts with `|`
44}
45
46pub fn missing_class_name :: -> Html
47{
48 pug`div.` //~ ERROR E0601 pug: line 1: expected a class name
49}
50
51pub fn missing_id :: -> Html
52{
53 pug`div#(x)` //~ ERROR E0601 pug: line 1: expected an id
54}
55
56pub fn bad_attr :: -> Html
57{
58 pug`p(class="x" oops` //~ ERROR E0601 pug: line 1: an attribute name or `)`
59}
60
61pub fn bad_attr_start :: -> Html
62{
63 pug`p("x")` //~ ERROR E0601 pug: line 1: an attribute name or `)`
64}
65
66pub fn unquoted_attr :: -> Html
67{
68 pug`p(class=x)`
69 //~^ ERROR E0601 pug: line 1: an attribute value is quoted or a single `{hole}`
70}
71
72pub fn unclosed_attr :: -> Html
73{
74 pug`p(class="x)` //~ ERROR E0601 pug: line 1: an attribute value is not closed
75}
76
77// An element can't be an attribute value: a type error now (it was a
78// panic), as is one in a quoted value (`Element` has no `Show`).
79pub fn element_attr :: el: Html -> Html
80{
81 pug`p(class={el})`
82 //~^ ERROR E0602 attribute `class` must be a String, Int, Bool or Option<String>
83}
84
85pub fn element_in_quoted_attr :: el: Html -> Html
86{
87 pug`p(class="a {el}")` //~ ERROR E0401 does not implement `Show`
88}
89
90// Holes are typed by position: a `Bool` attribute is a flag (present iff
91// true), an `Option<String>` is absent for `None`.
92pub fn bool_attrs :: on: Bool off: Bool -> Html
93{
94 pug`input(required={on} autofocus={off})`
95}
96
97pub fn option_attr :: value: Option<String> -> Html
98{
99 pug`input(value={value})`
100}
101
102// Components: an uppercase tag calls the function with labelled
103// arguments, children included (as in a literal).
104fn card :: title: String children: List<Html> -> Html
105{
106 <section><h2>{title}</h2>{children}</section>
107}
108
109pub fn uses_card :: title: String -> Html
110{
111 pug`
112 Card(title={title})
113 p body
114 `
115}
116
117pub fn component_flag :: title: String -> Html
118{
119 pug`
120 Card(title) //~ ERROR E0604 needs a value
121 p x
122 `
123}