| Crates.io | itml-parser |
| lib.rs | itml-parser |
| version | 0.1.0 |
| created_at | 2025-10-28 09:00:21.662401+00 |
| updated_at | 2025-10-28 09:00:21.662401+00 |
| description | Parser / Formatter / Linter for ITML v0.1 — the Intention Markup Language |
| homepage | https://github.com/intent-ecosystem/itml-parser |
| repository | https://github.com/intent-ecosystem/itml-parser |
| max_upload_size | |
| id | 1904407 |
| size | 146,182 |
Parser, formatter, and linter for ITML v0.1 — the Intention Markup Language used by the Intent Registry ecosystem.
.itml text according to ITML v0.1 specificationAdd to your Cargo.toml:
[dependencies]
itml-parser = "0.1"
use itml_parser::{parse, format, lint, ParseOptions, FormatOptions, LintOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let itml_source = r#"
schema "Address"
description: "A postal address schema"
fields:
street: string
city: string
state: string
zip: string
country: string = "US"
validation:
- street: required
- city: required
- state: required
- zip: pattern("^[0-9]{5}(-[0-9]{4})?$")
"#;
// Parse ITML
let parse_opts = ParseOptions::default();
let doc = parse(itml_source, &parse_opts)?;
println!("Parsed: {:?}", doc);
// Format ITML
let format_opts = FormatOptions::default();
let formatted = format(&doc, &format_opts);
println!("Formatted:\n{}", formatted);
// Lint ITML
let lint_opts = LintOptions::default();
let diagnostics = lint(&doc, &lint_opts);
for diagnostic in diagnostics {
println!("Lint: {} - {}", diagnostic.code, diagnostic.message);
}
Ok(())
}
npm install @intent/itml-parser-wasm
import init, { parse_itml, format_itml, lint_itml } from '@intent/itml-parser-wasm';
await init();
const itmlSource = `
schema "Address"
description: "A postal address schema"
fields:
street: string
city: string
state: string
zip: string
`;
// Parse ITML
const ast = parse_itml(itmlSource);
console.log('Parsed AST:', ast);
// Format ITML
const formatted = format_itml(itmlSource, 2);
console.log('Formatted ITML:', formatted);
// Lint ITML
const diagnostics = lint_itml(itmlSource, ['ITML001', 'ITML002']);
console.log('Lint diagnostics:', diagnostics);
parse(input: &str, opts: &ParseOptions) -> Result<Document, ParseError>Parses ITML source code into a typed AST.
Parameters:
input: The ITML source code to parseopts: Parse options (tabs, line endings, etc.)Returns: Document AST or ParseError
format(doc: &Document, opts: &FormatOptions) -> StringFormats a Document AST into canonical ITML text.
Parameters:
doc: The Document AST to formatopts: Format options (indentation, trailing newline, etc.)Returns: Formatted ITML string
lint(doc: &Document, opts: &LintOptions) -> Vec<Diagnostic>Lints a Document AST and returns diagnostic information.
Parameters:
doc: The Document AST to lintopts: Lint options (enabled rules, fix mode, etc.)Returns: Vector of diagnostic objects
parse_itml(input: string): JsValueParses ITML source code and returns the AST as a JavaScript object.
format_itml(input: string, indent?: number): stringFormats ITML source code with consistent indentation.
lint_itml(input: string, rules?: string[]): JsValueLints ITML source code and returns diagnostic information.
| Code | Description | Level |
|---|---|---|
| ITML001 | Every intent must have inputs and (workflow or rules) | Error |
| ITML002 | Avoid "*" in network.allow | Warning |
| ITML003 | Routes targets must exist | Error |
| ITML004 | Tests required when rules exist | Warning |
| ITML005 | Do not mix tabs and spaces | Error |
| ITML006 | Unknown keys warn with suggestions | Warning |
string, number, boolean, datetime, uuid, byteslist(T), map(T), enum(...)See the examples/ directory for sample ITML files:
address.valid.itml - Valid address schemaaddress.invalid.itml - Invalid syntax exampleproject.app.itml - Complete application definitionsend_email.intent.itml - Complex intent with workflow# Build Rust crate
cargo build
# Run tests
cargo test
# Run benchmarks
cargo bench
# Build WASM package
make wasm
# Run all tests including WASM
make test-all
itml-parser/
├── src/
│ ├── ast.rs # AST type definitions
│ ├── parser.rs # ITML parser implementation
│ ├── formatter.rs # Pretty printer
│ ├── linter/ # Lint rules and diagnostics
│ ├── wasm.rs # WASM bindings
│ └── lib.rs # Public API
├── grammar/
│ └── itml.pest # Pest grammar definition
├── examples/ # Sample ITML files
├── tests/ # Test suites
├── benches/ # Performance benchmarks
├── wasm/ # WASM package files
└── .github/workflows/ # CI/CD configuration
The parser is optimized for performance with:
Benchmark results (on modern hardware):
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)cargo fmt and cargo clippyThis project is licensed under the MIT License - see the LICENSE file for details.