Inhaltsverzeichnis
Pipeline PXAML
La pipeline PXAML trasforma il markup UI dichiarativo in interfacce utente eseguibili.
Panoramica
PXAML (Markup) → Parser → IR (JSON) → Renderer → GUI/TUI/Web
Fasi della pipeline
Fase 1: Parsing
Il parser PXAML legge il markup XML e genera un Abstract Syntax Tree (AST).
<!-- Input: PXAML --> <Window Title="Demo" Width="400"> <Button Content="Click me" Click="OnClick"/> </Window>
Compiti del parser:
- Validazione XML
- Risoluzione namespace
- Riconoscimento elementi
- Parsing attributi
- Riconoscimento binding eventi
Fase 2: Generazione IR
L'AST viene trasformato in una Intermediate Representation (IR) - un formato intermedio basato su JSON.
{
"type": "Window",
"properties": {
"Title": { "value": "Demo", "type": "string" },
"Width": { "value": 400, "type": "number" }
},
"children": [
{
"type": "Button",
"properties": {
"Content": { "value": "Click me", "type": "string" }
},
"events": {
"Click": { "handler": "OnClick" }
}
}
]
}
Proprieta IR:
- Indipendente dalla piattaforma
- Serializzabile (JSON)
- Differenziabile per Hot Reload
- Informazioni di tipo preservate
Fase 3: Risoluzione binding
I data binding vengono analizzati e convertiti in strutture eseguibili.
<!-- PXAML con binding --> <TextBox Text="{Binding Path=UserName, Mode=TwoWay}"/>
{
"type": "TextBox",
"properties": {
"Text": {
"type": "binding",
"path": "UserName",
"mode": "TwoWay"
}
}
}
Fase 4: Rendering
L'IR viene tradotto dal renderer specifico del target in elementi UI nativi.
| Renderer | Output | Tecnologia |
|---|---|---|
| GUI | Controlli nativi | LCL/WinAPI |
| TUI | Caratteri terminale | ANSI/VT100 |
| Web | Elementi DOM | HTML/CSS |
Componenti
TWvdSPxamlParser
type TWvdSPxamlParser = class public function Parse(const ASource: string): TWvdSIRNode; function ParseFile(const APath: string): TWvdSIRNode; end;
TWvdSIRNode
type TWvdSIRNode = class NodeType: string; Properties: TWvdSPropertyMap; Children: TWvdSIRNodeList; Events: TWvdSEventMap; Bindings: TWvdSBindingList; end;
TWvdSRenderer (Astratto)
type TWvdSRenderer = class abstract public procedure Render(ARoot: TWvdSIRNode); virtual; abstract; procedure Update(AOldRoot, ANewRoot: TWvdSIRNode); virtual; abstract; end;
Hot Reload
La pipeline supporta l'Hot Reload tramite differenziazione IR:
1. Nuovo PXAML → Parser → Nuovo IR 2. Diff(Vecchio IR, Nuovo IR) → Lista patch 3. Renderer.ApplyPatches(Lista patch)
Vantaggi:
- Solo gli elementi modificati vengono aggiornati
- Lo stato viene preservato
- Iterazione rapida durante lo sviluppo
Gestione errori
| Tipo errore | Fase | Gestione |
|---|---|---|
| Errore sintassi XML | Parsing | Posizione + messaggio |
| Elemento sconosciuto | Parsing | Warning + fallback |
| Tipo property non valido | IR | Coercizione tipo + warning |
| Errore binding | Binding | Valore fallback |
Vedi anche
Zuletzt geändert: il 29/01/2026 alle 22:29