Declarative Parser

The Matrix Framework’s declarative parser allows you to define your middleware tree structure using a familiar markup syntax.

Overview

The parser processes markup files to create a hierarchical tree of middleware components.

Example

<TreeGeometry>
    <MQTTConnector Name="MQTTConnector" Path="/mqtt">
        <JWTAuthorizationComponent Name="JWTAuthorization" Path="/jwt">
            <TerminalComponent Name="Terminal" Path="/terminal" />
        </JWTAuthorizationComponent>
    </MQTTConnector>
</TreeGeometry>

Key Features

  • Component Creation: Automatically creates and configures components
  • Property Setting: Sets component properties from attributes
  • Event Binding: Binds event handlers using onEventName attributes
  • Tree Building: Constructs the middleware tree hierarchy

Usage

// Parse markup string
const tree = await Parser.parse(markupString);

// Access components
const mqttConnector = tree.findNode("/mqtt");
const terminal = tree.findNode("/mqtt/jwt/terminal");

Best Practices

  1. Organize Components

    • Group related components together
    • Use consistent naming conventions
    • Maintain clear hierarchy
  2. Property Configuration

    • Set properties using attributes
    • Use data binding where appropriate
    • Validate property values
  3. Event Handling

    • Bind event handlers declaratively
    • Keep handler names descriptive
    • Consider event propagation