Skip to main content

Crate neutron_engine

Crate neutron_engine 

Source
Expand description

§Neutron Engine

A lightweight markup parser for the Neutron styling language (.nt). Provides fast, zero-dependency parsing of XML-like tags with inline style declarations.

§Example

use neutron_engine::{parse_tag, parse_attributes, parse_style, normalize_decl, Attribute, StyleDecl};

let tag = r#"<Container style="b:#000; w:fill" id="Main">"#;
if let Some((name, attrs_text)) = parse_tag(tag) {
    println!("Tag: {}", name);

    let mut attrs = [Attribute { name: "", value: "" }; 12];
    let attr_count = parse_attributes(attrs_text, &mut attrs);

    for attr in &attrs[..attr_count] {
        if attr.name == "style" {
            let mut styles = [StyleDecl { name: "", value: "" }; 16];
            let style_count = parse_style(attr.value, &mut styles);

            for style in &styles[..style_count] {
                let prop = normalize_decl(*style);
                println!("Style: {:?}", prop);
            }
        }
    }
}

Modules§

iris

Structs§

Attribute
Represents an attribute with name and value
StyleDecl
Represents a style declaration with name and value

Enums§

StyleProp
Normalized style property enum

Functions§

normalize_decl
Normalize a style declaration into a typed StyleProp
parse_attributes
Parse attributes from a string into an array of Attribute structs
parse_neutron
Parse a complete Neutron document and print the parsed structure
parse_neutron_file
Read a Neutron file and parse it
parse_style
Parse style declarations from a string
parse_tag
Parse a tag string into tag name and attributes text