Skip to content

liveview-native/vml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VML - View Markup Language

A Zig parser for View Markup Language (VML), an XML-based markup language for describing SwiftUI user interface hierarchies.

Overview

VML provides a static, declarative representation of SwiftUI view hierarchies suitable for server-side generation and client-side rendering. This implementation is a Zig-based parser that validates and processes VML documents according to the VML 1.0 specification.

Features

  • Complete VML 1.0 Parser: Full implementation of the VML specification
  • Zero Dependencies: Pure Zig implementation with no external dependencies
  • Entity Decoding: Support for named and numeric HTML entities
  • Error Tracking: Line and column tracking for parse errors
  • Memory Safe: Proper allocation and deallocation with Zig's allocator system
  • Comment Stripping: Optional comment removal during parsing
  • Comprehensive Testing: Extensive test suite covering all parser features

Installation

Add VML to your build.zig.zon:

.dependencies = .{
    .vml = .{
        .url = "https://github.com/<your-repo>/vml/archive/<commit>.tar.gz",
        .hash = "...",
    },
},

Usage

Basic Parsing

const std = @import("std");
const vml = @import("vml");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    const input = 
        \\<!doctype swiftui+vml>
        \\<vml>
        \\  <body>
        \\    <Text style="font(.title)">Hello World</Text>
        \\  </body>
        \\</vml>
    ;

    var parser = vml.Parser.init(allocator, input);
    var doc = try parser.parse();
    defer doc.deinit(allocator);

    std.debug.print("Doctype: {s}\n", .{doc.doctype});
}

Parser Options

const options = vml.ParserOptions{
    .strip_comments = true,  // Remove comments during parsing
};

var parser = vml.Parser.initWithOptions(allocator, input, options);

Error Handling

var parser = vml.Parser.init(allocator, input);
const doc = parser.parse() catch |err| {
    if (parser.getErrorLocation()) |loc| {
        std.debug.print("Parse error at line {}, column {}: {s}\n", 
            .{loc.line, loc.column, loc.message});
    }
    return err;
};
defer doc.deinit(allocator);

VML Specification

This parser implements the View Markup Language Specification v1.0. Key features include:

  • XML-Based Syntax: Standard XML document structure
  • SwiftUI Mapping: Direct 1:1 mapping to SwiftUI view types
  • Style Attribute: Semicolon-separated SwiftUI modifiers
  • Template/Slot System: Support for ViewBuilder content
  • Entity Encoding: Full HTML entity support

Example VML Document

<!doctype swiftui+vml>
<vml>
  <head>
    <VStack template="launch" spacing="16">
      <ProgressView/>
      <Text style="font(.headline)">Loading...</Text>
    </VStack>
  </head>
  <body>
    <NavigationStack>
      <VStack spacing="20" style="padding(.top, 50)">
        <Image systemName="lock.circle.fill" 
               style="resizable();frame(width: 80, height: 80);foregroundStyle(.blue)"/>
        <TextField style="textFieldStyle(.roundedBorder)">Email</TextField>
        <Button style="buttonStyle(.borderedProminent)">Sign In</Button>
      </VStack>
    </NavigationStack>
  </body>
</vml>

Project Structure

vml/
├── src/
│   ├── main.zig      # CLI executable entry point
│   ├── root.zig      # Library root module
│   └── parser.zig    # VML parser implementation
├── build.zig         # Zig build configuration
├── build.zig.zon     # Package metadata
├── spec.md           # VML 1.0 specification
├── grammar.abnf      # ABNF grammar definition
└── README.md         # This file

Building

Build the project:

zig build

Run tests:

zig build test

Run the executable:

zig build run

Grammar

The parser implements the full ABNF grammar defined in grammar.abnf, supporting:

  • Document structure (<!doctype>, <vml>, <head>, <body>)
  • Elements (self-closing and container)
  • Attributes (quoted strings, entities)
  • Style syntax (modifiers, arguments, expressions)
  • Templates and slots
  • Comments
  • Whitespace handling

Requirements

  • Zig 0.15.1 or later

License

[Your License Here]

Contributing

Contributions are welcome! Please ensure all tests pass before submitting a pull request.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published