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 | // 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 | |
| 5 | import std/html.{type Html} |
| 6 | import std/template.{pug} |
| 7 | |
| 8 | pub 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 | |
| 17 | pub 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. |
| 26 | pub fn tab_indent :: -> Html |
| 27 | { |
| 28 | pug`\tdiv` //~ ERROR E0601 pug: line 1 is indented with a tab; use spaces |
| 29 | } |
| 30 | |
| 31 | pub 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 | |
| 40 | pub fn bad_start :: -> Html |
| 41 | { |
| 42 | pug`=oops` |
| 43 | //~^ ERROR E0601 `=` cannot start an element; a line of text starts with `|` |
| 44 | } |
| 45 | |
| 46 | pub fn missing_class_name :: -> Html |
| 47 | { |
| 48 | pug`div.` //~ ERROR E0601 pug: line 1: expected a class name |
| 49 | } |
| 50 | |
| 51 | pub fn missing_id :: -> Html |
| 52 | { |
| 53 | pug`div#(x)` //~ ERROR E0601 pug: line 1: expected an id |
| 54 | } |
| 55 | |
| 56 | pub fn bad_attr :: -> Html |
| 57 | { |
| 58 | pug`p(class="x" oops` //~ ERROR E0601 pug: line 1: an attribute name or `)` |
| 59 | } |
| 60 | |
| 61 | pub fn bad_attr_start :: -> Html |
| 62 | { |
| 63 | pug`p("x")` //~ ERROR E0601 pug: line 1: an attribute name or `)` |
| 64 | } |
| 65 | |
| 66 | pub 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 | |
| 72 | pub 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`). |
| 79 | pub 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 | |
| 85 | pub 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`. |
| 92 | pub fn bool_attrs :: on: Bool off: Bool -> Html |
| 93 | { |
| 94 | pug`input(required={on} autofocus={off})` |
| 95 | } |
| 96 | |
| 97 | pub 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). |
| 104 | fn card :: title: String children: List<Html> -> Html |
| 105 | { |
| 106 | <section><h2>{title}</h2>{children}</section> |
| 107 | } |
| 108 | |
| 109 | pub fn uses_card :: title: String -> Html |
| 110 | { |
| 111 | pug` |
| 112 | Card(title={title}) |
| 113 | p body |
| 114 | ` |
| 115 | } |
| 116 | |
| 117 | pub fn component_flag :: title: String -> Html |
| 118 | { |
| 119 | pug` |
| 120 | Card(title) //~ ERROR E0604 needs a value |
| 121 | p x |
| 122 | ` |
| 123 | } |
| 124 | |
| 125 | // An element written right after a hole is text (issue #54): the rest |
| 126 | // of the line renders literally, so W0601 warns at the element's head. |
| 127 | pub fn element_after_leading_hole :: icon: Html word: String -> Html |
| 128 | { |
| 129 | pug` |
| 130 | button(type="submit" class="act") |
| 131 | {icon}span.label {word} |
| 132 | //~^ WARN W0601 renders as text, not an element |
| 133 | ` |
| 134 | } |
| 135 | |
| 136 | pub fn element_after_hole_mid_line :: a: String b: String -> Html |
| 137 | { |
| 138 | pug` |
| 139 | p |
| 140 | {a} and {b}span.x |
| 141 | //~^ WARN W0601 span.x |
| 142 | ` |
| 143 | } |
| 144 | |
| 145 | pub fn element_after_hole_in_content :: x: String -> Html |
| 146 | { |
| 147 | pug` |
| 148 | p {x}span.y |
| 149 | //~^ WARN W0601 span.y |
| 150 | ` |
| 151 | } |
| 152 | |
| 153 | pub fn selectors_after_hole :: x: String y: String -> Html |
| 154 | { |
| 155 | pug` |
| 156 | div |
| 157 | {x}div#main.wide(role="main") |
| 158 | //~^ WARN W0601 div#main.wide(role="main") |
| 159 | {y}li#first |
| 160 | //~^ WARN W0601 li#first |
| 161 | ` |
| 162 | } |
| 163 | |
| 164 | pub fn attrs_after_hole :: x: String -> Html |
| 165 | { |
| 166 | pug` |
| 167 | p {x}a(href="/") |
| 168 | //~^ WARN W0601 a(href="/") |
| 169 | ` |
| 170 | } |
| 171 | |
| 172 | // Bare words, punctuation and tagless `.x`/`#x` after a hole are text, |
| 173 | // as is anything on a `| ` line; a hole alone on its line embeds, and |
| 174 | // the next line is an element. |
| 175 | pub fn text_after_holes :: n: Int price: Int a: String -> Html |
| 176 | { |
| 177 | pug` |
| 178 | p |
| 179 | {n} participants |
| 180 | {n}px wide |
| 181 | {price}.00 each |
| 182 | {n}#1 in line |
| 183 | {a}. |
| 184 | ` |
| 185 | } |
| 186 | |
| 187 | pub fn tagless_selectors_after_holes :: |
| 188 | x: String |
| 189 | host: String |
| 190 | file: String |
| 191 | url: String |
| 192 | -> Html |
| 193 | { |
| 194 | pug` |
| 195 | p |
| 196 | {x}.note |
| 197 | {x}#main |
| 198 | see {host}.com, {file}.pdf and {url}#section |
| 199 | ` |
| 200 | } |
| 201 | |
| 202 | pub fn explicit_text_line :: x: String -> Html |
| 203 | { |
| 204 | pug` |
| 205 | p |
| 206 | | {x}span.label |
| 207 | ` |
| 208 | } |
| 209 | |
| 210 | pub fn hole_alone_on_its_line :: icon: Html word: String -> Html |
| 211 | { |
| 212 | pug` |
| 213 | button(type="submit") |
| 214 | {icon} |
| 215 | span.label {word} |
| 216 | ` |
| 217 | } |