- Transpile adapter-sx.sx (aser) alongside adapter-html.sx for SX wire format - Add platform functions: serialize, escape_string, is_special_form, is_ho_form, aser_special (with proper control-flow-through-aser dispatch) - SxExpr wrapping prevents double-quoting in aser output - async_eval_ref.py: async wrapper with I/O primitives, RequestContext, async_render, async_eval_to_sx, async_eval_slot_to_sx - SX_USE_REF=1 env var switches shared.sx imports to transpiled backend - 68 comparison tests (test_sx_ref.py), 289 total tests passing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
81 lines
1.4 KiB
Python
81 lines
1.4 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,
|
|
)
|
|
import os as _os
|
|
|
|
if _os.environ.get("SX_USE_REF") == "1":
|
|
from .ref.sx_ref import (
|
|
EvalError,
|
|
evaluate,
|
|
make_env,
|
|
)
|
|
else:
|
|
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",
|
|
]
|