gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita0727ca3a0727ca3ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmrea0727ca3/plugins/core/AST.hl

13.5 KB

  1. // hl:core/AST — WHAT A FILE READS AND WHAT IT WRITES, from the compiler's own AST.
  2. //
  3. // The language has always been able to hand a caller the SYNTAX of a node
  4. // (`hlSyntax`) and the list of members a file declares (`hlMembers`). What it
  5. // never answered is what that syntax DOES with names: which members an
  6. // expression reads, which members a handler writes. Every consumer that needed
  7. // it wrote its own walk — hl:web's tree builder decides per tag what counts as
  8. // a read, and its browser half rediscovers the same set at runtime by walking
  9. // the DOM against the tree and JSON-comparing state afterwards (FRAMEWORK_AUDIT
  10. // §3). Two copies of one answer drift, and neither could see a write at all.
  11. //
  12. // The answer is the language's, so it lives here. `query(file)` is a table of
  13. // one file's (and, recursively, its project's) members, derivations, handlers
  14. // and methods, each with the names it reads and the names it writes, every node
  15. // carrying a stable site id `file:line:col`.
  16. //
  17. // NOTHING HERE KNOWS WHAT A VIEW IS. There is no attr, text, region, key or
  18. // component vocabulary in this file and none in the runtime rule beneath it: a
  19. // member is a member. A caller that wants one member's answer — hl:web wants
  20. // `View`'s — passes that member's NAME as the filter. That is the only way to
  21. // narrow the query, and it is a name, not a concept.
  22. //
  23. // import { query } from 'hl:core/AST'
  24. // let q = query('components/home.hl') // recursive, every member
  25. // let v = query('components/home.hl', true, 'View')
  26. //
  27. // THE GENERATION. Reflection reads a parse that is valid until the next
  28. // analysis; this package runs one of its own (`hlProject()`) the first time it
  29. // is asked and keeps the handle. `refresh()` runs a new one — a dev reload, or
  30. // a caller that changed a file. A static cannot be reassigned, so the handle
  31. // lives in a static hybrid, which can.
  32. static state = { gen = 0; graph = null; }
  33. // The live analysis generation, started on first use.
  34. static analysis = () => {
  35. if (state.gen == 0) {
  36. let g = hlProject()
  37. state.graph = g
  38. state.gen = g.analysisGen
  39. }
  40. return state.gen
  41. }
  42. // A NEW ANALYSIS: the parses this package answers from are replaced, and every
  43. // handle a caller still holds from the old one is refused by the language.
  44. static refresh = () => {
  45. let g = hlProject()
  46. state.graph = g
  47. state.gen = g.analysisGen
  48. return state.gen
  49. }
  50. // …of a project this run did not boot: a directory, a manifest, or an entry
  51. // file. The keys every answer below is filed under are that project's.
  52. static analyseFrom = (path) => {
  53. let g = hlProject(path)
  54. state.graph = g
  55. state.gen = g.analysisGen
  56. return state.gen
  57. }
  58. // The project graph the generation belongs to (`hlProject()`'s answer).
  59. static project = () => {
  60. analysis()
  61. return state.graph
  62. }
  63. // ---- the reflection surface, without the generation argument ------------------
  64. // `hlSyntax` and `hlMembers` are the ambient names the framework still calls;
  65. // here they are statics of a package, which is where they belong.
  66. static syntax = (file, node) => { return hlSyntax(analysis(), file, node) }
  67. static members = (file) => { return hlMembers(analysis(), file) }
  68. static methods = (file) => { return hlMethods(analysis(), file) }
  69. static handlers = (file) => { return hlEvents(analysis(), file).handles }
  70. static denotes = (file, name) => { return hlDenotes(analysis(), file, name) }
  71. static file = (file) => { return hlFile(analysis(), file) }
  72. // ---- the syntax of one node, as a tree ----------------------------------------
  73. // Every node carries its tag, its site id and the two answers the language gives
  74. // for it: the free names it READS and the names it WRITES. The shape below is
  75. // the shape `hlSyntax` returns, followed one child at a time — there is no
  76. // interpretation of any tag, only its children.
  77. //
  78. // AN `on` HANDLER IS A LEAF HERE ON PURPOSE. Its body is not evaluated by the
  79. // literal that carries it, so the names inside are the HANDLER's reads and
  80. // writes, not the literal's; the node answers for them and the walk stops.
  81. static tree = (file, node) => {
  82. let n = hlSyntax(analysis(), file, node)
  83. if (n == null) { return null }
  84. let out = { tag = n.tag; site = n.site; line = n.line; col = n.col; reads = n.reads; writes = n.writes; }
  85. if (n.tag == 'object_expression') {
  86. let kids = []
  87. for (h of n.entries) { kids.push(tree(file, h)) }
  88. out.entries = kids
  89. } else if (n.tag == 'object_property') {
  90. out.key = n.key
  91. out.value = tree(file, n.value)
  92. } else if (n.tag == 'view_for') {
  93. // A `for` ENTRY NAMES ITS LIST AND ITS ROW VARIABLE. The list is read in
  94. // the scope standing around the `for`; the row variable is bound inside
  95. // the body and every read of it there resolves as kind 'row'.
  96. out.row = n.varName
  97. out.list = tree(file, n.list)
  98. out.body = tree(file, n.body)
  99. } else if (n.tag == 'view_if') {
  100. out.condition = tree(file, n.condition)
  101. out.consequent = tree(file, n.consequent)
  102. out.alternate = tree(file, n.alternate)
  103. } else if (n.tag == 'on_statement') {
  104. out.event = n.event
  105. out.scope = n.scope
  106. out.realm = n.realm
  107. out.handler = n.handler
  108. } else if (n.tag == 'identifier' || n.tag == 'new_expression') {
  109. out.name = n.name
  110. } else if (n.tag == 'literal') {
  111. out.kind = n.kind
  112. out.text = n.text
  113. } else if (n.tag == 'member_expression') {
  114. out.object = tree(file, n.object)
  115. out.property = tree(file, n.property)
  116. out.computed = n.computed
  117. } else if (n.tag == 'call_expression') {
  118. out.callee = tree(file, n.callee)
  119. let args = []
  120. for (h of n.args) { args.push(tree(file, h)) }
  121. out.args = args
  122. } else if (n.tag == 'binary_expression') {
  123. out.operator = n.operator
  124. out.left = tree(file, n.left)
  125. out.right = tree(file, n.right)
  126. } else if (n.tag == 'unary_expression') {
  127. out.operator = n.operator
  128. out.operand = tree(file, n.operand)
  129. } else if (n.tag == 'conditional_expression') {
  130. out.condition = tree(file, n.condition)
  131. out.consequent = tree(file, n.consequent)
  132. out.alternate = tree(file, n.alternate)
  133. } else if (n.tag == 'array_expression') {
  134. let els = []
  135. for (h of n.elements) { els.push(tree(file, h)) }
  136. out.elements = els
  137. }
  138. return out
  139. }
  140. // ---- names ---------------------------------------------------------------------
  141. // A read or a write is `{ name, kind, isStatic, path?, key? }`. `kind` is the
  142. // language's own resolution of the bare name: 'member', 'method', 'handler',
  143. // 'class' (a default import), 'import' (a braced one), 'plugin', 'row' (bound by
  144. // an enclosing `for` entry), 'local' (a lambda, handler or method parameter, or
  145. // a `let`), 'none' (nothing this file declares — an ambient or a typo).
  146. // the names of a read/write list, as plain strings
  147. static namesOf = (list) => {
  148. let out = []
  149. for (r of list) { if (!out.includes(r.name)) { out.push(r.name) } }
  150. return out
  151. }
  152. // the subset of a read/write list that resolves to a member of the file itself
  153. static membersOf = (list) => {
  154. let out = []
  155. for (r of list) {
  156. if (r.kind == 'member' && !r.isStatic && !out.includes(r.name)) { out.push(r.name) }
  157. }
  158. return out
  159. }
  160. // ---- one file's answer ---------------------------------------------------------
  161. // every `on` node inside a member's syntax tree, flattened, each at its site
  162. static nestedHandlers = (member, node, &into) => {
  163. if (node == null) { return into }
  164. if (node.tag == 'on_statement') {
  165. into.push({ member = member; event = node.event; scope = node.scope; realm = node.realm; site = node.site; reads = node.reads; writes = node.writes; nested = true; })
  166. return into
  167. }
  168. if (node.entries != null) { for (c of node.entries) { nestedHandlers(member, c, into) } }
  169. if (node.args != null) { for (c of node.args) { nestedHandlers(member, c, into) } }
  170. if (node.elements != null) { for (c of node.elements) { nestedHandlers(member, c, into) } }
  171. if (node.value != null) { nestedHandlers(member, node.value, into) }
  172. if (node.list != null) { nestedHandlers(member, node.list, into) }
  173. if (node.body != null) { nestedHandlers(member, node.body, into) }
  174. if (node.condition != null) { nestedHandlers(member, node.condition, into) }
  175. if (node.consequent != null) { nestedHandlers(member, node.consequent, into) }
  176. if (node.alternate != null) { nestedHandlers(member, node.alternate, into) }
  177. if (node.object != null) { nestedHandlers(member, node.object, into) }
  178. if (node.property != null) { nestedHandlers(member, node.property, into) }
  179. if (node.callee != null) { nestedHandlers(member, node.callee, into) }
  180. if (node.left != null) { nestedHandlers(member, node.left, into) }
  181. if (node.right != null) { nestedHandlers(member, node.right, into) }
  182. if (node.operand != null) { nestedHandlers(member, node.operand, into) }
  183. return into
  184. }
  185. static one = (key, member) => {
  186. let gen = analysis()
  187. let f = hlFile(gen, key)
  188. let out = { key = key; class = f.class; members = []; derivations = []; handlers = []; methods = []; reaches = []; }
  189. for (m of hlMembers(gen, key)) {
  190. // (Hybriel has no `continue`: the body is guarded instead.)
  191. if (member == null || m.name == member) {
  192. let entry = { name = m.name; type = m.type; mandatory = m.mandatory; isStatic = m.isStatic; site = key + ':' + m.line + ':' + m.col; default = null; reads = []; writes = []; syntax = null; }
  193. if (m.hasValue) {
  194. let n = hlSyntax(gen, key, m.node)
  195. entry.default = n.site
  196. entry.reads = n.reads
  197. entry.writes = n.writes
  198. entry.syntax = tree(key, m.node)
  199. // A DERIVATION IS AN INITIALIZER READ THE OTHER WAY: the same table,
  200. // listed by the names the value depends on.
  201. out.derivations.push({ name = m.name; site = n.site; reads = n.reads; })
  202. nestedHandlers(m.name, entry.syntax, out.handlers)
  203. for (r of n.reads) {
  204. if (r.kind == 'class' && r.key != null && !out.reaches.includes(r.key)) { out.reaches.push(r.key) }
  205. }
  206. }
  207. out.members.push(entry)
  208. }
  209. }
  210. // The DECLARED handlers and methods answer for their whole body. A member
  211. // filter narrows the member table only — a handler is not a member, and
  212. // hiding the writes would make the filtered answer a lie about the file.
  213. for (h of hlEvents(gen, key).handles) {
  214. let n = hlSyntax(gen, key, h.node)
  215. out.handlers.push({ member = null; event = h.event; scope = h.scope; realm = h.realm; params = h.params; site = n.site; reads = n.reads; writes = n.writes; nested = false; })
  216. }
  217. for (mm of hlMethods(gen, key)) {
  218. // A literal's inline `on` is hoisted as a method over the SAME body
  219. // (parser `inlineHandlerEntry`); it already answered at its site above.
  220. if (!mm.inlineHandler) {
  221. let n = hlSyntax(gen, key, mm.node)
  222. out.methods.push({ name = mm.name; params = mm.params; site = n.site; reads = n.reads; writes = n.writes; })
  223. }
  224. }
  225. // WHAT THIS FILE REACHES: every import the language resolved to another file
  226. // of the project, and every composed reference a member's syntax read.
  227. if (state.graph.files[key] != null) {
  228. for (imp of state.graph.files[key].imports) {
  229. if (imp.key != null && !out.reaches.includes(imp.key)) { out.reaches.push(imp.key) }
  230. }
  231. }
  232. if (f.wrapper != null && !out.reaches.includes(f.wrapper)) { out.reaches.push(f.wrapper) }
  233. for (k of f.inherits) { if (!out.reaches.includes(k)) { out.reaches.push(k) } }
  234. return out
  235. }
  236. // ---- the query -----------------------------------------------------------------
  237. // `query(file, recursive = true, member = null)`:
  238. // files — one answer per file reached, keyed by the analysis key
  239. // order — the keys in the order they were reached, `file` first
  240. // Recursive follows what each file reaches (its imports, its wrapper, what it
  241. // inherits, and the composed references its members read), each file once.
  242. static query = (file, recursive, member) => {
  243. let rec = recursive == null ? true : recursive
  244. let want = member == null ? null : member
  245. analysis()
  246. let out = { root = file; files = {}; order = []; }
  247. let queue = [file]
  248. let seen = {}
  249. while (queue.length > 0) {
  250. let key = queue.shift()
  251. if (seen[key] == null) {
  252. seen[key] = true
  253. // A key the analysis does not hold is not this package's to parse —
  254. // the root is answered regardless, because the caller named it.
  255. if (state.graph.files[key] != null || key == file) {
  256. let answer = one(key, want)
  257. out.files[key] = answer
  258. out.order.push(key)
  259. if (rec) {
  260. for (k of answer.reaches) { if (seen[k] == null) { queue.push(k) } }
  261. }
  262. }
  263. }
  264. }
  265. return out
  266. }
  267. // EVERY FILE THE ANALYSIS HOLDS, once. A project's root reaches nearly all of
  268. // them; this reaches the rest too, which is what a whole-project report wants.
  269. static queryAll = (member) => {
  270. analysis()
  271. let out = { root = null; files = {}; order = []; }
  272. for (k of state.graph.files.keys()) {
  273. out.files[k] = one(k, member)
  274. out.order.push(k)
  275. }
  276. return out
  277. }
  278. // ---- what `hybriel --graph` carries, per file -----------------------------------
  279. // THE ONE DOCUMENT ASKS THIS PACKAGE (creator, 2026-09-14: the language scans
  280. // EVERYTHING by default and a filter only narrows). `--graph` prints the
  281. // language graph, and every file record in it carries the four tables below —
  282. // the same objects `query()` puts in `files[key]`, handed to the writer as they
  283. // are. There is no second walk and no second rendering: a person reads that
  284. // JSON, and a program imports `query` and gets the same answer as values.
  285. // `trees == false` (`--graph --no-ast`) leaves each member's syntax tree out —
  286. // `syntax` is null, every other field is the same bytes. null or true keeps it.
  287. static tables = (path, member, trees) => {
  288. if (path == null) { analysis() } else { analyseFrom(path) }
  289. let q = queryAll(member)
  290. let out = {}
  291. for (k of q.order) {
  292. let f = q.files[k]
  293. if (trees == false) { for (m of f.members) { m.syntax = null } }
  294. out[k] = { members = f.members; derivations = f.derivations; methods = f.methods; handlers = f.handlers; }
  295. }
  296. return out
  297. }

Branches

Latest commits

  • a0727ca3ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • a06975f9gitoria: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 32ba9d59gitoria: leave the host-only cookie experiment out of the browser gate (gitoria#24 is a separate mission)mre
  • 43ad2bcfgitoria header: the selector alone plus your name and Log out as before the theme missions; tests follow (WIP: host-only cookie experiment fails)mre
  • ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre