gitoria
All repositories: gitoria
7.4 KB
// The View's READERS — realm-neutral: the same code reads values on the server and (compiled to JS) in the// browser; the browser's bundle carries this file and nothing server-only (viewserver.hl). It reads a TREE, the// syntax of a View member reflected into plain hybrids by the server (see// server.hl `tree()`), against an INSTANCE whose members supply the values.//// Tree node shapes:// { k = 'el' tag key path = [ keys… ] site attrs = [ { name text } | { name member } ] children = [ … ] }// `site` is `file:line:col` of the literal — the id its class is minted under// `tag` is what the DOM gets (a custom key kebab-cased), `key` the source key// { k = 'text' text }// { k = 'member' name } an ordered entry naming a member of the class — a SITE// { k = 'field' name path } `p.title`: a path off a member or a `for` row variable// { k = 'for' row list body } `for (row of list) { … }`, body rendered per entry// { k = 'if' cond then other } `if (cond) { … } else { … }`// { k = 'on' event } a DOM event the owning literal handles (its inline `on`)// { k = 'component' cls key path bindings ons } `Child { count = count on done(v) { … } }`:// a composed component — its own mount renders here// { k = 'other' tag } a construct this round does not render yet (if / for / on)//// `ctx` rides through every call: `ctx.slot` is the HTML a shell's `slot` member// stands for (null when rendering a page alone), `ctx.kids` the child mounts of// the instance being rendered, keyed by the component node's path joined with// '/'. A component node renders ITS mount: its own instance, its own kids.// the language has no escapes: a newline and a tab are written as themselvesstatic newline = ""static tab = " "// a component node's key in a mount's `kids`: its path, '/'-joined (a list has no// join in the language; the walk is written out)kidKey(&path) {let out = ''for (p of path) { out = out + '/' + p }return out}// THE KEY OF ONE ROW — "lists are keyed by the record's id" (CONCEPT §2), and by// the row's index where the row is not a record or carries no id (a list of strings// is one: demo-blog's paragraphs). ONE rule, called by everything that has to tell// one row from the next: the server's HTML walk below, the mount key of a row's// children (WebFramework `mountKids`), and the browser's keyed region (client.hl).// Two rows with the SAME id are two rows to the language and one key to this rule;// the browser's region gives the second one a key of its own, the server does not.rowKey(&entry, i) {if (entry != null) {let t = hlTypeName(&entry)if ((t == 'Hybrid' || t == 'Instance') && entry.id != null) { return '' + entry.id }}return '' + i}// THE KEYS OF A LIST, in order: rowKey of each row, and where one id stands twice the second and later// rows get ':' + their index (#119). The browser's region (client listKeys) keys a list the same way, so a// child of the second row of one id is its own mount on the server too, not the first row's.listKeys(&entries) {let out = []let seen = {}let ri = 0for (entry of entries) {let k = rowKey(&entry, ri)if (seen[k] != null) { k = k + ':' + ri }seen[k] = trueout.push(k)ri = ri + 1}return out}// A LITERAL'S VALUE, TYPED — COMPONENTS.md §12, "typed, not stringified". `hlSyntax`// hands a literal back as its source text and its KIND, and a reference binding carries// the value rather than the text: `Level2 { n = 1 }` gives the child a Number, so `n * 97`// is arithmetic and not "operator '*' does not apply to String and Number" (measured// 2026-09-14, demo-nested wall 3). An attribute and a text child keep the text, because// HTML is text; only what crosses into a member of another class is typed.literalValue(kind, text) {if (kind == 'number') { return toNumber(text) }if (kind == 'boolean') { return text == 'true' }if (kind == 'null_literal') { return null }return text}// THE VALUE A REFERENCE BINDING CARRIES when it is a literal or a folded static — the// one place the two are read, so the server's mount and the browser's do it alike. A// static is folded to its VALUE and carried as one ('folded'), never printed and parsed// back; a literal carries its source text and its kind, which is all the syntax has.refValue(b) {if (b.kind == 'folded') { return b.value }if (b.kind != null) { return literalValue(b.kind, b.text) }return b.text}// THE VALUE a read names: a `for` row variable in scope wins over a member of the// same name (nesting is scope); a field path walks into it.value(&node, &page, &rows) {if (node.k == 'text') { return refValue(node) }if (node.k == 'expr') { return evalExpr(&node.x, &page, &rows) }// READ IN PLACE: `v = rows[node.name]` copied the whole row value (a block with all its spans) and each// `v = v[f]` step copied the rest again, per read, per mount; a path of up to three steps is one indexed readlet name = node.namelet inRow = rows[name] != nullif (node.k == 'field') {let path = node.pathlet n = path.lengthif (n == 1) {if (inRow) { return rows[name] == null ? null : rows[name][path[0]] }return page[name] == null ? null : page[name][path[0]]}if (n == 2) {if (inRow) { return rows[name][path[0]] == null ? null : rows[name][path[0]][path[1]] }return page[name][path[0]] == null ? null : page[name][path[0]][path[1]]}}let v = nullif (inRow) { v = rows[name] } else { v = page[name] }if (node.k == 'field') {for (f of node.path) {if (v == null) { return null }v = v[f]}}return v}// A VIEW EXPRESSION (`p { "x" + n }`, `a - b`, `n > 3 ? 'big' : 'small'`) is evaluated by// the LANGUAGE'S OWN OPERATORS: this walk only picks the operator the author wrote and// applies it, so what `+` gives null and a string, what `==` says of two types, what `&&`// returns — all of it is the runtime's answer, on the server (the interpreter or a// binary) and in the browser (the client target), and hl:web has no rule of its own.// The leaves are reads (`value`) and literals. `&&`, `||` and `?:` evaluate what they// pick only, as the language does.evalExpr(&x, &page, &rows) {if (x.k == 'bin') {let l = evalExpr(&x.l, &page, &rows)let op = x.opif (op == 'logical_and') { return l && evalExpr(&x.r, &page, &rows) }if (op == 'logical_or') { return l || evalExpr(&x.r, &page, &rows) }let r = evalExpr(&x.r, &page, &rows)if (op == 'add') { return l + r }if (op == 'subtract') { return l - r }if (op == 'multiply') { return l * r }if (op == 'divide') { return l / r }if (op == 'modulo') { return l % r }if (op == 'equal') { return l == r }if (op == 'not_equal') { return l != r }if (op == 'less_than') { return l < r }if (op == 'greater_than') { return l > r }if (op == 'less_equal') { return l <= r }if (op == 'greater_equal') { return l >= r }if (op == 'bit_and') { return l & r }if (op == 'bit_or') { return l | r }if (op == 'bit_xor') { return l ^ r }if (op == 'shift_left') { return l << r }return l >> r}if (x.k == 'un') {let o = evalExpr(&x.x, &page, &rows)if (x.op == 'logical_not') { return !o }if (x.op == 'negate') { return -o }return ~o}if (x.k == 'cond') { return evalExpr(&x.c, &page, &rows) ? evalExpr(&x.a, &page, &rows) : evalExpr(&x.b, &page, &rows) }return value(&x, &page, &rows)}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
- 3c425eddReference PR content styles and explain dynamic state classesmre
- e46fa222Own shell feedback styles and retain documented selector formsmre
- c26084c4Reference repository list styles and nest its breakpointmre
- f3e196b5Document Markdown direct-child selector remaindersmre
- 70597528Reference pull list rules and explain runtime class predicatesmre
- 1ce7ac24Reference ticket row and feedback styles from its Viewmre
- 10cdf54bGive organization repository rows their own Style referencesmre
- 0d019521Document shared class selectors in the styles-only filemre
- c67404a7Scope token labels and feedback through the token Viewmre
- 944e3dabScope key names, fingerprints and errors to the keys Viewmre
- 7bcf7bc2Nest repo navigation media rules and document selector gapsmre
- 46a76272Reference release row styles from the Viewmre
- a383f428Tie README definition and path styles to its own Viewmre
- a90812ffConsolidate add-code styles under its existing View idmre
- 89107a3eDocument the index direct-child selector remaindermre
- 07403362Scope reply form layout through the component form rulemre
- 097c52baStyle the login error through its View idmre
- c6d9c86aOwn the not-found code rule in its componentmre
- 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre