Function gutenberg_post_parser::root[][src]

pub fn root(input: Input) -> Result<(Input, Vec<Node>), Err<Input>>

The root function represents the axiom of the grammar, i.e. the top rule.

This is the main function to call to parse a traditional post.

Examples

In this example, one might notice that the output is a pair, where the left side contains the remaining data (i.e. data that have not been parsed, because the parser has stopped), and the right side contains the Abstract Syntax Tree (AST).

The left side should ideally always be empty.

extern crate gutenberg_post_parser;

use gutenberg_post_parser::{root, ast::Node};

let input = &b"<!-- wp:foo {\"bar\": true} /-->"[..];
let output = Ok(
    (
        // The remaining data.
        &b""[..],

        // The Abstract Syntax Tree.
        vec![
            Node::Block {
                name: (&b"core"[..], &b"foo"[..]),
                attributes: Some(&b"{\"bar\": true}"[..]),
                children: vec![]
            }
        ]
    )
);

assert_eq!(root(input), output);