piston_meta

A DSL parsing library for human readable text documents

Travis Crates.io

Documentation

Why Piston-Meta?

self-syntax

Notice: Parsing is supported but composing is not implemented yet.

"Hello world" in Piston-Meta

Piston-Meta allows parsing into any structure implementing MetaReader, for example Tokenizer. Tokenizer stores the tree structure in a flat Vec with "start node" and "end node" items.

```Rust extern crate piston_meta;

use piston_meta::*;

fn main() { let text = r#"say "Hello world!""#; let rules = r#"1 "rule" ["say" w! t?"foo"]"#; // Parse rules with meta language and convert to rules for parsing text. let rules = bootstrap::convert( &parse(&bootstrap::rules(), rules).unwrap(), &mut vec![] // stores ignored meta data ).unwrap(); let data = parse(&rules, text); match data { Ok(data) => { asserteq!(data.len(), 1); if let &MetaData::String(, ref hello) = &data[0].1 { println!("{}", hello); } } Err((range, err)) => { // Report the error to standard error output. ParseStdErr::new(&text).error(range, err); } } } ```

How does it work?

  1. Piston-Meta contains composable rules that can parse most human readable text formats.
  2. Piston-Meta knows how to parse and convert to its own rules, known as "bootstrapping".
  3. Therefore, you can tell Piston-Meta how to parse other text formats using a meta language!