Skip to content

Commit 3b10f0c

Browse files
committed
Update dependencies and code
1 parent 6bd1681 commit 3b10f0c

File tree

5 files changed

+84
-118
lines changed

5 files changed

+84
-118
lines changed

Cargo.toml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,32 @@ futures = "0.3"
2828
futures-signals = "0.3"
2929
gloo-file = { version = "0.3", features = [ "futures" ] }
3030
gloo-utils = "0.2"
31-
html5ever = "0.25"
32-
infer = "0.16.0"
31+
html5ever = "0.29"
32+
infer = "0.19.0"
3333
instant = { version = "0.1", features = [ "wasm-bindgen", "inaccurate" ] }
3434
isin = "0.1.18"
3535
js-sys = "0.3"
3636
log = "0.4"
37-
nom = "6.0"
37+
nom = "8.0"
3838
num-format = "0.4.4"
39-
pdf-extract = "0.7"
39+
pdf-extract = "0.8"
4040
rust_decimal = "1.7"
41-
scraper = "0.12"
42-
selectors = "0.22"
41+
scraper = "0.23"
42+
selectors = "0.26"
4343
serde = { version = "1.0", features = ["derive", "rc"] }
4444
xml-rs = "0.8"
4545
wasm-bindgen = "0.2"
4646
wasm-bindgen-futures = "0.4"
4747
wasm-logger = "0.2"
48-
zip = { version = "0.5", default-features = false, features = ["deflate"]}
48+
zip = { version = "2.2", default-features = false, features = ["deflate"]}
4949

5050
[dev-dependencies]
51-
ctor = "0.1"
52-
env_logger = "0.9"
53-
reqwest = { version = "0.11", default-features = false, features = ["json"] }
54-
thirtyfour = "0.27"
55-
tokio = { version = "1.0", features = ["fs", "macros", "rt-multi-thread", "io-util"] }
51+
ctor = "0.4"
52+
env_logger = "0.11"
53+
reqwest = { version = "0.12", default-features = false, features = ["json"] }
54+
serde_json = "1.0.139"
55+
thirtyfour = "0.35"
56+
tokio = { version = "1.0", features = ["full"] }
5657

5758
[profile.dev.package."*"]
5859
opt-level = 3
@@ -67,5 +68,6 @@ opt-level = "z" # 3 => fast, s/z => small
6768
# link time optimization using using whole-program analysis
6869
lto = true
6970

70-
[package.metadata.wasm-pack.profile.release]
71-
wasm-opt = ["--enable-bulk-memory", "-Oz"] # O4 => fast, Oz/Os => small
71+
# [package.metadata.wasm-pack.profile.release]
72+
# Configured in rollup.config.js
73+
# wasm-opt = ["--enable-bulk-memory", "-Oz"] # O4 => fast, Oz/Os => small

src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ pub struct Aeat720Information {
158158

159159
impl Aeat720Information {
160160
pub fn full_name(&self) -> String {
161-
self.personal_info.surname.clone() + " " + &self.personal_info.name
161+
self.personal_info.surname.clone() + " " + &self.personal_info.name[..]
162162
}
163163
}

src/parsers/degiro.rs

Lines changed: 50 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ use crate::utils::decimal;
1010
use anyhow::{Context, Result, bail};
1111
use chrono::NaiveDate;
1212
use nom::character::complete::anychar;
13+
use nom::error::ErrorKind;
1314
use nom::multi::many_till;
1415
use nom::sequence::{preceded, separated_pair};
15-
use nom::{
16-
IResult,
17-
error::{VerboseError, context},
18-
};
16+
use nom::{IResult, Parser, error::context};
1917
use nom::{
2018
branch::alt,
2119
bytes::complete::{is_a, take},
2220
character::complete::none_of,
2321
combinator::{map_res, opt, recognize},
2422
multi::many0,
2523
multi::many1,
26-
sequence::{terminated, tuple},
24+
sequence::terminated,
2725
};
2826
use nom::{
2927
bytes::complete::{tag, tag_no_case},
@@ -33,7 +31,7 @@ use nom::{
3331

3432
use rust_decimal::prelude::*;
3533

36-
type Res<T, U> = IResult<T, U, VerboseError<T>>;
34+
type Res<T, U> = IResult<T, U, (T, ErrorKind)>;
3735

3836
pub struct DegiroParser {
3937
content: String,
@@ -60,7 +58,8 @@ pérdidas
6058
impl DegiroParser {
6159
fn n_to_m_digits<'b>(n: usize, m: usize) -> impl FnMut(&'b str) -> Res<&'b str, String> {
6260
move |input| {
63-
many_m_n(n, m, one_of("0123456789"))(input)
61+
many_m_n(n, m, one_of("0123456789"))
62+
.parse(input)
6463
.map(|(next_input, result)| (next_input, result.into_iter().collect()))
6564
}
6665
}
@@ -72,7 +71,8 @@ impl DegiroParser {
7271
recognize(many1(terminated(one_of("0123456789"), many0(is_a(",."))))),
7372
|out: &str| Decimal::from_str(&decimal::transform_i18n_es_str(out)),
7473
),
75-
)(input)
74+
)
75+
.parse(input)
7676
}
7777

7878
fn number_no_decimal_digits(input: &str) -> Res<&str, Decimal> {
@@ -81,7 +81,8 @@ impl DegiroParser {
8181
map_res(recognize(many1(one_of("0123456789"))), |out: &str| {
8282
Decimal::from_str(out)
8383
}),
84-
)(input)
84+
)
85+
.parse(input)
8586
}
8687

8788
fn number_decimal_digits(input: &str, count: usize) -> Res<&str, Decimal> {
@@ -95,35 +96,38 @@ impl DegiroParser {
9596
)),
9697
|out: &str| Decimal::from_str(&decimal::transform_i18n_es_str(out)),
9798
),
98-
)(input)
99+
)
100+
.parse(input)
99101
}
100102

101103
fn earnings_value(input: &str) -> Res<&str, Decimal> {
102104
context(
103105
"earnings value",
104106
map_res(
105-
recognize(tuple((
107+
recognize((
106108
opt(one_of("+-")),
107109
recognize(many1(terminated(one_of("0123456789"), many0(char('.'))))),
108110
char(','),
109111
recognize(many1(terminated(one_of("0123456789"), many0(char('.'))))),
110-
))),
112+
)),
111113
|out: &str| Decimal::from_str(&decimal::transform_i18n_es_str(out)),
112114
),
113-
)(input)
115+
)
116+
.parse(input)
114117
}
115118

116119
fn date_concept(input: &str) -> Res<&str, NaiveDate> {
117120
context(
118121
"date concept",
119-
tuple((
122+
(
120123
DegiroParser::n_to_m_digits(1, 2),
121124
tag("/"),
122125
DegiroParser::n_to_m_digits(1, 2),
123126
tag("/"),
124127
DegiroParser::n_to_m_digits(1, 4),
125-
)),
126-
)(input)
128+
),
129+
)
130+
.parse(input)
127131
.map(|(next_input, res)| {
128132
let (day, _, month, _, year) = res;
129133
(
@@ -142,19 +146,21 @@ impl DegiroParser {
142146
context(
143147
"broker operation",
144148
alt((tag_no_case("C"), tag_no_case("V"))),
145-
)(input)
149+
)
150+
.parse(input)
146151
.map(|(next_input, res)| (next_input, res.into()))
147152
}
148153

149154
fn isin(input: &str) -> Res<&str, String> {
150155
context(
151156
"isin",
152-
tuple((
157+
(
153158
many_m_n(2, 2, none_of("\t \n0123456789")),
154159
many_m_n(9, 9, none_of("\t \n")),
155160
many1(one_of("0123456789")),
156-
)),
157-
)(input)
161+
),
162+
)
163+
.parse(input)
158164
.map(|(next_input, res)| {
159165
let (prefix, main, control) = res;
160166
let mut result: String = prefix.iter().collect();
@@ -165,8 +171,9 @@ impl DegiroParser {
165171
}
166172

167173
fn company_info(input: &str) -> Res<&str, CompanyInfo> {
168-
context("company info", many_till(anychar, DegiroParser::isin))(input).map(
169-
|(next_input, res)| {
174+
context("company info", many_till(anychar, DegiroParser::isin))
175+
.parse(input)
176+
.map(|(next_input, res)| {
170177
let (company_name, isin) = res;
171178
let company_name: String = company_name.into_iter().collect();
172179
let company_name = company_name.replace('\n', " ").trim_end().to_string();
@@ -178,8 +185,7 @@ impl DegiroParser {
178185
isin,
179186
},
180187
)
181-
},
182-
)
188+
})
183189
}
184190

185191
fn account_note<'a>(
@@ -188,7 +194,7 @@ impl DegiroParser {
188194
) -> Res<&'a str, AccountNote> {
189195
context(
190196
"account note",
191-
tuple((
197+
(
192198
DegiroParser::date_concept,
193199
tag(" "),
194200
DegiroParser::company_info,
@@ -206,10 +212,11 @@ impl DegiroParser {
206212
DegiroParser::decimal_value,
207213
tag(" "),
208214
DegiroParser::decimal_value,
209-
opt(tuple((char(' '), DegiroParser::earnings_value))),
215+
opt((char(' '), DegiroParser::earnings_value)),
210216
tag("\n"),
211-
)),
212-
)(input)
217+
),
218+
)
219+
.parse(input)
213220
.map(|(next_input, res)| {
214221
let (
215222
date,
@@ -249,7 +256,7 @@ impl DegiroParser {
249256
log::trace!("balance note: -{}-", input);
250257
context(
251258
"balance note",
252-
tuple((
259+
(
253260
tag("\n "),
254261
|input| DegiroParser::number_decimal_digits(input, 2), // value in euro
255262
|input| DegiroParser::number_decimal_digits(input, 4), // price
@@ -258,8 +265,9 @@ impl DegiroParser {
258265
take(3usize), // market
259266
alt((tag("Stock"), tag("ETF"))), // product type: Stock | ETF
260267
DegiroParser::company_info, // company info
261-
)),
262-
)(input)
268+
),
269+
)
270+
.parse(input)
263271
.map(|(next_input, res)| {
264272
let (_, value_in_euro, price, currency, quantity, market, _product_type, company) = res;
265273

@@ -287,7 +295,8 @@ impl DegiroParser {
287295
many0(preceded(char('\n'), |x| {
288296
DegiroParser::account_note(x, broker)
289297
})),
290-
)(input)
298+
)
299+
.parse(input)
291300
}
292301

293302
fn balance_notes<'a>(
@@ -297,7 +306,8 @@ impl DegiroParser {
297306
context(
298307
"balance notes",
299308
many0(|x| DegiroParser::balance_note(x, broker)),
300-
)(input)
309+
)
310+
.parse(input)
301311
}
302312

303313
fn parse_account_notes(&self, notes: &str) -> Result<AccountNotes> {
@@ -400,10 +410,7 @@ impl DegiroParser {
400410
#[allow(clippy::mistyped_literal_suffixes)]
401411
mod tests {
402412
use super::*;
403-
use nom::{
404-
Err as NomErr,
405-
error::{ErrorKind, VerboseError, VerboseErrorKind},
406-
};
413+
use nom::error::ErrorKind;
407414

408415
#[test]
409416
fn broker_operation_test() {
@@ -417,13 +424,7 @@ mod tests {
417424
);
418425
assert_eq!(
419426
DegiroParser::broker_operation("Z "),
420-
Err(NomErr::Error(VerboseError {
421-
errors: vec![
422-
("Z ", VerboseErrorKind::Nom(ErrorKind::Tag)),
423-
("Z ", VerboseErrorKind::Nom(ErrorKind::Alt)),
424-
("Z ", VerboseErrorKind::Context("broker operation")),
425-
]
426-
}))
427+
Err(nom::Err::Error(("Z ", ErrorKind::Tag)))
427428
);
428429
}
429430

@@ -439,12 +440,7 @@ mod tests {
439440
);
440441
assert_eq!(
441442
DegiroParser::date_concept("32_23_2020 "),
442-
Err(NomErr::Error(VerboseError {
443-
errors: vec![
444-
("_23_2020 ", VerboseErrorKind::Nom(ErrorKind::Tag)),
445-
("32_23_2020 ", VerboseErrorKind::Context("date concept")),
446-
]
447-
}))
443+
Err(nom::Err::Error(("_23_2020 ", ErrorKind::Tag)))
448444
);
449445
}
450446

@@ -460,13 +456,7 @@ mod tests {
460456
);
461457
assert_eq!(
462458
DegiroParser::isin("US342342 "),
463-
Err(NomErr::Error(VerboseError {
464-
errors: vec![
465-
(" ", VerboseErrorKind::Nom(ErrorKind::NoneOf)),
466-
(" ", VerboseErrorKind::Nom(ErrorKind::ManyMN)),
467-
("US342342 ", VerboseErrorKind::Context("isin")),
468-
]
469-
}))
459+
Err(nom::Err::Error((" ", ErrorKind::NoneOf)))
470460
);
471461
}
472462

@@ -516,13 +506,7 @@ STOCK WHEN-ISSUED US36262G1013 "#;
516506
);
517507
assert_eq!(
518508
DegiroParser::decimal_value("a234,23 "),
519-
Err(NomErr::Error(VerboseError {
520-
errors: vec![
521-
("a234,23 ", VerboseErrorKind::Nom(ErrorKind::OneOf)),
522-
("a234,23 ", VerboseErrorKind::Nom(ErrorKind::Many1)),
523-
("a234,23 ", VerboseErrorKind::Context("decimal value")),
524-
]
525-
}))
509+
Err(nom::Err::Error(("a234,23 ", ErrorKind::OneOf)))
526510
);
527511
}
528512

@@ -542,16 +526,7 @@ STOCK WHEN-ISSUED US36262G1013 "#;
542526
);
543527
assert_eq!(
544528
DegiroParser::number_decimal_digits("a234,23 ", 2),
545-
Err(NomErr::Error(VerboseError {
546-
errors: vec![
547-
("a234,23 ", VerboseErrorKind::Nom(ErrorKind::OneOf)),
548-
("a234,23 ", VerboseErrorKind::Nom(ErrorKind::Many1)),
549-
(
550-
"a234,23 ",
551-
VerboseErrorKind::Context("number n decimal digits")
552-
),
553-
]
554-
}))
529+
Err(nom::Err::Error(("a234,23 ", ErrorKind::OneOf)))
555530
);
556531
}
557532

@@ -571,12 +546,7 @@ STOCK WHEN-ISSUED US36262G1013 "#;
571546
);
572547
assert_eq!(
573548
DegiroParser::earnings_value("1234\n"),
574-
Err(NomErr::Error(VerboseError {
575-
errors: vec![
576-
("\n", VerboseErrorKind::Char(',')),
577-
("1234\n", VerboseErrorKind::Context("earnings value")),
578-
]
579-
}))
549+
Err(nom::Err::Error(("\n", ErrorKind::Char)))
580550
);
581551
}
582552

0 commit comments

Comments
 (0)