From b0bea0d9535d8477a3f991634478eb8d1659bdc7 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 7 Apr 2024 02:30:55 +0200 Subject: [PATCH] Adds the basics of parsing --- src/parser.rs | 80 ++++++++++++++++++++++------------------ src/skills_structures.rs | 1 + tarpaulin-report.html | 4 +- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 2049131..7e71544 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,9 +1,4 @@ /// Reads and parse a skill sheet -use crate::skills_structures::Renderable; -use crate::skills_structures::Section; -use crate::skills_structures::Skill; -use crate::skills_structures::SubSection; -use crate::skills_structures::SubSkill; use std::{fs, path::Path}; use crate::{ @@ -19,54 +14,67 @@ trait Parser { impl Parser for SkillList { type Err = LoadError; fn from_path(path: impl AsRef + ToString) -> Result { - let mut ls = SkillList::with_config(&ConfigList::new(path.to_string(), 0, 0, 50)); let file_content = fs::read_to_string(&path).map_err(LoadError::Io)?; - let mut linecount = 1; let mut global_id = 0; let mut globlist = Vec::with_capacity(100); - struct line_id { - kind: SkillTypes, - value: String, - } - // let (mut last_sect, mut last_subs, mut last_skill) = (None, None, None); - // let mut inner: Box = Box::new(&mut ls); + let (mut last_sect, mut last_subs, mut last_skill, mut last_sskill) = (0, 0, 0, 0); for line in file_content.lines() { let (index, skill) = line.split_at(1); - match index.parse::()? { - // inner.append_list(Section::new(skill, 0, 0, 0))? + let kind = index.parse::()?; + match kind { SkillTypes::Section => { - let mut s = Section::new(skill, ls.get_data().childs, global_id, 0); - ls.get_mut_data().childs += 1; - ls.list.push(&mut s); - last_sect = ls.list.last(); + last_sect += 1; + (last_subs, last_skill, last_sskill) = (0, 0, 0); + globlist.push(LineId { + kind, + value: skill.to_owned(), + global_id, + id: last_sect, + }); } SkillTypes::SubSection => { - if let Some(sec) = last_sect { - let mut ss = SubSection::new(skill, sec.get_data().childs, global_id, 0); - sec.get_mut_data().childs + 1; - sec.list.push(&mut ss); - last_subs = sec.list.last(); - } + last_subs += 1; + (last_skill, last_sskill) = (0, 0); + globlist.push(LineId { + kind, + value: skill.to_owned(), + global_id, + id: last_subs, + }); } SkillTypes::Skill => { - if let Some(ssc) = last_subs { - let mut sk = Skill::new(skill, ssc.get_data().childs, global_id, 0); - ssc.get_mut_data().childs += 1; - ssc.list.push(&mut sk); - last_skill = ssc.list.last(); - } + last_skill += 1; + last_sskill = 0; + globlist.push(LineId { + kind, + value: skill.to_owned(), + global_id, + id: last_skill, + }); } SkillTypes::SubSkill => { - if let Some(_sk) = last_skill { - // let ssk = SubSkill::new(skill, sk.get_data().childs, global_id, 0); - } + last_sskill += 1; + globlist.push(LineId { + kind, + value: skill.to_owned(), + global_id, + id: last_sskill, + }); } SkillTypes::NewLine => (), - SkillTypes::Error => return Err(LoadError::LineParseError), + SkillTypes::Error => (), } global_id += 1; - linecount += 1; } + let ls = SkillList::with_config(&ConfigList::new(path.to_string(), 0, 0, global_id)); + todo!(); Ok(ls) } } + +struct LineId { + kind: SkillTypes, + value: String, + global_id: usize, + id: usize, +} diff --git a/src/skills_structures.rs b/src/skills_structures.rs index b33cdd3..f308bb7 100644 --- a/src/skills_structures.rs +++ b/src/skills_structures.rs @@ -250,6 +250,7 @@ impl Renderable for SkillList { } fn new(name: &str, _id: usize, _global_id: usize, _size_hint: usize) -> Self { + let _ = name; todo!() } diff --git a/tarpaulin-report.html b/tarpaulin-report.html index a62165e..c2590c9 100644 --- a/tarpaulin-report.html +++ b/tarpaulin-report.html @@ -118,8 +118,8 @@