Skip to content

Commit b3fc078

Browse files
committed
Rework
1 parent 6f53109 commit b3fc078

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1828
-1687
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sarif-viewer.connectToGithubCodeScanning": "off"
3+
}

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

errful/src/formatting/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'e> From<&'e dyn Errful> for PrettyDisplay<'e> {
118118
struct Styles {
119119
base: owo_colors::Style,
120120
base_dim: owo_colors::Style,
121-
bold: owo_colors::Style,
121+
_bold: owo_colors::Style,
122122
only_bold: owo_colors::Style,
123123
main_sev: owo_colors::Style,
124124
}
@@ -128,7 +128,7 @@ impl Styles {
128128
Self {
129129
base: owo_colors::Style::new(),
130130
base_dim: owo_colors::Style::new(),
131-
bold: owo_colors::Style::new(),
131+
_bold: owo_colors::Style::new(),
132132
only_bold: owo_colors::Style::new(),
133133
main_sev: owo_colors::Style::new(),
134134
}
@@ -139,7 +139,7 @@ impl Styles {
139139
Self {
140140
base,
141141
base_dim: base.dimmed(),
142-
bold: base.bold(),
142+
_bold: base.bold(),
143143
only_bold: owo_colors::Style::new().bold(),
144144
main_sev: base.bold().underline(),
145145
}

gedcomesque/examples/gogogo.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::{path::PathBuf, time::Instant};
44

55
use errful::ExitResult;
66
use gedcomesque::entities::individual::{ActiveModel as IndividualActive, Entity as Individual};
7-
use gedcomfy::parser::{
8-
encodings::SupportedEncoding, lines::LineValue, options::ParseOptions, Parser,
7+
use gedcomfy::reader::{
8+
encodings::SupportedEncoding, input::FileLoadError, lines::LineValue, options::ParseOptions,
9+
Reader, ReaderError,
910
};
1011
use sea_orm::{
1112
sea_query::TableCreateStatement, ActiveValue, ConnectionTrait, Database, DatabaseConnection,
@@ -24,9 +25,8 @@ enum Error {
2425
source: sea_orm::DbErr,
2526
},
2627

27-
Parse(gedcomfy::parser::ParserError<'static>),
28-
29-
FileLoad(gedcomfy::parser::FileLoadError),
28+
Loading(#[from] FileLoadError),
29+
Parsing(#[from] gedcomfy::reader::WithSourceCode<'static, ReaderError>),
3030
}
3131

3232
#[tokio::main(flavor = "current_thread")]
@@ -37,8 +37,9 @@ async fn main() -> ExitResult<Error> {
3737
let opts = ParseOptions::default().force_encoding(SupportedEncoding::Windows1252);
3838
let file_size = { std::fs::File::open(&path)?.metadata()?.len() };
3939
let start_time = Instant::now();
40-
let mut parser = Parser::with_options(opts).load_file(&path)?;
41-
let records = parser.raw_records().map_err(|e| e.to_static())?;
40+
let reader = Reader::with_options(opts);
41+
let input = reader.decode_file(path)?;
42+
let records = reader.raw_records(&input)?;
4243
let elapsed = start_time.elapsed().as_secs_f64();
4344
println!(
4445
"parsed {filename} in {}s: ({} bytes, {} records, {} records/s)",
@@ -65,14 +66,14 @@ async fn main() -> ExitResult<Error> {
6566
let to_insert = Vec::from_iter(
6667
records
6768
.iter()
68-
.filter(|r| r.value.line.tag.value == "INDI")
69+
.filter(|r| r.sourced_value.line.tag.sourced_value == "INDI")
6970
.map(|r| IndividualActive {
7071
name: ActiveValue::Set(
7172
r.records
7273
.iter()
7374
.find_map(|r| {
74-
if r.value.line.tag.value == "NAME" {
75-
match r.value.line.line_value.value {
75+
if r.sourced_value.line.tag.sourced_value == "NAME" {
76+
match r.sourced_value.line.value.sourced_value {
7677
LineValue::None | LineValue::Ptr(_) => todo!("unhandled"),
7778
LineValue::Str(s) => Some(s),
7879
}

gedcomfy/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ kdl = ["dep:kdl"]
1414
[dependencies]
1515
ascii = "1.1.0"
1616
complex-indifference = { path = "../complex-indifference" }
17-
derive_more = { version = "1.0.0", features = ["from", "display", "error"] }
17+
derive_more = { version = "2.0.1", features = ["from", "display"] }
1818
errful = { path = "../errful" }
1919
encoding_rs = "0.8.34"
2020
kdl = { version = "4.6.0", optional = true }
@@ -28,6 +28,7 @@ yoke = { version = "0.7.4", features = ["derive"] }
2828
itertools = "0.14.0"
2929
memmap2 = "0.9.5"
3030
dunce = "1.0.5"
31+
thiserror = "2.0.12"
3132

3233

3334
[dev-dependencies]

gedcomfy/src/encodings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Display;
33
use itertools::Itertools;
44
use miette::Diagnostic;
55

6-
use crate::parser::{encodings::SupportedEncoding, GEDCOMSource};
6+
use crate::reader::{encodings::SupportedEncoding, GEDCOMSource};
77

88
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
99
pub enum GEDCOMEncoding {
@@ -26,7 +26,7 @@ impl Display for GEDCOMEncoding {
2626
}
2727
}
2828

29-
#[derive(derive_more::Error, derive_more::Display, Diagnostic, Debug)]
29+
#[derive(thiserror::Error, derive_more::Display, Diagnostic, Debug)]
3030
#[display("GEDCOM encoding {encoding} is ambiguous")]
3131
#[diagnostic(help("This value could imply any of the following encodings: {}",
3232
.possibilities.iter().join(", ")))]
@@ -67,7 +67,7 @@ impl From<SupportedEncoding> for GEDCOMEncoding {
6767
}
6868
}
6969
}
70-
#[derive(derive_more::Error, derive_more::Display, Diagnostic, Debug)]
70+
#[derive(thiserror::Error, derive_more::Display, Diagnostic, Debug)]
7171
#[display("invalid GEDCOM encoding")]
7272
pub struct InvalidGEDCOMEncoding {}
7373

gedcomfy/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22
33
use core::str;
44

5-
use miette::{Context, IntoDiagnostic, SourceSpan};
6-
use parser::{
7-
decoding::DecodingError, lines::LineSyntaxError, options::ParseOptions, records::RawRecord,
8-
GEDCOMSource, Sourced,
5+
use miette::SourceSpan;
6+
use reader::{
7+
decoding::DecodingError, lines::LineSyntaxError, records::RawRecord, GEDCOMSource, Sourced,
98
};
109
use vec1::Vec1;
1110

1211
pub mod encodings;
1312
pub mod highlighting;
14-
pub mod parser;
13+
pub mod reader;
1514
pub mod schemas;
1615
pub mod versions;
1716

18-
pub use parser::Parser;
17+
pub use reader::Reader;
1918

20-
#[derive(
21-
derive_more::Error, derive_more::Display, derive_more::From, Debug, miette::Diagnostic,
22-
)]
19+
#[derive(thiserror::Error, derive_more::Display, Debug, miette::Diagnostic)]
2320
pub enum ValidationError {
2421
#[display("{} syntax error{} detected", errors.len(), if errors.len() > 1 { "s" } else { "" })]
2522
SyntaxErrorsDetected {
@@ -29,7 +26,6 @@ pub enum ValidationError {
2926
#[display("Encoding error detected: further validation errors will not be found")]
3027
#[diagnostic(transparent)]
3128
EncodingErrorDetected {
32-
#[error(source)]
3329
#[from]
3430
error: DecodingError,
3531
},
@@ -39,11 +35,11 @@ impl<S: GEDCOMSource + ?Sized> RawRecord<'_, S> {
3935
pub(crate) fn subrecord_optional(&self, subrecord_tag: &str) -> Option<&Sourced<RawRecord<S>>> {
4036
self.records
4137
.iter()
42-
.find(|r| r.value.line.tag.value == subrecord_tag)
38+
.find(|r| r.sourced_value.line.tag.sourced_value == subrecord_tag)
4339
}
4440
}
4541

46-
#[derive(derive_more::Error, derive_more::Display, Debug, miette::Diagnostic)]
42+
#[derive(thiserror::Error, derive_more::Display, Debug, miette::Diagnostic)]
4743
pub enum FileStructureError {
4844
#[display("Missing HEAD record")]
4945
#[diagnostic(code(gedcom::schema_error::missing_head_record))]

gedcomfy/src/parser/decoding.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)