Fixed bug in parser. Added opt_vec_at() fn.
[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 25, 2021, 2:29 AM
WPR2A6Y7OMJ7JIO7LNFVUR5YSB34HFWWZNGQLAQOJBFGUCNLNA4QCDependencies
- [2]
QMBJ2BAZCan now handle FromStr. - [3]
6ZJX2OQVFirst commit - [4]
BRO5BHI2Added val() function to KeyTreeRef. - [5]
TMYMF5L6temp - [6]
VDFODD2FAdded line to BadIndent error. - [7]
446EWE33Added key_into() function. - [8]
JUK3ONMUFixed comment parsing bug. - [9]
N467KW7JRefactored (simplified) errors.
Change contents
- replacement in src/parser.rs at line 122
Err(first_token_must_be_key(&token.to_string()))Err(first_token_must_be_key(file!(),line!(),&token.to_string())) - edit in src/parser.rs at line 169
file!(),line!(), - replacement in src/parser.rs at line 309
key: &s[start_key..=pos],key: &s[start_key..=end_key], - edit in src/parser.rs at line 385
file!(),line!(), - edit in src/parser.rs at line 396
file!(),line!(), - replacement in src/parser.rs at line 407
return Err(no_space_after_key());line += 1;let token_str = &s[start_key..=pos - 1];return Err(no_space_after_key(file!(),line!(),&token_str.to_string(),line,)); - edit in src/parser.rs at line 423
file!(),line!(), - edit in src/parser.rs at line 435
file!(),line!(), - replacement in src/parser.rs at line 446
// line_start = pos;return Err(colon_before_key())line += 1;let token_str = &s[start_key..=pos - 1];return Err(colon_before_key(file!(),line!(),&token_str.to_string(),line,)) - replacement in src/parser.rs at line 456
// start_key = pos;return Err(colon_before_key())line += 1;let token_str = &s[start_key..=pos - 1];return Err(colon_before_key(file!(),line!(),&token_str.to_string(),line,)) - replacement in src/parser.rs at line 466
return Err(no_space_after_key())line += 1;let token_str = &s[start_key..=pos - 1];return Err(no_space_after_key(file!(),line!(),&token_str.to_string(),line,)) - replacement in src/parser.rs at line 479
return Err(no_space_after_key())line += 1;let token_str = &s[start_key..=pos - 1];return Err(no_space_after_key(file!(),line!(),&token_str.to_string(),line,)) - edit in src/parser.rs at line 501
file!(),line!(), - edit in src/parser.rs at line 513
file!(),line!(), - replacement in src/parser.rs at line 569
Err(no_tokens())Err(no_tokens(file!(),line!(),)) - replacement in src/lib.rs at line 349
pub struct KeyTreeRef<'a>(&'a KeyTree<'a>, usize);pub struct KeyTreeRef<'a>(&'a KeyTree<'a>, pub usize); - replacement in src/lib.rs at line 433
_ => Err(expected_unique_keyvalue_found_multi(key_path)),_ => Err(expected_unique_keyvalue_found_multi(file!(), line!(), key_path)), - replacement in src/lib.rs at line 445
0 => Err(expected_unique_keyvalue_found_none(key_path)),0 => Err(expected_unique_keyvalue_found_none(file!(), line!(), key_path)), - replacement in src/lib.rs at line 447
_ => Err(expected_unique_keyvalue_found_multi(key_path)),_ => Err(expected_unique_keyvalue_found_multi(file!(), line!(), key_path)), - replacement in src/lib.rs at line 458
0 => Err(expected_unique_keyvalue_found_none(key_path)),0 => Err(expected_unique_keyvalue_found_none(file!(), line!(), key_path)), - replacement in src/lib.rs at line 460
_ => Err(expected_unique_keyvalue_found_multi(key_path)),_ => Err(expected_unique_keyvalue_found_multi(file!(), line!(), key_path)), - replacement in src/lib.rs at line 473
_ => Err(expected_unique_keyvalue_found_multi(key_path)),_ => Err(expected_unique_keyvalue_found_multi(file!(), line!(), key_path)), - edit in src/lib.rs at line 492
whereKeyTreeRef<'a>: TryInto<T>,KeyTreeRef<'a>: TryInto<T, Error = Error>,{let path = KeyPath::from_str(key_path);let kts = self.resolve_path(&path)?;let mut v = Vec::new();for kt in kts {v.push(kt.key_into()?)}if v.is_empty() {return Err(expected_non_empty_collection(file!(),line!(),key_path))};Ok(v)}pub fn opt_vec_at<T>(&self, key_path: &str) -> Result<Vec<T>> - replacement in src/error.rs at line 19
"[01] line {}, token [{}]. Bad first segment [{}].","[keytree:01] line {}, token [{}]. Bad first segment [{}].", - replacement in src/error.rs at line 28
"[02] line {}, token [{}]. Indentation of {} is incorrect.","[keytree:02] line {}, token [{}]. Indentation of {} is incorrect.", - replacement in src/error.rs at line 37
"[03] line {}, token [{}], Cannot resolve token with siblings.","[keytree:03] line {}, token [{}]. Cannot resolve token with siblings.", - replacement in src/error.rs at line 43
pub fn colon_before_key() -> Error {Error(String::from("[03] Colon before key."))pub fn colon_before_key(file: &str, code_line: u32, token: &str, line: usize) -> Error {Error(format!("[keytree:04:{}:{}] Line {}, token [{}]. Colon before key.",file,code_line,line,token,)) - replacement in src/error.rs at line 54
Error(String::from("[04] Empty path."))Error(String::from("[keytree:05] Empty path.")) - replacement in src/error.rs at line 58
Error(String::from("[05] Keytree string is empty."))Error(String::from("[keytree:06] Keytree string is empty.")) - replacement in src/error.rs at line 63
"[06] line {}, token [{}]. Expected [key:] but found [key: value].","[keytree:07] line {}, token [{}]. Expected [key:] but found [key: value].", - replacement in src/error.rs at line 71
"[07] line {}, token [{}]. Expected [key: value] but found [key:].","[keytree:08] line {}, token [{}]. Expected [key: value] but found [key:].", - edit in src/error.rs at line 77
pub fn expected_non_empty_collection(code_file: &str, code_line: u32, keypath: &str) -> Error {Error(format!("[keytree:09:{}:{}] Expected non-empty collection at [{}].",code_file,code_line,keypath,))} - replacement in src/error.rs at line 88
"[08] keypath: [{}]. Expected unique token but found multiple tokens.","[keytree:09] keypath: [{}]. Expected unique token but found multiple tokens.", - replacement in src/error.rs at line 93
pub fn expected_unique_keyvalue_found_multi(key_path: &str) -> Error {pub fn expected_unique_keyvalue_found_multi(file: &str, code_line: u32, key_path: &str) -> Error { - replacement in src/error.rs at line 95
"[09] keypath: [{}]. Expected unique [key: value] but found multiple tokens.","[keytree:10:{}:{}] keypath: [{}]. Expected unique [key: value] but found multiple tokens.",file,code_line, - replacement in src/error.rs at line 102
pub fn expected_unique_keyvalue_found_none(key_path: &str) -> Error {pub fn expected_unique_keyvalue_found_none(file: &str, code_line: u32, key_path: &str) -> Error { - replacement in src/error.rs at line 104
"[10] keypath: [{}]. Expected unique [key: value] but found none.","[keytree:11:{}:{}] Keypath [{}]. Expected unique [key: value] but found none.",file,code_line, - replacement in src/error.rs at line 111[2.11391]→[2.11391:11445](∅→∅),[3.6808]→[3.3345:3356](∅→∅),[2.11445]→[3.3345:3356](∅→∅),[3.3345]→[3.3345:3356](∅→∅),[3.3356]→[2.11446:11519](∅→∅),[2.11519]→[3.3509:3515](∅→∅),[3.3509]→[3.3509:3515](∅→∅)
pub fn expected_unique_token_found_multi() -> Error {Error(String::from("[11] Expected a unique token but found multiple."))pub fn expected_unique_token_found_multi(file: &str, code_line: u32, key_path: &str) -> Error {Error(format!("[keytree:12:{}:{}] Keypath [{}]. Expected a unique token but found multiple.",file,code_line,key_path,)) - replacement in src/error.rs at line 122
"[12] line {}, token [{}]. Failed to parse value.","[keytree:13] line {}, token [{}]. Failed to parse value.", - replacement in src/error.rs at line 128
pub fn first_token_must_be_key(token: &str) -> Error {pub fn first_token_must_be_key(file: &str, code_line: u32, token: &str) -> Error { - replacement in src/error.rs at line 130
"[13] token {}. First token must be [key:].","[keytree:14:{}:{}] token {}. First token must be [key:].",file,code_line, - replacement in src/error.rs at line 139
"[14] line {}, token [{}]. The first segment of [{}] does not match.","[keytree:15] line {}, token [{}]. The first segment of [{}] does not match.", - replacement in src/error.rs at line 146
pub fn incomplete_comment_or_key(token: &str, line: usize) -> Error {pub fn incomplete_comment_or_key(file: &str, code_line: u32, token: &str, line: usize) -> Error { - replacement in src/error.rs at line 148
"[15] line {}, token [{}]. Incomplete comment or key.","[keytree:16:{}:{}] line {}, token [{}]. Incomplete comment or key.",file,code_line, - replacement in src/error.rs at line 156
pub fn incomplete_line(token: &str, line: usize) -> Error {pub fn incomplete_line(file: &str, code_line: u32, token: &str, line: usize) -> Error { - replacement in src/error.rs at line 158
"[16] line {}, token [{}]. Incomplete line.","[keytree:17:{}:{}] line {}, token [{}]. Incomplete line.",file,code_line, - replacement in src/error.rs at line 168
"[17] line {}, token [{}], keypath [{}]. Keypath extends beyond keyvalue.","[keytree:18] line {} token [{}], keypath [{}]. Keypath extends beyond keyvalue.", - replacement in src/error.rs at line 176
Error(format!( "[18] Keypath {} must have two or more segments.", key_path))Error(format!( "[keytree:19] Keypath {} must have two or more segments.", key_path)) - replacement in src/error.rs at line 181
"[19] line {}, token [{}]. Keypath segment {} does not match key.","[keytree:20] line {} token [{}]. Keypath segment {} does not match key.", - replacement in src/error.rs at line 190
"[20] line {}, token [{}]. Failed to find key [{}]","[keytree:21] line {} token [{}]. Failed to find key [{}]", - replacement in src/error.rs at line 197
pub fn no_colon_after_key(token: &str, line: usize) -> Error {pub fn no_colon_after_key(file: &str, code_line: u32, token: &str, line: usize) -> Error { - replacement in src/error.rs at line 199
"[21] line {}, token [{}], No colon after key.","[keytree:22:{}:{}] line {} token [{}], No colon after key.",file,code_line, - replacement in src/error.rs at line 207
pub fn no_space_after_key() -> Error {Error(String::from("[22] No space after key."))pub fn no_space_after_key(file: &str, code_line: u32, token: &str, line: usize) -> Error {Error(format!("[keytree:23:{}:{}] line {} token [{}]. No space after key.",file,code_line,line,token,)) - replacement in src/error.rs at line 217
pub fn no_tokens() -> Error {Error(String::from("[23] No tokens."))pub fn no_tokens(file: &str, code_line: u32) -> Error {Error(format!("[keytree:24:{}:{}] No tokens in parsed keytree.",file,code_line,)) - replacement in src/error.rs at line 225
pub fn non_root_has_zero_indent(token: &str, line: usize) -> Error {pub fn non_root_has_zero_indent(file: &str, code_line: u32, token: &str, line: usize) -> Error { - replacement in src/error.rs at line 227
"[24] line {}, token [{}]. Token other than root token as zero indent.","[keytree:25:{}:{}] line {}, token [{}]. Token other than root token as zero indent.",file,code_line,