ludic/packages/ludic.ui/expr_parse.ludic
Orkuncakilkaya 66a2bc2214 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>
2026-09-24 15:58:47 +03:00

96 lines
2.3 KiB
Text

# expr_parse.ludic - a condition, or/and/not, a comparison, sums and products, then a name
# with its members, indexes and calls
function px_cond(r: UiRd) -> UiExpr {
let a = px_or(r)
if not rd_op(r, "?") { return a }
let e = ex_new(X_COND)
e.a = a
e.b = px_cond(r)
if not rd_op(r, ":") { rd_fail(r, "':'") }
e.c = px_cond(r)
return e
}
function px_or(r: UiRd) -> UiExpr {
var a = px_and(r)
while rd_word(r, "or") or rd_op(r, "||") {
let e = ex_new(X_OR)
e.a = a
e.b = px_and(r)
a = e
}
return a
}
function px_and(r: UiRd) -> UiExpr {
var a = px_not(r)
while rd_word(r, "and") or rd_op(r, "&&") {
let e = ex_new(X_AND)
e.a = a
e.b = px_not(r)
a = e
}
return a
}
function px_not(r: UiRd) -> UiExpr {
rd_ws(r)
if rd_word(r, "not") or (rd_c(r, 0) == 33 and rd_c(r, 1) != 61 and rd_op(r, "!")) {
let e = ex_new(X_NOT)
e.a = px_not(r)
return e
}
return px_cmp(r)
}
function px_bin(op: string, a: UiExpr, b: UiExpr) -> UiExpr {
let e = ex_new(X_BIN)
e.s = op
e.a = a
e.b = b
return e
}
function px_cmp(r: UiRd) -> UiExpr {
let a = px_sum(r)
let ops = ["==", "!=", "<=", ">=", "<", ">"]
for k in 0 .. len(ops) {
if rd_op(r, ops[k]) { return px_bin(ops[k], a, px_sum(r)) }
}
return a
}
function px_sum(r: UiRd) -> UiExpr {
var a = px_prod(r)
while true {
if rd_op(r, "+") { a = px_bin("+", a, px_prod(r)) } else if rd_op(r, "-") { a = px_bin("-", a, px_prod(r)) } else { return a }
}
return a
}
function px_prod(r: UiRd) -> UiExpr {
var a = px_unary(r)
while true {
if rd_op(r, "*") { a = px_bin("*", a, px_unary(r)) } else if rd_op(r, "/") { a = px_bin("/", a, px_unary(r)) } else if rd_op(r, "%") { a = px_bin("%", a, px_unary(r)) } else { return a }
}
return a
}
function px_unary(r: UiRd) -> UiExpr {
if rd_op(r, "-") {
let e = ex_new(X_NEG)
e.a = px_unary(r)
return e
}
return px_post(r)
}
function px_post(r: UiRd) -> UiExpr {
var a = px_primary(r)
while r.err == "" {
if rd_op(r, ".") {
let e = ex_new(X_MEMBER)
e.a = a
e.s = rd_name(r)
a = e
} else if rd_op(r, "[") {
let e = ex_new(X_INDEX)
e.a = a
e.b = px_cond(r)
if not rd_op(r, "]") { rd_fail(r, "']'") }
a = e
} else { return a }
}
return a
}