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:
Orkun ÇAKILKAYA 2026-09-24 15:58:47 +03:00
parent 334469ef61
commit 66a2bc2214
64 changed files with 74806 additions and 63975 deletions

View file

@ -0,0 +1,70 @@
# select.ludic - CSS selectors: a compound (`button.primary#buy[type=big]:hover:not(.off)`) joined
# to the one on its left by a space (anywhere inside it) or `>` (straight inside it)
export property UiSel {
tag: string = ""
id: string = ""
classes: []string = null
akeys: []string = null
avals: []string = null # "" with aops 0 is [attr]; aops 1 is [attr=value]
aops: []int = null
pseudos: []string = null
pargs: []string = null
nots: []UiSel = null
prev: UiSel = null
comb: int = 0 # 0: prev is an ancestor, 1: prev is the parent
}
function sel_new() -> UiSel {
let s = new UiSel
s.classes = new []string
s.akeys = new []string
s.avals = new []string
s.aops = new []int
s.pseudos = new []string
s.pargs = new []string
s.nots = new []UiSel
return s
}
function sel_parse(src: string, err: []string) -> UiSel {
let r = new UiRd
r.s = src
var cur: UiSel = null
var comb = 0
while r.err == "" {
rd_ws(r)
if r.i >= len(r.s) { break }
if rd_op(r, ">") {
comb = 1
continue
}
let c = sel_compound(r)
c.prev = cur
c.comb = comb
cur = c
comb = 0
}
if r.err != "" { push(err, r.err) }
if cur == null { push(err, `"{src}" selects nothing`) }
return cur
}
function sel_is_name(c: int) -> bool { return rd_is_word(c) or c == 45 }
function sel_name(r: UiRd) -> string {
let at = r.i
while r.i < len(r.s) and sel_is_name(r.s[r.i]) { r.i += 1 }
if r.i == at { rd_fail(r, "a name") }
return r.s[at..r.i]
}
function sel_compound(r: UiRd) -> UiSel {
let s = sel_new()
if rd_c(r, 0) == 42 { r.i += 1 } else if sel_is_name(rd_c(r, 0)) { s.tag = sel_name(r) }
while r.err == "" and r.i < len(r.s) {
let c = rd_c(r, 0)
if c == 35 {
r.i += 1
s.id = sel_name(r)
} else if c == 46 {
r.i += 1
push(s.classes, sel_name(r))
} else if c == 91 { sel_attr(r, s) } else if c == 58 { sel_pseudo(r, s) } else if c == 42 { r.i += 1 } else { return s }
}
return s
}