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
42
packages/ludic.ui/link.ludic
Normal file
42
packages/ludic.ui/link.ludic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# link.ludic - each tag in a file that is not an element names a component: the file's own, an
|
||||
# unnamed import's exported one, or `as:Name` from the import called `as`
|
||||
const LK_OWN: string = " row button spacer scroll img hr if else each slot state style component screen import "
|
||||
function lib_link(f: UiFile, t: UiTpl) -> void {
|
||||
t.sheet = f.sheet
|
||||
if not lk_element(t.tag) {
|
||||
t.comp = lk_find(f, t.tag, false)
|
||||
if t.comp == null and lk_find(f, t.tag, true) != null { ui_err(`{f.path}: <{t.tag}>: that component is not exported - export="true" on it lets other files use it`) } else if t.comp == null { ui_err(`{f.path}: <{t.tag}>: there is no such element, and no component of that name here or exported by an import`) }
|
||||
}
|
||||
for i in 0 .. len(t.kids) { lib_link(f, t.kids[i]) }
|
||||
}
|
||||
function lk_element(tag: string) -> bool { return lk_in(LK_OWN, tag) or lk_in(EL_BOXES, tag) or lk_in(EL_TEXTS, tag) }
|
||||
# a word in a list of words written " a b c "
|
||||
function lk_in(words: string, w: string) -> bool {
|
||||
let pat = ` {w} `
|
||||
let n = len(pat)
|
||||
for i in 0 .. len(words) - n + 1 {
|
||||
if words[i..i + n] == pat { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
# `any` finds an unexported one too, to say why it cannot be used
|
||||
function lk_find(f: UiFile, tag: string, any: bool) -> UiTpl {
|
||||
var colon = -1
|
||||
for i in 0 .. len(tag) {
|
||||
if tag[i] == 58 { colon = i }
|
||||
}
|
||||
if colon < 0 {
|
||||
let own = lib_find(f.names, tag)
|
||||
if own >= 0 { return f.comps[own] }
|
||||
}
|
||||
for i in 0 .. len(f.imp) {
|
||||
var want = tag
|
||||
if colon >= 0 {
|
||||
if f.imp_as[i] != tag[0..colon] { continue }
|
||||
want = tag[colon + 1..len(tag)]
|
||||
} else if f.imp_as[i] != "" { continue }
|
||||
let at = lib_find(f.imp[i].names, want)
|
||||
if at >= 0 and (any or f.imp[i].exported[at]) { return f.imp[i].comps[at] }
|
||||
}
|
||||
return null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue