rustixml 0.2.0

Native iXML (Invisible XML) parser - 83.7% spec conformance, works in Rust and WebAssembly
Documentation

rustixml

Crates.io License WASM

A pure Rust implementation of the Invisible XML (iXML) specification with WebAssembly support.

Turn any text into XML using simple grammar rules. Works natively in Rust and in the browser via WebAssembly.

โœจ Features

  • ๐Ÿš€ Fast native recursive descent parser - Direct interpretation of iXML grammars
  • โœ… 83.7% spec conformance - 41 out of 49 correctness tests passing (details)
  • ๐ŸŒ WebAssembly support - 50KB gzipped, runs in any modern browser
  • ๐Ÿ“ฆ Single dependency - Only unicode-general-category for native builds
  • ๐Ÿ”’ Pure safe Rust - No unsafe code
  • ๐ŸŽฏ Zero-copy parsing - Efficient memory usage

๐Ÿš€ Quick Start

Rust

Add to your Cargo.toml:

[dependencies]
rustixml = "0.2"

Example usage:

use rustixml::{parse_ixml_grammar, NativeParser};

fn main() -> Result<(), String> {
    // Define an iXML grammar
    let grammar = r#"
        greeting: "Hello, ", name, "!".
        name: letter+.
        letter: ["A"-"Z"; "a"-"z"].
    "#;

    // Parse the grammar
    let ast = parse_ixml_grammar(grammar)?;
    
    // Create a parser
    let parser = NativeParser::new(ast);
    
    // Parse some input
    let xml = parser.parse("Hello, World!")?;
    
    println!("{}", xml);
    // Output: <greeting>Hello, <name>World</name>!</greeting>
    
    Ok(())
}

WebAssembly (Browser)

<!DOCTYPE html>
<html>
<head>
    <script type="module">
        import init, { parse_ixml } from './pkg/rustixml.js';

        async function run() {
            await init();

            const grammar = `
                greeting: "Hello, ", name, "!".
                name: letter+.
                letter: ["A"-"Z"; "a"-"z"].
            `;

            const result = parse_ixml(grammar, "Hello, World!");
            
            if (result.success) {
                console.log('XML:', result.output);
            } else {
                console.error('Error:', result.error);
            }
        }

        run();
    </script>
</head>
<body>
    <h1>iXML Parser Demo</h1>
</body>
</html>

๐ŸŽฎ Live Demo

Try it online: Demo Website (coming soon)

Or run locally:

# Clone the repository
git clone https://github.com/bigale/rustixml.git
cd rustixml

# Build WASM
wasm-pack build --target web

# Serve the demo
python3 -m http.server 8080

# Open http://localhost:8080/www/ in your browser

Three demo versions available:

  • www/index.html - Standard demo (recommended for most users)
  • www/htmz-standalone.html - HTMZ pattern demo (form-driven, no backend)
  • www/wasmz.html - WASMZ pattern demo โญ (native speed with wasm:// routing!)

See www/HTMZ-README.md for comparison of all three versions.

WASMZ Pattern: The wasmz.html demo showcases true wasm:// routing where HTML forms directly call compiled Rust functions that return HTML templates. This is a reference implementation of the WASMZ pattern (WebAssembly + htmz) offering ~10x performance improvement over JavaScript. See www/WASMZ-PATTERN.md for technical details.

๐Ÿ“– What is Invisible XML?

Invisible XML (iXML) is a specification for describing text formats as grammars and automatically converting text that matches those grammars into XML. It's like regular expressions on steroids!

Example: Parse CSV into XML:

csv: row+.
row: field+separator, field, newline.
field: char*.
@separator: ",".
-char: ~[","; #0A].
-newline: #0A.

Input:

name,age,city
Alice,30,NYC
Bob,25,LA

Output:

<csv>
  <row><field>name</field><field>age</field><field>city</field></row>
  <row><field>Alice</field><field>30</field><field>NYC</field></row>
  <row><field>Bob</field><field>25</field><field>LA</field></row>
</csv>

๐Ÿ—๏ธ Architecture

rustixml uses a native recursive descent parser that directly interprets iXML grammar ASTs. Unlike other implementations that use parser generators, this approach:

  • โœ… Eliminates intermediate compilation steps
  • โœ… Produces smaller WASM binaries (50KB vs 500KB+)
  • โœ… Handles insertion/suppression semantics natively
  • โœ… Provides better error messages

See docs/ARCHITECTURE.md for details.

๐Ÿ“Š Conformance

Overall: 45/65 tests (69.2%)
Correct tests: 41/49 tests (83.7%)

See docs/NATIVE_PARSER_STATUS.md for detailed test results.

๐Ÿ”ง Building

Native

cargo build --release

WebAssembly

# Install wasm-pack if you haven't already
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Build for web
wasm-pack build --target web

# Build for Node.js
wasm-pack build --target nodejs

# Build for bundlers (webpack, rollup, etc.)
wasm-pack build --target bundler

๐Ÿงช Testing

# Run unit tests
cargo test

# Run conformance tests
cargo run --bin conformance_test

๐Ÿ“ฆ Publishing

Crates.io

cargo publish

npm

wasm-pack build --target web
cd pkg
npm publish

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Areas where help is especially appreciated:

  • ๐Ÿ› Fixing failing test cases (see KNOWN_ISSUES.md)
  • ๐Ÿ“ Improving documentation
  • โœจ Adding examples
  • ๐Ÿงช Writing more tests

๐Ÿ“„ License

Licensed under either of:

at your option.

๐Ÿ™ Acknowledgments

  • iXML Specification by the Invisible XML Community Group
  • iXML Test Suite for comprehensive conformance testing
  • Rust and WebAssembly communities for excellent tooling

๐Ÿ“š Resources


Made with โค๏ธ and ๐Ÿฆ€ by Alex Everitt