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
84
packages/ludic.ui/style.ludic
Normal file
84
packages/ludic.ui/style.ludic
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# style.ludic - stylesheets: `.chip { bg: bg2; pad: 6 } button { h: 40 }` in a <style>, or an .lss
|
||||
# file brought in by <import src="look.lss"/> (which may `@import "base.lss";` in turn). A selector is
|
||||
# a tag, a .class, both, or *; a property is any attribute, {holes} and all. The more specific rule
|
||||
# wins, then the later; an attribute beats them all.
|
||||
export property UiRule {
|
||||
sel: UiSel = null
|
||||
spec: int = 0
|
||||
keys: []string = null
|
||||
vals: []UiExpr = null
|
||||
}
|
||||
export property UiSheet {
|
||||
rules: []UiRule = null
|
||||
}
|
||||
function sheet_read(f: UiFile, t: UiTpl) -> void {
|
||||
var src = t.raw
|
||||
let from = bd_name(t, "src", "")
|
||||
if from != "" { src = lib_text(lib_beside(f.path, from)) }
|
||||
lss_text(f, src)
|
||||
}
|
||||
function lss_is(path: string) -> bool { return len(path) > 4 and path[len(path) - 4..len(path)] == ".lss" }
|
||||
# a stylesheet file: a file with rules and imports and nothing else
|
||||
function lss_file(src: string, path: string) -> UiFile {
|
||||
let f = lib_new(path)
|
||||
lss_text(f, src)
|
||||
f.sheet = sheet_of(f)
|
||||
return f
|
||||
}
|
||||
function lss_text(f: UiFile, src: string) -> void {
|
||||
let err = new []string
|
||||
let r = new UiRd
|
||||
r.s = lss_strip(src)
|
||||
while r.err == "" {
|
||||
rd_ws(r)
|
||||
if r.i >= len(r.s) { break }
|
||||
if rd_op(r, "@import") {
|
||||
lss_import(f, lss_upto(r, 59))
|
||||
continue
|
||||
}
|
||||
let sels = lss_upto(r, 123)
|
||||
let body = lss_upto(r, 125)
|
||||
lss_rule(f, sels, body, err)
|
||||
}
|
||||
for i in 0 .. len(err) { ui_err(`{f.path}: <style> {err[i]}`) }
|
||||
}
|
||||
# @import "base.lss"; - its rules come before this file's own
|
||||
function lss_import(f: UiFile, what: string) -> void {
|
||||
var p = tpl_words(what)
|
||||
if len(p) > 5 and p[0..4] == "url(" { p = p[4..len(p) - 1] }
|
||||
if len(p) >= 2 and (p[0] == 34 or p[0] == 39) { p = p[1..len(p) - 1] }
|
||||
let other = lib_file(lib_beside(f.path, p))
|
||||
if other != null {
|
||||
push(f.imp, other)
|
||||
push(f.imp_as, "")
|
||||
}
|
||||
}
|
||||
# the text up to the character `c`, which is taken too; a {hole} inside a body is skipped whole
|
||||
function lss_upto(r: UiRd, c: int) -> string {
|
||||
let at = r.i
|
||||
var depth = 0
|
||||
while r.i < len(r.s) and (r.s[r.i] != c or depth > 0) {
|
||||
if c == 125 and r.s[r.i] == 123 { depth += 1 }
|
||||
if c == 125 and r.s[r.i] == 125 { depth -= 1 }
|
||||
r.i += 1
|
||||
}
|
||||
let out: string = r.s[at..r.i]
|
||||
if r.i < len(r.s) { r.i += 1 } else { rd_fail(r, "a closing brace") }
|
||||
return out
|
||||
}
|
||||
function lss_strip(src: string) -> string {
|
||||
var out = ""
|
||||
var at = 0
|
||||
var i = 0
|
||||
while i + 1 < len(src) {
|
||||
if src[i] == 47 and src[i + 1] == 42 {
|
||||
out = out + src[at..i]
|
||||
var j = i + 2
|
||||
while j + 1 < len(src) and not (src[j] == 42 and src[j + 1] == 47) { j += 1 }
|
||||
i = j + 2
|
||||
at = i
|
||||
} else { i += 1 }
|
||||
}
|
||||
if at < len(src) { out = out + src[at..len(src)] }
|
||||
return out
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue