47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""µFrame compile + DSL metadata endpoints."""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
import uframe
|
|
import uframe.keywords # noqa: F401 — triggers keyword registration
|
|
from uframe.errors import UFrameError
|
|
from uframe.registry import get_dsl_meta
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CompileRequest(BaseModel):
|
|
source: str
|
|
width: int = 64
|
|
|
|
|
|
class CompileResponse(BaseModel):
|
|
ascii: str
|
|
micron: str
|
|
script: str
|
|
is_dynamic: bool
|
|
warnings: list[str]
|
|
|
|
|
|
@router.post("/compile", response_model=CompileResponse)
|
|
async def compile_source(req: CompileRequest):
|
|
"""Compile µFrame .uf source into ASCII and Micron output."""
|
|
try:
|
|
result = uframe.compile(req.source, width=req.width)
|
|
return CompileResponse(
|
|
ascii=result.ascii,
|
|
micron=result.micron,
|
|
script=result.script,
|
|
is_dynamic=result.is_dynamic,
|
|
warnings=[w.message for w in result.warnings],
|
|
)
|
|
except UFrameError as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|
|
|
|
|
|
@router.get("/dsl-meta")
|
|
async def dsl_meta():
|
|
"""Return DSL metadata for frontend syntax highlighting and autocomplete."""
|
|
return get_dsl_meta()
|