doccy 0.3.2

Doccy is a simple brace based markup language.
Documentation
extern crate clap;
extern crate doccy;

use clap::{App, SubCommand};
use doccy::{doccy_to_html, grammar::ParseError};
use std::io::{self, Read};
use std::process::exit;

fn main() {
    let matches = App::new("Doccy")
        .about("Doccy is a simple brace based markup language.")
        .version(env!("CARGO_PKG_VERSION"))
        .subcommand(SubCommand::with_name("to-html").about("Parse and render input as HTML."))
        .get_matches();

    if let Some(_) = matches.subcommand_matches("to-html") {
        let mut buffer = String::new();

        io::stdin().read_to_string(&mut buffer).unwrap();

        match doccy_to_html(&buffer) {
            Ok(html) => println!("{}", html),
            Err(error) => display_error(buffer, error),
        };
    }
}

fn display_error(input: String, error: ParseError) {
    let lines = input.as_str().lines();
    let mut line = 0;

    for text in lines {
        line += 1;

        if line > error.line - 7 && line <= error.line {
            println!("\t{}: {}", line, text);
        }
    }

    println!(
        "\t{}^\nExpected one of {:?}",
        &(0..(error.column)).map(|_| " ").collect::<String>(),
        error.expected
    );

    exit(1);
}