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
62
packages/ludic.ui/act.ludic
Normal file
62
packages/ludic.ui/act.ludic
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# act.ludic - what a press does: `buy(i)` asks the view, `set pick = i` changes a state, and
|
||||
# `emit picked` runs what the component's user said with on-picked. Several are `;` apart.
|
||||
const A_CALL: int = 0
|
||||
const A_SET: int = 1
|
||||
const A_EMIT: int = 2
|
||||
export property UiAct {
|
||||
kinds: []int = null
|
||||
names: []string = null
|
||||
exprs: []UiExpr = null
|
||||
}
|
||||
function act_parse(src: string, err: []string) -> UiAct {
|
||||
let a = new UiAct
|
||||
a.kinds = new []int
|
||||
a.names = new []string
|
||||
a.exprs = new []UiExpr
|
||||
let r = new UiRd
|
||||
r.s = src
|
||||
while r.err == "" {
|
||||
rd_ws(r)
|
||||
if r.i >= len(r.s) { break }
|
||||
if rd_word(r, "set") {
|
||||
push(a.kinds, A_SET)
|
||||
push(a.names, rd_name(r))
|
||||
if not rd_op(r, "=") { rd_fail(r, "'='") }
|
||||
push(a.exprs, px_cond(r))
|
||||
} else if rd_word(r, "emit") {
|
||||
push(a.kinds, A_EMIT)
|
||||
push(a.names, rd_name(r))
|
||||
push(a.exprs, null)
|
||||
} else {
|
||||
push(a.kinds, A_CALL)
|
||||
push(a.names, "")
|
||||
push(a.exprs, px_cond(r))
|
||||
}
|
||||
if not rd_op(r, ";") { break }
|
||||
}
|
||||
rd_ws(r)
|
||||
if r.err == "" and r.i < len(r.s) { rd_fail(r, "';' or the end") }
|
||||
if r.err != "" { push(err, r.err) }
|
||||
return a
|
||||
}
|
||||
function act_run(a: UiAct, e: UiEnv) -> void {
|
||||
for i in 0 .. len(a.kinds) {
|
||||
if a.kinds[i] == A_SET { env_set(e, a.names[i], ui_eval(a.exprs[i], e)) }
|
||||
if a.kinds[i] == A_CALL { ui_eval(a.exprs[i], e) }
|
||||
if a.kinds[i] == A_EMIT { act_emit(a.names[i], e) }
|
||||
}
|
||||
}
|
||||
function act_emit(name: string, e: UiEnv) -> void {
|
||||
var at = e
|
||||
while at != null {
|
||||
if at.on_names != null {
|
||||
for i in 0 .. len(at.on_names) {
|
||||
if at.on_names[i] == name {
|
||||
act_run(at.on_acts[i], at.on_envs[i])
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
at = at.parent
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue