mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-02-03 22:15:42 -06:00
3.5 KiB
3.5 KiB
bases compiler + runtime (quartz implementation)
status: active last updated: 2026-01-28
this directory contains the obsidian bases compiler, interpreter, and runtime helpers used by quartz to render .base files. it is designed to match obsidian bases syntax and semantics with deterministic evaluation and consistent diagnostics.
You can test it out with any of the base file in my vault here:
npx tsx quartz/util/base/inspect-base.ts docs/navigation.base > /tmp/ast-ir.json
jq '.expressions[] | {context, kind, source, ast}' /tmp/ast-ir.json
jq '.expressions[] | {context, kind, ir}' /tmp/ast-ir.json
scope
- parse base expressions (filters, formulas, summaries, property expressions)
- compile expressions to bytecode ir
- interpret bytecode with a deterministic stack vm
- resolve file, note, formula, and property values
- render views (table, list, cards/gallery, board, calendar, map)
- surface parse and runtime diagnostics in base output
architecture (pipeline)
- parse
.baseyaml (plugin:quartz/plugins/transformers/bases.ts) - parse expressions into ast (
compiler/parser.ts) - compile ast to ir (
compiler/ir.ts) - evaluate ir per row with caches (
compiler/interpreter.ts) - render views and diagnostics (
render.ts)
modules
compiler/lexer.ts: tokenizer with span tracking and regex supportcompiler/parser.ts: pratt parser for expression grammar and error recoverycompiler/ir.ts: bytecode instruction set + compilercompiler/interpreter.ts: stack vm, value model, coercions, methods, functionscompiler/diagnostics.ts: diagnostics types and helperscompiler/schema.ts: summary config schema and builtinscompiler/properties.ts: property expression builder for columns and config keysrender.ts: view rendering and diagnostics outputquery.ts: summaries and view summary helperstypes.ts: base config types and yaml parsing helpers
value model (runtime)
runtime values are tagged unions with explicit kinds:
- null, boolean, number, string
- date, duration
- list, object
- file, link
- regex, html, icon, image
coercions are permissive to match obsidian behavior. comparisons prefer type-aware equality (links resolve to files when possible, dates compare by time, etc), with fallbacks when resolution fails.
expression features (spec parity)
- operators:
==,!=,>,<,>=,<=,&&,||,!,+,-,*,/,% - member and index access
- function calls and method calls
- list literals and regex literals
thisbinding with embed-aware scoping- list helpers (
filter,map,reduce) using implicit localsvalue,index,acc - summary context helpers:
values(column values) androws(row files)
diagnostics
- parser diagnostics are collected with spans at compile time
- runtime diagnostics are collected during evaluation and deduped per context
- base views render diagnostics above the view output
this scoping
- main base file:
thisresolves to the base file - embedded base:
thisresolves to the embedding file - row evaluation:
fileresolves to the row file
performance decisions
- bytecode ir keeps evaluation linear and stable
- per-build backlink index avoids n^2 scans
- property cache memoizes property expressions per file
- formula cache memoizes formula evaluation per file
view rendering
- table, list, cards/gallery, board, calendar, map
- map rendering expects coordinates
[lat, lon]and map config fields - view filters combine with base filters via logical and