Skip to content

Commit 58f96ff

Browse files
author
Geobert Quach
committed
chore: update deps
and fix deprecated items used in pest
1 parent ef6d65a commit 58f96ff

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 4.2.3
2+
- Upgrade dependencies
3+
- Port code to pest 2.4 (`prec_climber` being deprecated)
4+
15
# 4.2.2
26
- FIX: Panic when parsing "+ 3" .
37
- FIX: OOM error on too big numbers. We now limit to 5000 dices of 5000 sides.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "caith"
3-
version = "4.2.2"
3+
version = "4.2.3"
44
authors = ["Geobert Quach <geobert@protonmail.com>"]
55
edition = "2018"
66
description = "A dice roller library supporting many features"
@@ -20,12 +20,12 @@ maintenance = { status = "actively-developed" }
2020
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2121

2222
[dependencies]
23-
pest = "2.1.3"
24-
pest_derive = "2.1.0"
25-
rand = "0.8.4"
23+
pest = "2.4.1"
24+
pest_derive = "2.4.1"
25+
rand = "0.8.5"
2626

2727
[dev-dependencies]
28-
rand_core = "0.6.3"
28+
rand_core = "0.6.4"
2929

3030
[features]
3131
default = []

src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub type Result<T> = std::result::Result<T, RollError>;
99
#[derive(Debug)]
1010
pub enum RollError {
1111
/// Error while parsing the expression, emitted by `pest`
12-
ParseError(pest::error::Error<Rule>),
12+
ParseError(Box<pest::error::Error<Rule>>),
1313
/// Any other error while walking the AST, the String contains an explaination of what happened
1414
ParamError(String),
1515
}
@@ -27,7 +27,7 @@ impl Error for RollError {}
2727

2828
impl From<pest::error::Error<Rule>> for RollError {
2929
fn from(e: pest::error::Error<Rule>) -> Self {
30-
RollError::ParseError(e)
30+
RollError::ParseError(Box::new(e))
3131
}
3232
}
3333

src/helpers/cde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Display for CdeResult {
169169
Loksyu ({}): {} ● Yin / {} ○ Yang
170170
Tin Ji ({}): {}
171171
"#,
172-
self.history.as_ref().unwrap().to_string(),
172+
self.history.as_ref().unwrap(),
173173
prefixes[0],
174174
self.elements[0],
175175
self.success,

src/parser.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::{Arc, Once, RwLock};
22

33
use pest::{
44
iterators::{Pair, Pairs},
5-
prec_climber::{Assoc, Operator, PrecClimber},
5+
pratt_parser::PrattParser,
66
};
77
use pest_derive::Parser;
88

@@ -41,17 +41,22 @@ struct OptionResult {
4141
// Struct to have a singleton of PrecClimber without using once_cell
4242
#[derive(Clone)]
4343
struct Climber {
44-
inner: Arc<RwLock<PrecClimber<Rule>>>,
44+
inner: Arc<RwLock<PrattParser<Rule>>>,
4545
}
4646

4747
impl Climber {
4848
fn climb<'i, P, F, G, T>(&self, pairs: P, primary: F, infix: G) -> T
4949
where
5050
P: Iterator<Item = Pair<'i, Rule>>,
5151
F: FnMut(Pair<'i, Rule>) -> T,
52-
G: FnMut(T, Pair<'i, Rule>, T) -> T,
52+
G: FnMut(T, Pair<'i, Rule>, T) -> T + 'i,
5353
{
54-
self.inner.read().unwrap().climb(pairs, primary, infix)
54+
self.inner
55+
.read()
56+
.unwrap()
57+
.map_primary(primary)
58+
.map_infix(infix)
59+
.parse(pairs)
5560
}
5661
}
5762

@@ -61,15 +66,15 @@ fn get_climber() -> Climber {
6166

6267
unsafe {
6368
ONCE.call_once(|| {
64-
use self::Assoc::*;
65-
use self::Rule::*;
69+
use pest::pratt_parser::{Assoc, Op};
6670

6771
// Make it
6872
let singleton = Climber {
69-
inner: Arc::new(RwLock::new(PrecClimber::new(vec![
70-
Operator::new(add, Left) | Operator::new(sub, Left),
71-
Operator::new(mul, Left) | Operator::new(div, Left),
72-
]))),
73+
inner: Arc::new(RwLock::new(
74+
PrattParser::new()
75+
.op(Op::infix(Rule::add, Assoc::Left) | Op::infix(Rule::sub, Assoc::Left))
76+
.op(Op::infix(Rule::mul, Assoc::Left) | Op::infix(Rule::div, Assoc::Left)),
77+
)),
7378
};
7479

7580
// Put it in the heap so it can outlive this call

0 commit comments

Comments
 (0)