keytree 0.2.4

Simple markup language designed to load config files and schemas directly to Rust types.
Documentation
// To handle debugging comprehensively, and to avoid lifetime issues, we use individual functions
// for each error. get the required resolution in error handling. Since these errors respond with
// stderr and then exit, we can't do standard tests of them. To test error handling, run
// /examples/parser.

use std::process;
use crate::parser::BuildVars;

pub struct KeyTreeErr;

// pub fn lines_around(s: &str, pos: usize, lines: n) -> (&[&str], start_line, end_line)

    // Take a slice from start to pos
    // s.chars().rev()
    // find n times (or hit the beginning of the str)
    
    // Take a slice from pos
    // s.chars()
    // find n times (or hit the end of the str)

    // return this as a slice


impl KeyTreeErr {

    pub fn append_path(_vars: &BuildVars) {
        // Path to be appended to.
        // Path to append.
        let s = "Tried to call at() on .. but failed to append path.";
        println!("{}", s);
        process::exit(1);
    }

    pub fn at_on_empty(_vars: &BuildVars) {
        let s = format!(
            "Tried to call at() on a non-existent path.",
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn colon_before_key(pos: usize) {
        let s = format!(
            "Expected a character to start a key but received a colon at pos: {}.",
            pos
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn char_after_value(pos: usize) {
        let s = format!(
            "char after value at pos: {}.",
            pos
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn empty_string() {
        let s = format!(
            "Could not parse empty string."
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn first_token_is_val(pos: usize, _vars: &BuildVars) {
        let s = format!(
            "Tried to parse string and expected first token to be a key, but it was a value at ps: {:?}.",
            pos
        );
        // vars.err_output(pos);
        println!("{}", s);
        process::exit(1);
    }

    pub fn indent(pos: usize, vars: &BuildVars) {
        let s = format!(
            "Tried to parse string but key must be indent in units of 4 at pos: {}.",
            pos
        );
        println!("{}", vars.s);
        println!("{}", s);
        process::exit(1);
    }

    pub fn line_incomplete(pos: usize) {
        let s = format!("Tried to parse line, but the line was incomplete error at pos: {}.", pos);
        println!("{}", s);
        process::exit(1);
    }

    pub fn missing_quote(pos: usize) {
        let s = format!(
            "missing quote at start of value at pos: {}.",
            pos
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn no_colon(pos: usize) {
        let s = format!(
            "Tried to parse a key but there was a whitespace but not colon at: {}.",
            pos,
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn no_space_after_key(pos: usize) {
        let s = format!(
           "Tried to parse a key but there was no space after the colon at: {}.",
           pos,
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn no_value() {
        let s = format!("Expected a value but couldn't find it.");
        println!("{}", s);
        process::exit(1);
    }

    pub fn non_contiguous() {
        let s = format!(
            //
            "A key appears in a non-contiguous position."
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn not_keyval() {
        let s = format!(
            "The token is not a key/value."
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn not_unique() {
        let s = "expected a unique path when calling value() on KeyTree, using context path.";
        println!("{}", s);
        process::exit(1);
    }

    pub fn not_unique_but_empty() {
        let s = "expected a unique path but found and empty path.";
        println!("{}", s);
        process::exit(1);
    }

    pub fn not_unique_but_many() {
        let s = "expected a unique path but found several paths.";
        println!("{}", s);
        process::exit(1);
    }

    pub fn not_value() {
        let s = "tried to call value() on KeyTree but the token at the context path was a Key.";
        // show path called.
        // show self: KeyTree.
        println!("{}", s);
        process::exit(1);
    }

    pub fn parse_keytree() {
        let s = "Failed to parse string.";
        println!("{}", s);
        process::exit(1);
    }

    pub fn parse_value() {
        let s = format!(
            "Tried to parse a value, but failed."
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn path_not_in_keymap() {
        let s = "tried to find text path in KeyTree but was not in KeyMap.";
        // show relevant part of s?
        // show path called
        // show self: KeyTree
        println!("{}", s);
        process::exit(1);
    }

    pub fn path_not_in_keylen() {
        let s = format!(
            "Tried to find path in KeyLen but was missing.",
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn quote_in_key(pos: usize) {
        let s = format!(
            "quote in key at pos: {}.",
            pos
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn path(pos: usize) {
        let s = format!(
            "path parsing error at pos: {}.",
            pos
        );
        println!("{}", s);
        process::exit(1);
    }

    pub fn root_key() {
        let s = format!(
            "could not get root key."
        );
        println!("{}", s);
        process::exit(1);
    }
}