feat(lang): L11 views and templates - the UI is markup, not code
A `view Name { field = x; function q(..); on e(..) }` declaration is the one bridge between a
program and its UI: it writes view_<name>() -> UiView, whose model is a Value of every field and
whose call runs a query or an event by name.
ludic.ui is a template runtime:
- HTML-shaped XML screens and components, loaded at run time;
- {expression} bindings, if/else/each, props, slots, per-instance state;
- on-press / onclick actions (event, set, emit);
- component libraries (export="true", <import src as>).
Styling:
- stylesheets in <style> or importable .lss files (@import);
- CSS selectors (#id, .class, [attr=v], descendant and > combinators, :hover, :disabled,
:first-child, :last-child, :nth-child, :not) weighed by specificity;
- the box model and flex under CSS's property names.
Also:
- default parameters, and positional-then-named calls;
- Value gains a float kind;
- a function shadowing a runtime one is refused;
- an index is evaluated before the slice is read;
- runtime errors name the right file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
334469ef61
commit
66a2bc2214
64 changed files with 74806 additions and 63975 deletions
71
packages/ludic.ui/style_rule.ludic
Normal file
71
packages/ludic.ui/style_rule.ludic
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# style_rule.ludic - a rule read, the cascade a file sees, and a node's rules applied to it
|
||||
function lss_rule(f: UiFile, sels: string, body: string, err: []string) -> void {
|
||||
let decls = lss_decls(body, err)
|
||||
let each = lss_split(sels, 44)
|
||||
for i in 0 .. len(each) {
|
||||
let sel = tpl_words(each[i])
|
||||
if len(sel) == 0 { continue }
|
||||
let r = new UiRule
|
||||
r.keys = decls.keys
|
||||
r.vals = decls.vals
|
||||
r.sel = sel_parse(sel, err)
|
||||
if r.sel != null {
|
||||
r.spec = sel_spec(r.sel)
|
||||
push(f.own, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
# `key: value; key: value`, a rule's body or a style="..." attribute
|
||||
function lss_decls(body: string, err: []string) -> UiRule {
|
||||
let r = new UiRule
|
||||
r.keys = new []string
|
||||
r.vals = new []UiExpr
|
||||
let decls = lss_split(body, 59)
|
||||
for i in 0 .. len(decls) {
|
||||
let d = decls[i]
|
||||
var colon = -1
|
||||
for k in 0 .. len(d) {
|
||||
if colon < 0 and d[k] == 58 { colon = k }
|
||||
}
|
||||
if colon < 0 {
|
||||
if len(tpl_words(d)) > 0 { push(err, `"{tpl_words(d)}" is not a property: value`) }
|
||||
continue
|
||||
}
|
||||
push(r.keys, tpl_words(d[0..colon]))
|
||||
push(r.vals, tpl_value(tpl_words(d[colon + 1..len(d)]), err))
|
||||
}
|
||||
return r
|
||||
}
|
||||
function lss_split(s: string, c: int) -> []string {
|
||||
let out = new []string
|
||||
var at = 0
|
||||
for i in 0 .. len(s) {
|
||||
if s[i] == c {
|
||||
push(out, s[at..i])
|
||||
at = i + 1
|
||||
}
|
||||
}
|
||||
push(out, s[at..len(s)])
|
||||
return out
|
||||
}
|
||||
# the imports' rules, then the file's own, ordered by specificity and otherwise as written
|
||||
function sheet_of(f: UiFile) -> UiSheet {
|
||||
let sh = new UiSheet
|
||||
sh.rules = new []UiRule
|
||||
for i in 0 .. len(f.imp) {
|
||||
if f.imp[i].sheet != null {
|
||||
for k in 0 .. len(f.imp[i].sheet.rules) { sheet_add(sh, f.imp[i].sheet.rules[k]) }
|
||||
}
|
||||
}
|
||||
for k in 0 .. len(f.own) { sheet_add(sh, f.own[k]) }
|
||||
return sh
|
||||
}
|
||||
function sheet_add(sh: UiSheet, r: UiRule) -> void {
|
||||
push(sh.rules, r)
|
||||
var i = len(sh.rules) - 1
|
||||
while i > 0 and sh.rules[i - 1].spec > r.spec {
|
||||
sh.rules[i] = sh.rules[i - 1]
|
||||
i -= 1
|
||||
}
|
||||
sh.rules[i] = r
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue