Files
mono/shared/sx/__init__.py
giles ab75e505a8 Add macros, declarative handlers (defhandler), and convert all fragment routes to sx
Phase 1 — Macros: defmacro + quasiquote syntax (`, ,, ,@) in parser,
evaluator, HTML renderer, and JS mirror. Macro type, expansion, and
round-trip serialization.

Phase 2 — Expanded primitives: app-url, url-for, asset-url, config,
format-date, parse-int (pure); service, request-arg, request-path,
nav-tree, get-children (I/O); jinja-global, relations-from (pure).
Updated _io_service to accept (service "registry-name" "method" :kwargs)
with auto kebab→snake conversion. DTO-to-dict now expands datetime fields
into year/month/day convenience keys. Tuple returns converted to lists.

Phase 3 — Declarative handlers: HandlerDef type, defhandler special form,
handler registry (service → name → HandlerDef), async evaluator+renderer
(async_eval.py) that awaits I/O primitives inline within control flow.
Handler loading from .sx files, execute_handler, blueprint factory.

Phase 4 — Convert all fragment routes: 13 Python fragment handlers across
8 services replaced with declarative .sx handler files. All routes.py
simplified to uniform sx dispatch pattern. Two Jinja HTML handlers
(events/container-cards, events/account-page) kept as Python.

New files: shared/sx/async_eval.py, shared/sx/handlers.py,
shared/sx/tests/test_handlers.py, plus 13 handler .sx files under
{service}/sx/handlers/. MarketService.product_by_slug() added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 00:22:18 +00:00

71 lines
1.2 KiB
Python

"""
S-expression language core.
Parse, evaluate, and serialize s-expressions. This package provides the
foundation for the composable fragment architecture described in
``docs/sx-architecture-plan.md``.
Quick start::
from shared.sx import parse, evaluate, serialize, Symbol, Keyword
expr = parse('(let ((x 10)) (+ x 1))')
result = evaluate(expr) # → 11
expr2 = parse('(map (fn (n) (* n n)) (list 1 2 3))')
result2 = evaluate(expr2) # → [1, 4, 9]
"""
from .types import (
NIL,
Component,
HandlerDef,
Keyword,
Lambda,
Macro,
Symbol,
)
from .parser import (
ParseError,
parse,
parse_all,
serialize,
)
from .evaluator import (
EvalError,
evaluate,
make_env,
)
from .primitives import (
all_primitives,
get_primitive,
register_primitive,
)
from .env import Env
__all__ = [
# Types
"Symbol",
"Keyword",
"Lambda",
"Macro",
"Component",
"HandlerDef",
"NIL",
# Parser
"parse",
"parse_all",
"serialize",
"ParseError",
# Evaluator
"evaluate",
"make_env",
"EvalError",
# Primitives
"register_primitive",
"get_primitive",
"all_primitives",
# Environment
"Env",
]